/src/php-src/ext/uri/uriparser/src/UriParse.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * uriparser - RFC 3986 URI parsing library |
3 | | * |
4 | | * Copyright (C) 2007, Weijia Song <songweijia@gmail.com> |
5 | | * Copyright (C) 2007, Sebastian Pipping <sebastian@pipping.org> |
6 | | * All rights reserved. |
7 | | * |
8 | | * Redistribution and use in source and binary forms, with or without |
9 | | * modification, are permitted provided that the following conditions |
10 | | * are met: |
11 | | * |
12 | | * 1. Redistributions of source code must retain the above |
13 | | * copyright notice, this list of conditions and the following |
14 | | * disclaimer. |
15 | | * |
16 | | * 2. Redistributions in binary form must reproduce the above |
17 | | * copyright notice, this list of conditions and the following |
18 | | * disclaimer in the documentation and/or other materials |
19 | | * provided with the distribution. |
20 | | * |
21 | | * 3. Neither the name of the copyright holder nor the names of |
22 | | * its contributors may be used to endorse or promote products |
23 | | * derived from this software without specific prior written |
24 | | * permission. |
25 | | * |
26 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
27 | | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
28 | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
29 | | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
30 | | * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
31 | | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
32 | | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
33 | | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
34 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
35 | | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
36 | | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
37 | | * OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | | */ |
39 | | |
40 | | /** |
41 | | * @file UriParse.c |
42 | | * Holds the RFC 3986 %URI parsing implementation. |
43 | | * NOTE: This source file includes itself twice. |
44 | | */ |
45 | | |
46 | | /* What encodings are enabled? */ |
47 | | #include <uriparser/UriDefsConfig.h> |
48 | | #if (!defined(URI_PASS_ANSI) && !defined(URI_PASS_UNICODE)) |
49 | | /* Include SELF twice */ |
50 | | # ifdef URI_ENABLE_ANSI |
51 | | # define URI_PASS_ANSI 1 |
52 | | # include "UriParse.c" |
53 | | # undef URI_PASS_ANSI |
54 | | # endif |
55 | | # ifdef URI_ENABLE_UNICODE |
56 | | # define URI_PASS_UNICODE 1 |
57 | | # include "UriParse.c" |
58 | | # undef URI_PASS_UNICODE |
59 | | # endif |
60 | | #else |
61 | | # ifdef URI_PASS_ANSI |
62 | | # include <uriparser/UriDefsAnsi.h> |
63 | | # else |
64 | | # include <uriparser/UriDefsUnicode.h> |
65 | | # include <wchar.h> |
66 | | # endif |
67 | | |
68 | | |
69 | | |
70 | | #ifndef URI_DOXYGEN |
71 | | # include <uriparser/Uri.h> |
72 | | # include <uriparser/UriIp4.h> |
73 | | # include "UriCommon.h" |
74 | | # include "UriMemory.h" |
75 | | # include "UriParseBase.h" |
76 | | #endif |
77 | | |
78 | | |
79 | | |
80 | | #define URI_SET_DIGIT \ |
81 | 0 | _UT('0'): \ |
82 | 0 | case _UT('1'): \ |
83 | 0 | case _UT('2'): \ |
84 | 0 | case _UT('3'): \ |
85 | 0 | case _UT('4'): \ |
86 | 0 | case _UT('5'): \ |
87 | 0 | case _UT('6'): \ |
88 | 0 | case _UT('7'): \ |
89 | 0 | case _UT('8'): \ |
90 | 0 | case _UT('9') |
91 | | |
92 | | #define URI_SET_HEX_LETTER_UPPER \ |
93 | 0 | _UT('A'): \ |
94 | 0 | case _UT('B'): \ |
95 | 0 | case _UT('C'): \ |
96 | 0 | case _UT('D'): \ |
97 | 0 | case _UT('E'): \ |
98 | 0 | case _UT('F') |
99 | | |
100 | | #define URI_SET_HEX_LETTER_LOWER \ |
101 | 0 | _UT('a'): \ |
102 | 0 | case _UT('b'): \ |
103 | 0 | case _UT('c'): \ |
104 | 0 | case _UT('d'): \ |
105 | 0 | case _UT('e'): \ |
106 | 0 | case _UT('f') |
107 | | |
108 | | #define URI_SET_HEXDIG \ |
109 | 0 | URI_SET_DIGIT: \ |
110 | 0 | case URI_SET_HEX_LETTER_UPPER: \ |
111 | 0 | case URI_SET_HEX_LETTER_LOWER |
112 | | |
113 | | #define URI_SET_ALPHA \ |
114 | 0 | URI_SET_HEX_LETTER_UPPER: \ |
115 | 0 | case URI_SET_HEX_LETTER_LOWER: \ |
116 | 0 | case _UT('g'): \ |
117 | 0 | case _UT('G'): \ |
118 | 0 | case _UT('h'): \ |
119 | 0 | case _UT('H'): \ |
120 | 0 | case _UT('i'): \ |
121 | 0 | case _UT('I'): \ |
122 | 0 | case _UT('j'): \ |
123 | 0 | case _UT('J'): \ |
124 | 0 | case _UT('k'): \ |
125 | 0 | case _UT('K'): \ |
126 | 0 | case _UT('l'): \ |
127 | 0 | case _UT('L'): \ |
128 | 0 | case _UT('m'): \ |
129 | 0 | case _UT('M'): \ |
130 | 0 | case _UT('n'): \ |
131 | 0 | case _UT('N'): \ |
132 | 0 | case _UT('o'): \ |
133 | 0 | case _UT('O'): \ |
134 | 0 | case _UT('p'): \ |
135 | 0 | case _UT('P'): \ |
136 | 0 | case _UT('q'): \ |
137 | 0 | case _UT('Q'): \ |
138 | 0 | case _UT('r'): \ |
139 | 0 | case _UT('R'): \ |
140 | 0 | case _UT('s'): \ |
141 | 0 | case _UT('S'): \ |
142 | 0 | case _UT('t'): \ |
143 | 0 | case _UT('T'): \ |
144 | 0 | case _UT('u'): \ |
145 | 0 | case _UT('U'): \ |
146 | 0 | case _UT('v'): \ |
147 | 0 | case _UT('V'): \ |
148 | 0 | case _UT('w'): \ |
149 | 0 | case _UT('W'): \ |
150 | 0 | case _UT('x'): \ |
151 | 0 | case _UT('X'): \ |
152 | 0 | case _UT('y'): \ |
153 | 0 | case _UT('Y'): \ |
154 | 0 | case _UT('z'): \ |
155 | 0 | case _UT('Z') |
156 | | |
157 | | |
158 | | |
159 | | static const URI_CHAR * URI_FUNC(ParseAuthority)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
160 | | static const URI_CHAR * URI_FUNC(ParseAuthorityTwo)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast); |
161 | | static const URI_CHAR * URI_FUNC(ParseHexZero)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast); |
162 | | static const URI_CHAR * URI_FUNC(ParseHierPart)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
163 | | static const URI_CHAR * URI_FUNC(ParseIpFutLoop)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
164 | | static const URI_CHAR * URI_FUNC(ParseIpFutStopGo)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
165 | | static const URI_CHAR * URI_FUNC(ParseIpLit2)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
166 | | static const URI_CHAR * URI_FUNC(ParseIPv6address2)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
167 | | static const URI_CHAR * URI_FUNC(ParseMustBeSegmentNzNc)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
168 | | static const URI_CHAR * URI_FUNC(ParseOwnHost)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
169 | | static const URI_CHAR * URI_FUNC(ParseOwnHost2)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
170 | | static const URI_CHAR * URI_FUNC(ParseOwnHostUserInfo)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
171 | | static const URI_CHAR * URI_FUNC(ParseOwnHostUserInfoNz)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
172 | | static const URI_CHAR * URI_FUNC(ParseOwnPortUserInfo)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
173 | | static const URI_CHAR * URI_FUNC(ParseOwnUserInfo)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
174 | | static const URI_CHAR * URI_FUNC(ParsePartHelperTwo)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
175 | | static const URI_CHAR * URI_FUNC(ParsePathAbsEmpty)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
176 | | static const URI_CHAR * URI_FUNC(ParsePathAbsNoLeadSlash)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
177 | | static const URI_CHAR * URI_FUNC(ParsePathRootless)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
178 | | static const URI_CHAR * URI_FUNC(ParsePchar)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
179 | | static const URI_CHAR * URI_FUNC(ParsePctEncoded)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
180 | | static const URI_CHAR * URI_FUNC(ParsePctSubUnres)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
181 | | static const URI_CHAR * URI_FUNC(ParsePort)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast); |
182 | | static const URI_CHAR * URI_FUNC(ParseQueryFrag)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
183 | | static const URI_CHAR * URI_FUNC(ParseSegment)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
184 | | static const URI_CHAR * URI_FUNC(ParseSegmentNz)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
185 | | static const URI_CHAR * URI_FUNC(ParseSegmentNzNcOrScheme2)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
186 | | static const URI_CHAR * URI_FUNC(ParseUriReference)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
187 | | static const URI_CHAR * URI_FUNC(ParseUriTail)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
188 | | static const URI_CHAR * URI_FUNC(ParseUriTailTwo)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
189 | | static const URI_CHAR * URI_FUNC(ParseZeroMoreSlashSegs)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory); |
190 | | |
191 | | static UriBool URI_FUNC(OnExitOwnHost2)(URI_TYPE(ParserState) * state, const URI_CHAR * first, UriMemoryManager * memory); |
192 | | static UriBool URI_FUNC(OnExitOwnHostUserInfo)(URI_TYPE(ParserState) * state, const URI_CHAR * first, UriMemoryManager * memory); |
193 | | static UriBool URI_FUNC(OnExitOwnPortUserInfo)(URI_TYPE(ParserState) * state, const URI_CHAR * first, UriMemoryManager * memory); |
194 | | static UriBool URI_FUNC(OnExitSegmentNzNcOrScheme2)(URI_TYPE(ParserState) * state, const URI_CHAR * first, UriMemoryManager * memory); |
195 | | static void URI_FUNC(OnExitPartHelperTwo)(URI_TYPE(ParserState) * state); |
196 | | |
197 | | static void URI_FUNC(ResetParserStateExceptUri)(URI_TYPE(ParserState) * state); |
198 | | |
199 | | static UriBool URI_FUNC(PushPathSegment)(URI_TYPE(ParserState) * state, |
200 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
201 | | UriMemoryManager * memory); |
202 | | |
203 | | static void URI_FUNC(StopSyntax)(URI_TYPE(ParserState) * state, const URI_CHAR * errorPos, UriMemoryManager * memory); |
204 | | static void URI_FUNC(StopMalloc)(URI_TYPE(ParserState) * state, UriMemoryManager * memory); |
205 | | |
206 | | static int URI_FUNC(ParseUriExMm)(URI_TYPE(ParserState) * state, |
207 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
208 | | UriMemoryManager * memory); |
209 | | |
210 | | |
211 | | |
212 | | static URI_INLINE void URI_FUNC(StopSyntax)(URI_TYPE(ParserState) * state, |
213 | 0 | const URI_CHAR * errorPos, UriMemoryManager * memory) { |
214 | 0 | URI_FUNC(FreeUriMembersMm)(state->uri, memory); |
215 | 0 | state->errorPos = errorPos; |
216 | 0 | state->errorCode = URI_ERROR_SYNTAX; |
217 | 0 | } Unexecuted instantiation: UriParse.c:uriStopSyntaxA Unexecuted instantiation: UriParse.c:uriStopSyntaxW |
218 | | |
219 | | |
220 | | |
221 | 0 | static URI_INLINE void URI_FUNC(StopMalloc)(URI_TYPE(ParserState) * state, UriMemoryManager * memory) { |
222 | 0 | URI_FUNC(FreeUriMembersMm)(state->uri, memory); |
223 | 0 | state->errorPos = NULL; |
224 | 0 | state->errorCode = URI_ERROR_MALLOC; |
225 | 0 | } Unexecuted instantiation: UriParse.c:uriStopMallocA Unexecuted instantiation: UriParse.c:uriStopMallocW |
226 | | |
227 | | |
228 | | |
229 | | /* |
230 | | * [authority]-><[>[ipLit2][authorityTwo] |
231 | | * [authority]->[ownHostUserInfoNz] |
232 | | * [authority]-><NULL> |
233 | | */ |
234 | | static URI_INLINE const URI_CHAR * URI_FUNC(ParseAuthority)( |
235 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
236 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
237 | 0 | if (first >= afterLast) { |
238 | | /* "" regname host */ |
239 | 0 | state->uri->hostText.first = URI_FUNC(SafeToPointTo); |
240 | 0 | state->uri->hostText.afterLast = URI_FUNC(SafeToPointTo); |
241 | 0 | return afterLast; |
242 | 0 | } |
243 | | |
244 | 0 | switch (*first) { |
245 | 0 | case _UT('['): |
246 | 0 | { |
247 | 0 | const URI_CHAR * const afterIpLit2 |
248 | 0 | = URI_FUNC(ParseIpLit2)(state, first + 1, afterLast, memory); |
249 | 0 | if (afterIpLit2 == NULL) { |
250 | 0 | return NULL; |
251 | 0 | } |
252 | 0 | state->uri->hostText.first = first + 1; /* HOST BEGIN */ |
253 | 0 | return URI_FUNC(ParseAuthorityTwo)(state, afterIpLit2, afterLast); |
254 | 0 | } |
255 | | |
256 | 0 | case _UT('!'): |
257 | 0 | case _UT('$'): |
258 | 0 | case _UT('%'): |
259 | 0 | case _UT('&'): |
260 | 0 | case _UT('('): |
261 | 0 | case _UT(')'): |
262 | 0 | case _UT('-'): |
263 | 0 | case _UT('*'): |
264 | 0 | case _UT(','): |
265 | 0 | case _UT('.'): |
266 | 0 | case _UT(':'): |
267 | 0 | case _UT(';'): |
268 | 0 | case _UT('@'): |
269 | 0 | case _UT('\''): |
270 | 0 | case _UT('_'): |
271 | 0 | case _UT('~'): |
272 | 0 | case _UT('+'): |
273 | 0 | case _UT('='): |
274 | 0 | case URI_SET_DIGIT: |
275 | 0 | case URI_SET_ALPHA: |
276 | 0 | state->uri->userInfo.first = first; /* USERINFO BEGIN */ |
277 | 0 | return URI_FUNC(ParseOwnHostUserInfoNz)(state, first, afterLast, memory); |
278 | | |
279 | 0 | default: |
280 | | /* "" regname host */ |
281 | 0 | state->uri->hostText.first = URI_FUNC(SafeToPointTo); |
282 | 0 | state->uri->hostText.afterLast = URI_FUNC(SafeToPointTo); |
283 | 0 | return first; |
284 | 0 | } |
285 | 0 | } Unexecuted instantiation: UriParse.c:uriParseAuthorityA Unexecuted instantiation: UriParse.c:uriParseAuthorityW |
286 | | |
287 | | |
288 | | |
289 | | /* |
290 | | * [authorityTwo]-><:>[port] |
291 | | * [authorityTwo]-><NULL> |
292 | | */ |
293 | 0 | static URI_INLINE const URI_CHAR * URI_FUNC(ParseAuthorityTwo)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast) { |
294 | 0 | if (first >= afterLast) { |
295 | 0 | return afterLast; |
296 | 0 | } |
297 | | |
298 | 0 | switch (*first) { |
299 | 0 | case _UT(':'): |
300 | 0 | { |
301 | 0 | const URI_CHAR * const afterPort = URI_FUNC(ParsePort)(state, first + 1, afterLast); |
302 | 0 | if (afterPort == NULL) { |
303 | 0 | return NULL; |
304 | 0 | } |
305 | 0 | state->uri->portText.first = first + 1; /* PORT BEGIN */ |
306 | 0 | state->uri->portText.afterLast = afterPort; /* PORT END */ |
307 | 0 | return afterPort; |
308 | 0 | } |
309 | | |
310 | 0 | default: |
311 | 0 | return first; |
312 | 0 | } |
313 | 0 | } Unexecuted instantiation: UriParse.c:uriParseAuthorityTwoA Unexecuted instantiation: UriParse.c:uriParseAuthorityTwoW |
314 | | |
315 | | |
316 | | |
317 | | /* |
318 | | * [hexZero]->[HEXDIG][hexZero] |
319 | | * [hexZero]-><NULL> |
320 | | */ |
321 | 0 | static const URI_CHAR * URI_FUNC(ParseHexZero)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast) { |
322 | 0 | if (first >= afterLast) { |
323 | 0 | return afterLast; |
324 | 0 | } |
325 | | |
326 | 0 | switch (*first) { |
327 | 0 | case URI_SET_HEXDIG: |
328 | 0 | return URI_FUNC(ParseHexZero)(state, first + 1, afterLast); |
329 | | |
330 | 0 | default: |
331 | 0 | return first; |
332 | 0 | } |
333 | 0 | } Unexecuted instantiation: UriParse.c:uriParseHexZeroA Unexecuted instantiation: UriParse.c:uriParseHexZeroW |
334 | | |
335 | | |
336 | | |
337 | | /* |
338 | | * [hierPart]->[pathRootless] |
339 | | * [hierPart]-></>[partHelperTwo] |
340 | | * [hierPart]-><NULL> |
341 | | */ |
342 | | static URI_INLINE const URI_CHAR * URI_FUNC(ParseHierPart)( |
343 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
344 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
345 | 0 | if (first >= afterLast) { |
346 | 0 | return afterLast; |
347 | 0 | } |
348 | | |
349 | 0 | switch (*first) { |
350 | 0 | case _UT('!'): |
351 | 0 | case _UT('$'): |
352 | 0 | case _UT('%'): |
353 | 0 | case _UT('&'): |
354 | 0 | case _UT('('): |
355 | 0 | case _UT(')'): |
356 | 0 | case _UT('-'): |
357 | 0 | case _UT('*'): |
358 | 0 | case _UT(','): |
359 | 0 | case _UT('.'): |
360 | 0 | case _UT(':'): |
361 | 0 | case _UT(';'): |
362 | 0 | case _UT('@'): |
363 | 0 | case _UT('\''): |
364 | 0 | case _UT('_'): |
365 | 0 | case _UT('~'): |
366 | 0 | case _UT('+'): |
367 | 0 | case _UT('='): |
368 | 0 | case URI_SET_DIGIT: |
369 | 0 | case URI_SET_ALPHA: |
370 | 0 | return URI_FUNC(ParsePathRootless)(state, first, afterLast, memory); |
371 | | |
372 | 0 | case _UT('/'): |
373 | 0 | return URI_FUNC(ParsePartHelperTwo)(state, first + 1, afterLast, memory); |
374 | | |
375 | 0 | default: |
376 | 0 | return first; |
377 | 0 | } |
378 | 0 | } Unexecuted instantiation: UriParse.c:uriParseHierPartA Unexecuted instantiation: UriParse.c:uriParseHierPartW |
379 | | |
380 | | |
381 | | |
382 | | /* |
383 | | * [ipFutLoop]->[subDelims][ipFutStopGo] |
384 | | * [ipFutLoop]->[unreserved][ipFutStopGo] |
385 | | * [ipFutLoop]-><:>[ipFutStopGo] |
386 | | */ |
387 | | static const URI_CHAR * URI_FUNC(ParseIpFutLoop)(URI_TYPE(ParserState) * state, |
388 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
389 | 0 | UriMemoryManager * memory) { |
390 | 0 | if (first >= afterLast) { |
391 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
392 | 0 | return NULL; |
393 | 0 | } |
394 | | |
395 | 0 | switch (*first) { |
396 | 0 | case _UT('!'): |
397 | 0 | case _UT('$'): |
398 | 0 | case _UT('&'): |
399 | 0 | case _UT('('): |
400 | 0 | case _UT(')'): |
401 | 0 | case _UT('-'): |
402 | 0 | case _UT('*'): |
403 | 0 | case _UT(','): |
404 | 0 | case _UT('.'): |
405 | 0 | case _UT(':'): |
406 | 0 | case _UT(';'): |
407 | 0 | case _UT('\''): |
408 | 0 | case _UT('_'): |
409 | 0 | case _UT('~'): |
410 | 0 | case _UT('+'): |
411 | 0 | case _UT('='): |
412 | 0 | case URI_SET_DIGIT: |
413 | 0 | case URI_SET_ALPHA: |
414 | 0 | return URI_FUNC(ParseIpFutStopGo)(state, first + 1, afterLast, memory); |
415 | | |
416 | 0 | default: |
417 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
418 | 0 | return NULL; |
419 | 0 | } |
420 | 0 | } Unexecuted instantiation: UriParse.c:uriParseIpFutLoopA Unexecuted instantiation: UriParse.c:uriParseIpFutLoopW |
421 | | |
422 | | |
423 | | |
424 | | /* |
425 | | * [ipFutStopGo]->[ipFutLoop] |
426 | | * [ipFutStopGo]-><NULL> |
427 | | */ |
428 | | static const URI_CHAR * URI_FUNC(ParseIpFutStopGo)( |
429 | | URI_TYPE(ParserState) * state, |
430 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
431 | 0 | UriMemoryManager * memory) { |
432 | 0 | if (first >= afterLast) { |
433 | 0 | return afterLast; |
434 | 0 | } |
435 | | |
436 | 0 | switch (*first) { |
437 | 0 | case _UT('!'): |
438 | 0 | case _UT('$'): |
439 | 0 | case _UT('&'): |
440 | 0 | case _UT('('): |
441 | 0 | case _UT(')'): |
442 | 0 | case _UT('-'): |
443 | 0 | case _UT('*'): |
444 | 0 | case _UT(','): |
445 | 0 | case _UT('.'): |
446 | 0 | case _UT(':'): |
447 | 0 | case _UT(';'): |
448 | 0 | case _UT('\''): |
449 | 0 | case _UT('_'): |
450 | 0 | case _UT('~'): |
451 | 0 | case _UT('+'): |
452 | 0 | case _UT('='): |
453 | 0 | case URI_SET_DIGIT: |
454 | 0 | case URI_SET_ALPHA: |
455 | 0 | return URI_FUNC(ParseIpFutLoop)(state, first, afterLast, memory); |
456 | | |
457 | 0 | default: |
458 | 0 | return first; |
459 | 0 | } |
460 | 0 | } Unexecuted instantiation: UriParse.c:uriParseIpFutStopGoA Unexecuted instantiation: UriParse.c:uriParseIpFutStopGoW |
461 | | |
462 | | |
463 | | |
464 | | /* |
465 | | * [ipFuture]-><v>[HEXDIG][hexZero]<.>[ipFutLoop] |
466 | | */ |
467 | | static const URI_CHAR * URI_FUNC(ParseIpFuture)(URI_TYPE(ParserState) * state, |
468 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
469 | 0 | UriMemoryManager * memory) { |
470 | 0 | if (first >= afterLast) { |
471 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
472 | 0 | return NULL; |
473 | 0 | } |
474 | | |
475 | | /* |
476 | | First character has already been |
477 | | checked before entering this rule. |
478 | | |
479 | | switch (*first) { |
480 | | case _UT('v'): |
481 | | case _UT('V'): |
482 | | */ |
483 | 0 | if (first + 1 >= afterLast) { |
484 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
485 | 0 | return NULL; |
486 | 0 | } |
487 | | |
488 | 0 | switch (first[1]) { |
489 | 0 | case URI_SET_HEXDIG: |
490 | 0 | { |
491 | 0 | const URI_CHAR * afterIpFutLoop; |
492 | 0 | const URI_CHAR * const afterHexZero |
493 | 0 | = URI_FUNC(ParseHexZero)(state, first + 2, afterLast); |
494 | 0 | if (afterHexZero == NULL) { |
495 | 0 | return NULL; |
496 | 0 | } |
497 | 0 | if (afterHexZero >= afterLast) { |
498 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
499 | 0 | return NULL; |
500 | 0 | } |
501 | 0 | if (*afterHexZero != _UT('.')) { |
502 | 0 | URI_FUNC(StopSyntax)(state, afterHexZero, memory); |
503 | 0 | return NULL; |
504 | 0 | } |
505 | 0 | state->uri->hostText.first = first; /* HOST BEGIN */ |
506 | 0 | state->uri->hostData.ipFuture.first = first; /* IPFUTURE BEGIN */ |
507 | 0 | afterIpFutLoop = URI_FUNC(ParseIpFutLoop)(state, afterHexZero + 1, afterLast, memory); |
508 | 0 | if (afterIpFutLoop == NULL) { |
509 | 0 | return NULL; |
510 | 0 | } |
511 | 0 | state->uri->hostText.afterLast = afterIpFutLoop; /* HOST END */ |
512 | 0 | state->uri->hostData.ipFuture.afterLast = afterIpFutLoop; /* IPFUTURE END */ |
513 | 0 | return afterIpFutLoop; |
514 | 0 | } |
515 | | |
516 | 0 | default: |
517 | 0 | URI_FUNC(StopSyntax)(state, first + 1, memory); |
518 | 0 | return NULL; |
519 | 0 | } |
520 | | |
521 | | /* |
522 | | default: |
523 | | URI_FUNC(StopSyntax)(state, first, memory); |
524 | | return NULL; |
525 | | } |
526 | | */ |
527 | 0 | } Unexecuted instantiation: UriParse.c:uriParseIpFutureA Unexecuted instantiation: UriParse.c:uriParseIpFutureW |
528 | | |
529 | | |
530 | | |
531 | | /* |
532 | | * [ipLit2]->[ipFuture]<]> |
533 | | * [ipLit2]->[IPv6address2] |
534 | | */ |
535 | | static URI_INLINE const URI_CHAR * URI_FUNC(ParseIpLit2)( |
536 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
537 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
538 | 0 | if (first >= afterLast) { |
539 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
540 | 0 | return NULL; |
541 | 0 | } |
542 | | |
543 | 0 | switch (*first) { |
544 | | /* The leading "v" of IPvFuture is case-insensitive. */ |
545 | 0 | case _UT('v'): |
546 | 0 | case _UT('V'): |
547 | 0 | { |
548 | 0 | const URI_CHAR * const afterIpFuture |
549 | 0 | = URI_FUNC(ParseIpFuture)(state, first, afterLast, memory); |
550 | 0 | if (afterIpFuture == NULL) { |
551 | 0 | return NULL; |
552 | 0 | } |
553 | 0 | if (afterIpFuture >= afterLast) { |
554 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
555 | 0 | return NULL; |
556 | 0 | } |
557 | 0 | if (*afterIpFuture != _UT(']')) { |
558 | 0 | URI_FUNC(StopSyntax)(state, afterIpFuture, memory); |
559 | 0 | return NULL; |
560 | 0 | } |
561 | 0 | return afterIpFuture + 1; |
562 | 0 | } |
563 | | |
564 | 0 | case _UT(':'): |
565 | 0 | case _UT(']'): |
566 | 0 | case URI_SET_HEXDIG: |
567 | 0 | state->uri->hostData.ip6 = memory->malloc(memory, 1 * sizeof(UriIp6)); /* Freed when stopping on parse error */ |
568 | 0 | if (state->uri->hostData.ip6 == NULL) { |
569 | 0 | URI_FUNC(StopMalloc)(state, memory); |
570 | 0 | return NULL; |
571 | 0 | } |
572 | 0 | return URI_FUNC(ParseIPv6address2)(state, first, afterLast, memory); |
573 | | |
574 | 0 | default: |
575 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
576 | 0 | return NULL; |
577 | 0 | } |
578 | 0 | } Unexecuted instantiation: UriParse.c:uriParseIpLit2A Unexecuted instantiation: UriParse.c:uriParseIpLit2W |
579 | | |
580 | | |
581 | | |
582 | | /* |
583 | | * [IPv6address2]->..<]> |
584 | | */ |
585 | | static const URI_CHAR * URI_FUNC(ParseIPv6address2)( |
586 | | URI_TYPE(ParserState) * state, |
587 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
588 | 0 | UriMemoryManager * memory) { |
589 | 0 | int zipperEver = 0; |
590 | 0 | int quadsDone = 0; |
591 | 0 | int digitCount = 0; |
592 | 0 | unsigned char digitHistory[4]; |
593 | 0 | int ip4OctetsDone = 0; |
594 | |
|
595 | 0 | unsigned char quadsAfterZipper[14]; |
596 | 0 | int quadsAfterZipperCount = 0; |
597 | | |
598 | |
|
599 | 0 | for (;;) { |
600 | 0 | if (first >= afterLast) { |
601 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
602 | 0 | return NULL; |
603 | 0 | } |
604 | | |
605 | | /* Inside IPv4 part? */ |
606 | 0 | if (ip4OctetsDone > 0) { |
607 | | /* Eat rest of IPv4 address */ |
608 | 0 | for (;;) { |
609 | 0 | switch (*first) { |
610 | 0 | case URI_SET_DIGIT: |
611 | 0 | if (digitCount == 4) { |
612 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
613 | 0 | return NULL; |
614 | 0 | } |
615 | 0 | digitHistory[digitCount++] = (unsigned char)(9 + *first - _UT('9')); |
616 | 0 | break; |
617 | | |
618 | 0 | case _UT('.'): |
619 | 0 | if ((ip4OctetsDone == 4) /* NOTE! */ |
620 | 0 | || (digitCount == 0) |
621 | 0 | || (digitCount == 4)) { |
622 | | /* Invalid digit or octet count */ |
623 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
624 | 0 | return NULL; |
625 | 0 | } else if ((digitCount > 1) |
626 | 0 | && (digitHistory[0] == 0)) { |
627 | | /* Leading zero */ |
628 | 0 | URI_FUNC(StopSyntax)(state, first - digitCount, memory); |
629 | 0 | return NULL; |
630 | 0 | } else if ((digitCount == 3) |
631 | 0 | && (100 * digitHistory[0] |
632 | 0 | + 10 * digitHistory[1] |
633 | 0 | + digitHistory[2] > 255)) { |
634 | | /* Octet value too large */ |
635 | 0 | if (digitHistory[0] > 2) { |
636 | 0 | URI_FUNC(StopSyntax)(state, first - 3, memory); |
637 | 0 | } else if (digitHistory[1] > 5) { |
638 | 0 | URI_FUNC(StopSyntax)(state, first - 2, memory); |
639 | 0 | } else { |
640 | 0 | URI_FUNC(StopSyntax)(state, first - 1, memory); |
641 | 0 | } |
642 | 0 | return NULL; |
643 | 0 | } |
644 | | |
645 | | /* Copy IPv4 octet */ |
646 | 0 | state->uri->hostData.ip6->data[16 - 4 + ip4OctetsDone] = uriGetOctetValue(digitHistory, digitCount); |
647 | 0 | digitCount = 0; |
648 | 0 | ip4OctetsDone++; |
649 | 0 | break; |
650 | | |
651 | 0 | case _UT(']'): |
652 | 0 | if ((ip4OctetsDone != 3) /* NOTE! */ |
653 | 0 | || (digitCount == 0) |
654 | 0 | || (digitCount == 4)) { |
655 | | /* Invalid digit or octet count */ |
656 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
657 | 0 | return NULL; |
658 | 0 | } else if ((digitCount > 1) |
659 | 0 | && (digitHistory[0] == 0)) { |
660 | | /* Leading zero */ |
661 | 0 | URI_FUNC(StopSyntax)(state, first - digitCount, memory); |
662 | 0 | return NULL; |
663 | 0 | } else if ((digitCount == 3) |
664 | 0 | && (100 * digitHistory[0] |
665 | 0 | + 10 * digitHistory[1] |
666 | 0 | + digitHistory[2] > 255)) { |
667 | | /* Octet value too large */ |
668 | 0 | if (digitHistory[0] > 2) { |
669 | 0 | URI_FUNC(StopSyntax)(state, first - 3, memory); |
670 | 0 | } else if (digitHistory[1] > 5) { |
671 | 0 | URI_FUNC(StopSyntax)(state, first - 2, memory); |
672 | 0 | } else { |
673 | 0 | URI_FUNC(StopSyntax)(state, first - 1, memory); |
674 | 0 | } |
675 | 0 | return NULL; |
676 | 0 | } |
677 | | |
678 | 0 | state->uri->hostText.afterLast = first; /* HOST END */ |
679 | | |
680 | | /* Copy missing quads right before IPv4 */ |
681 | 0 | memcpy(state->uri->hostData.ip6->data + 16 - 4 - 2 * quadsAfterZipperCount, |
682 | 0 | quadsAfterZipper, 2 * quadsAfterZipperCount); |
683 | | |
684 | | /* Copy last IPv4 octet */ |
685 | 0 | state->uri->hostData.ip6->data[16 - 4 + 3] = uriGetOctetValue(digitHistory, digitCount); |
686 | |
|
687 | 0 | return first + 1; |
688 | | |
689 | 0 | default: |
690 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
691 | 0 | return NULL; |
692 | 0 | } |
693 | 0 | first++; |
694 | |
|
695 | 0 | if (first >= afterLast) { |
696 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
697 | 0 | return NULL; |
698 | 0 | } |
699 | 0 | } |
700 | 0 | } else { |
701 | | /* Eat while no dot in sight */ |
702 | 0 | int letterAmong = 0; |
703 | 0 | int walking = 1; |
704 | 0 | do { |
705 | 0 | switch (*first) { |
706 | 0 | case URI_SET_HEX_LETTER_LOWER: |
707 | 0 | letterAmong = 1; |
708 | 0 | if (digitCount == 4) { |
709 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
710 | 0 | return NULL; |
711 | 0 | } |
712 | 0 | digitHistory[digitCount] = (unsigned char)(15 + *first - _UT('f')); |
713 | 0 | digitCount++; |
714 | 0 | break; |
715 | | |
716 | 0 | case URI_SET_HEX_LETTER_UPPER: |
717 | 0 | letterAmong = 1; |
718 | 0 | if (digitCount == 4) { |
719 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
720 | 0 | return NULL; |
721 | 0 | } |
722 | 0 | digitHistory[digitCount] = (unsigned char)(15 + *first - _UT('F')); |
723 | 0 | digitCount++; |
724 | 0 | break; |
725 | | |
726 | 0 | case URI_SET_DIGIT: |
727 | 0 | if (digitCount == 4) { |
728 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
729 | 0 | return NULL; |
730 | 0 | } |
731 | 0 | digitHistory[digitCount] = (unsigned char)(9 + *first - _UT('9')); |
732 | 0 | digitCount++; |
733 | 0 | break; |
734 | | |
735 | 0 | case _UT(':'): |
736 | 0 | { |
737 | 0 | int setZipper = 0; |
738 | |
|
739 | 0 | if (digitCount > 0) { |
740 | 0 | if (zipperEver) { |
741 | 0 | uriWriteQuadToDoubleByte(digitHistory, digitCount, quadsAfterZipper + 2 * quadsAfterZipperCount); |
742 | 0 | quadsAfterZipperCount++; |
743 | 0 | } else { |
744 | 0 | uriWriteQuadToDoubleByte(digitHistory, digitCount, state->uri->hostData.ip6->data + 2 * quadsDone); |
745 | 0 | } |
746 | 0 | quadsDone++; |
747 | 0 | digitCount = 0; |
748 | 0 | } |
749 | 0 | letterAmong = 0; |
750 | | |
751 | | /* Too many quads? */ |
752 | 0 | if (quadsDone >= 8 - zipperEver) { |
753 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
754 | 0 | return NULL; |
755 | 0 | } |
756 | | |
757 | | /* "::"? */ |
758 | 0 | if (first + 1 >= afterLast) { |
759 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
760 | 0 | return NULL; |
761 | 0 | } |
762 | 0 | if (first[1] == _UT(':')) { |
763 | 0 | const int resetOffset = 2 * (quadsDone + (digitCount > 0)); |
764 | |
|
765 | 0 | first++; |
766 | 0 | if (zipperEver) { |
767 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
768 | 0 | return NULL; /* "::.+::" */ |
769 | 0 | } |
770 | | |
771 | | /* Zero everything after zipper */ |
772 | 0 | memset(state->uri->hostData.ip6->data + resetOffset, 0, 16 - resetOffset); |
773 | 0 | setZipper = 1; |
774 | | |
775 | | /* ":::+"? */ |
776 | 0 | if (first + 1 >= afterLast) { |
777 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
778 | 0 | return NULL; /* No ']' yet */ |
779 | 0 | } |
780 | 0 | if (first[1] == _UT(':')) { |
781 | 0 | URI_FUNC(StopSyntax)(state, first + 1, memory); |
782 | 0 | return NULL; /* ":::+ "*/ |
783 | 0 | } |
784 | 0 | } else if (quadsDone == 0 || first[1] == _UT(']')) { |
785 | | /* Single leading or trailing ":" */ |
786 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
787 | 0 | return NULL; |
788 | 0 | } |
789 | | |
790 | 0 | if (setZipper) { |
791 | 0 | zipperEver = 1; |
792 | 0 | } |
793 | 0 | } |
794 | 0 | break; |
795 | | |
796 | 0 | case _UT('.'): |
797 | 0 | if ((quadsDone + zipperEver > 6) /* NOTE */ |
798 | 0 | || (!zipperEver && (quadsDone < 6)) |
799 | 0 | || letterAmong |
800 | 0 | || (digitCount == 0) |
801 | 0 | || (digitCount == 4)) { |
802 | | /* Invalid octet before */ |
803 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
804 | 0 | return NULL; |
805 | 0 | } else if ((digitCount > 1) |
806 | 0 | && (digitHistory[0] == 0)) { |
807 | | /* Leading zero */ |
808 | 0 | URI_FUNC(StopSyntax)(state, first - digitCount, memory); |
809 | 0 | return NULL; |
810 | 0 | } else if ((digitCount == 3) |
811 | 0 | && (100 * digitHistory[0] |
812 | 0 | + 10 * digitHistory[1] |
813 | 0 | + digitHistory[2] > 255)) { |
814 | | /* Octet value too large */ |
815 | 0 | if (digitHistory[0] > 2) { |
816 | 0 | URI_FUNC(StopSyntax)(state, first - 3, memory); |
817 | 0 | } else if (digitHistory[1] > 5) { |
818 | 0 | URI_FUNC(StopSyntax)(state, first - 2, memory); |
819 | 0 | } else { |
820 | 0 | URI_FUNC(StopSyntax)(state, first - 1, memory); |
821 | 0 | } |
822 | 0 | return NULL; |
823 | 0 | } |
824 | | |
825 | | /* Copy first IPv4 octet */ |
826 | 0 | state->uri->hostData.ip6->data[16 - 4] = uriGetOctetValue(digitHistory, digitCount); |
827 | 0 | digitCount = 0; |
828 | | |
829 | | /* Switch over to IPv4 loop */ |
830 | 0 | ip4OctetsDone = 1; |
831 | 0 | walking = 0; |
832 | 0 | break; |
833 | | |
834 | 0 | case _UT(']'): |
835 | | /* Too little quads? */ |
836 | 0 | if (!zipperEver && !((quadsDone == 7) && (digitCount > 0))) { |
837 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
838 | 0 | return NULL; |
839 | 0 | } |
840 | | |
841 | 0 | if (digitCount > 0) { |
842 | 0 | if (zipperEver) { |
843 | | /* Too many quads? */ |
844 | 0 | if (quadsDone >= 7) { |
845 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
846 | 0 | return NULL; |
847 | 0 | } |
848 | 0 | uriWriteQuadToDoubleByte(digitHistory, digitCount, quadsAfterZipper + 2 * quadsAfterZipperCount); |
849 | 0 | quadsAfterZipperCount++; |
850 | 0 | } else { |
851 | 0 | uriWriteQuadToDoubleByte(digitHistory, digitCount, state->uri->hostData.ip6->data + 2 * quadsDone); |
852 | 0 | } |
853 | | /* |
854 | | quadsDone++; |
855 | | digitCount = 0; |
856 | | */ |
857 | 0 | } |
858 | | |
859 | | /* Copy missing quads to the end */ |
860 | 0 | memcpy(state->uri->hostData.ip6->data + 16 - 2 * quadsAfterZipperCount, |
861 | 0 | quadsAfterZipper, 2 * quadsAfterZipperCount); |
862 | |
|
863 | 0 | state->uri->hostText.afterLast = first; /* HOST END */ |
864 | 0 | return first + 1; /* Fine */ |
865 | | |
866 | 0 | default: |
867 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
868 | 0 | return NULL; |
869 | 0 | } |
870 | 0 | first++; |
871 | |
|
872 | 0 | if (first >= afterLast) { |
873 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
874 | 0 | return NULL; /* No ']' yet */ |
875 | 0 | } |
876 | 0 | } while (walking); |
877 | 0 | } |
878 | 0 | } |
879 | 0 | } Unexecuted instantiation: UriParse.c:uriParseIPv6address2A Unexecuted instantiation: UriParse.c:uriParseIPv6address2W |
880 | | |
881 | | |
882 | | |
883 | | /* |
884 | | * [mustBeSegmentNzNc]->[pctEncoded][mustBeSegmentNzNc] |
885 | | * [mustBeSegmentNzNc]->[subDelims][mustBeSegmentNzNc] |
886 | | * [mustBeSegmentNzNc]->[unreserved][mustBeSegmentNzNc] |
887 | | * [mustBeSegmentNzNc]->[uriTail] // can take <NULL> |
888 | | * [mustBeSegmentNzNc]-></>[segment][zeroMoreSlashSegs][uriTail] |
889 | | * [mustBeSegmentNzNc]-><@>[mustBeSegmentNzNc] |
890 | | */ |
891 | | static const URI_CHAR * URI_FUNC(ParseMustBeSegmentNzNc)( |
892 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
893 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
894 | 0 | if (first >= afterLast) { |
895 | 0 | if (!URI_FUNC(PushPathSegment)(state, state->uri->scheme.first, first, memory)) { /* SEGMENT BOTH */ |
896 | 0 | URI_FUNC(StopMalloc)(state, memory); |
897 | 0 | return NULL; |
898 | 0 | } |
899 | 0 | state->uri->scheme.first = NULL; /* Not a scheme, reset */ |
900 | 0 | return afterLast; |
901 | 0 | } |
902 | | |
903 | 0 | switch (*first) { |
904 | 0 | case _UT('%'): |
905 | 0 | { |
906 | 0 | const URI_CHAR * const afterPctEncoded |
907 | 0 | = URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory); |
908 | 0 | if (afterPctEncoded == NULL) { |
909 | 0 | return NULL; |
910 | 0 | } |
911 | 0 | return URI_FUNC(ParseMustBeSegmentNzNc)(state, afterPctEncoded, afterLast, memory); |
912 | 0 | } |
913 | | |
914 | 0 | case _UT('@'): |
915 | 0 | case _UT('!'): |
916 | 0 | case _UT('$'): |
917 | 0 | case _UT('&'): |
918 | 0 | case _UT('('): |
919 | 0 | case _UT(')'): |
920 | 0 | case _UT('*'): |
921 | 0 | case _UT(','): |
922 | 0 | case _UT(';'): |
923 | 0 | case _UT('\''): |
924 | 0 | case _UT('+'): |
925 | 0 | case _UT('='): |
926 | 0 | case _UT('-'): |
927 | 0 | case _UT('.'): |
928 | 0 | case _UT('_'): |
929 | 0 | case _UT('~'): |
930 | 0 | case URI_SET_DIGIT: |
931 | 0 | case URI_SET_ALPHA: |
932 | 0 | return URI_FUNC(ParseMustBeSegmentNzNc)(state, first + 1, afterLast, memory); |
933 | | |
934 | 0 | case _UT('/'): |
935 | 0 | { |
936 | 0 | const URI_CHAR * afterZeroMoreSlashSegs; |
937 | 0 | const URI_CHAR * afterSegment; |
938 | 0 | if (!URI_FUNC(PushPathSegment)(state, state->uri->scheme.first, first, memory)) { /* SEGMENT BOTH */ |
939 | 0 | URI_FUNC(StopMalloc)(state, memory); |
940 | 0 | return NULL; |
941 | 0 | } |
942 | 0 | state->uri->scheme.first = NULL; /* Not a scheme, reset */ |
943 | 0 | afterSegment = URI_FUNC(ParseSegment)(state, first + 1, afterLast, memory); |
944 | 0 | if (afterSegment == NULL) { |
945 | 0 | return NULL; |
946 | 0 | } |
947 | 0 | if (!URI_FUNC(PushPathSegment)(state, first + 1, afterSegment, memory)) { /* SEGMENT BOTH */ |
948 | 0 | URI_FUNC(StopMalloc)(state, memory); |
949 | 0 | return NULL; |
950 | 0 | } |
951 | 0 | afterZeroMoreSlashSegs |
952 | 0 | = URI_FUNC(ParseZeroMoreSlashSegs)(state, afterSegment, afterLast, memory); |
953 | 0 | if (afterZeroMoreSlashSegs == NULL) { |
954 | 0 | return NULL; |
955 | 0 | } |
956 | 0 | return URI_FUNC(ParseUriTail)(state, afterZeroMoreSlashSegs, afterLast, memory); |
957 | 0 | } |
958 | | |
959 | 0 | default: |
960 | 0 | if (!URI_FUNC(PushPathSegment)(state, state->uri->scheme.first, first, memory)) { /* SEGMENT BOTH */ |
961 | 0 | URI_FUNC(StopMalloc)(state, memory); |
962 | 0 | return NULL; |
963 | 0 | } |
964 | 0 | state->uri->scheme.first = NULL; /* Not a scheme, reset */ |
965 | 0 | return URI_FUNC(ParseUriTail)(state, first, afterLast, memory); |
966 | 0 | } |
967 | 0 | } Unexecuted instantiation: UriParse.c:uriParseMustBeSegmentNzNcA Unexecuted instantiation: UriParse.c:uriParseMustBeSegmentNzNcW |
968 | | |
969 | | |
970 | | |
971 | | /* |
972 | | * [ownHost]-><[>[ipLit2][authorityTwo] |
973 | | * [ownHost]->[ownHost2] // can take <NULL> |
974 | | */ |
975 | | static URI_INLINE const URI_CHAR * URI_FUNC(ParseOwnHost)( |
976 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
977 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
978 | 0 | if (first >= afterLast) { |
979 | 0 | state->uri->hostText.afterLast = afterLast; /* HOST END */ |
980 | 0 | return afterLast; |
981 | 0 | } |
982 | | |
983 | 0 | switch (*first) { |
984 | 0 | case _UT('['): |
985 | 0 | { |
986 | 0 | const URI_CHAR * const afterIpLit2 |
987 | 0 | = URI_FUNC(ParseIpLit2)(state, first + 1, afterLast, memory); |
988 | 0 | if (afterIpLit2 == NULL) { |
989 | 0 | return NULL; |
990 | 0 | } |
991 | 0 | state->uri->hostText.first = first + 1; /* HOST BEGIN */ |
992 | 0 | return URI_FUNC(ParseAuthorityTwo)(state, afterIpLit2, afterLast); |
993 | 0 | } |
994 | | |
995 | 0 | default: |
996 | 0 | return URI_FUNC(ParseOwnHost2)(state, first, afterLast, memory); |
997 | 0 | } |
998 | 0 | } Unexecuted instantiation: UriParse.c:uriParseOwnHostA Unexecuted instantiation: UriParse.c:uriParseOwnHostW |
999 | | |
1000 | | |
1001 | | |
1002 | | static URI_INLINE UriBool URI_FUNC(OnExitOwnHost2)( |
1003 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
1004 | 0 | UriMemoryManager * memory) { |
1005 | 0 | state->uri->hostText.afterLast = first; /* HOST END */ |
1006 | | |
1007 | | /* Valid IPv4 or just a regname? */ |
1008 | 0 | state->uri->hostData.ip4 = memory->malloc(memory, 1 * sizeof(UriIp4)); /* Freed when stopping on parse error */ |
1009 | 0 | if (state->uri->hostData.ip4 == NULL) { |
1010 | 0 | return URI_FALSE; /* Raises malloc error */ |
1011 | 0 | } |
1012 | 0 | if (URI_FUNC(ParseIpFourAddress)(state->uri->hostData.ip4->data, |
1013 | 0 | state->uri->hostText.first, state->uri->hostText.afterLast)) { |
1014 | | /* Not IPv4 */ |
1015 | 0 | memory->free(memory, state->uri->hostData.ip4); |
1016 | 0 | state->uri->hostData.ip4 = NULL; |
1017 | 0 | } |
1018 | 0 | return URI_TRUE; /* Success */ |
1019 | 0 | } Unexecuted instantiation: UriParse.c:uriOnExitOwnHost2A Unexecuted instantiation: UriParse.c:uriOnExitOwnHost2W |
1020 | | |
1021 | | |
1022 | | |
1023 | | /* |
1024 | | * [ownHost2]->[authorityTwo] // can take <NULL> |
1025 | | * [ownHost2]->[pctSubUnres][ownHost2] |
1026 | | */ |
1027 | | static const URI_CHAR * URI_FUNC(ParseOwnHost2)( |
1028 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
1029 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
1030 | 0 | if (first >= afterLast) { |
1031 | 0 | if (!URI_FUNC(OnExitOwnHost2)(state, first, memory)) { |
1032 | 0 | URI_FUNC(StopMalloc)(state, memory); |
1033 | 0 | return NULL; |
1034 | 0 | } |
1035 | 0 | return afterLast; |
1036 | 0 | } |
1037 | | |
1038 | 0 | switch (*first) { |
1039 | 0 | case _UT('!'): |
1040 | 0 | case _UT('$'): |
1041 | 0 | case _UT('%'): |
1042 | 0 | case _UT('&'): |
1043 | 0 | case _UT('('): |
1044 | 0 | case _UT(')'): |
1045 | 0 | case _UT('-'): |
1046 | 0 | case _UT('*'): |
1047 | 0 | case _UT(','): |
1048 | 0 | case _UT('.'): |
1049 | 0 | case _UT(';'): |
1050 | 0 | case _UT('\''): |
1051 | 0 | case _UT('_'): |
1052 | 0 | case _UT('~'): |
1053 | 0 | case _UT('+'): |
1054 | 0 | case _UT('='): |
1055 | 0 | case URI_SET_DIGIT: |
1056 | 0 | case URI_SET_ALPHA: |
1057 | 0 | { |
1058 | 0 | const URI_CHAR * const afterPctSubUnres |
1059 | 0 | = URI_FUNC(ParsePctSubUnres)(state, first, afterLast, memory); |
1060 | 0 | if (afterPctSubUnres == NULL) { |
1061 | 0 | return NULL; |
1062 | 0 | } |
1063 | 0 | return URI_FUNC(ParseOwnHost2)(state, afterPctSubUnres, afterLast, memory); |
1064 | 0 | } |
1065 | | |
1066 | 0 | default: |
1067 | 0 | if (!URI_FUNC(OnExitOwnHost2)(state, first, memory)) { |
1068 | 0 | URI_FUNC(StopMalloc)(state, memory); |
1069 | 0 | return NULL; |
1070 | 0 | } |
1071 | 0 | return URI_FUNC(ParseAuthorityTwo)(state, first, afterLast); |
1072 | 0 | } |
1073 | 0 | } Unexecuted instantiation: UriParse.c:uriParseOwnHost2A Unexecuted instantiation: UriParse.c:uriParseOwnHost2W |
1074 | | |
1075 | | |
1076 | | |
1077 | | static URI_INLINE UriBool URI_FUNC(OnExitOwnHostUserInfo)( |
1078 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
1079 | 0 | UriMemoryManager * memory) { |
1080 | 0 | state->uri->hostText.first = state->uri->userInfo.first; /* Host instead of userInfo, update */ |
1081 | 0 | state->uri->userInfo.first = NULL; /* Not a userInfo, reset */ |
1082 | 0 | state->uri->hostText.afterLast = first; /* HOST END */ |
1083 | | |
1084 | | /* Valid IPv4 or just a regname? */ |
1085 | 0 | state->uri->hostData.ip4 = memory->malloc(memory, 1 * sizeof(UriIp4)); /* Freed when stopping on parse error */ |
1086 | 0 | if (state->uri->hostData.ip4 == NULL) { |
1087 | 0 | return URI_FALSE; /* Raises malloc error */ |
1088 | 0 | } |
1089 | 0 | if (URI_FUNC(ParseIpFourAddress)(state->uri->hostData.ip4->data, |
1090 | 0 | state->uri->hostText.first, state->uri->hostText.afterLast)) { |
1091 | | /* Not IPv4 */ |
1092 | 0 | memory->free(memory, state->uri->hostData.ip4); |
1093 | 0 | state->uri->hostData.ip4 = NULL; |
1094 | 0 | } |
1095 | 0 | return URI_TRUE; /* Success */ |
1096 | 0 | } Unexecuted instantiation: UriParse.c:uriOnExitOwnHostUserInfoA Unexecuted instantiation: UriParse.c:uriOnExitOwnHostUserInfoW |
1097 | | |
1098 | | |
1099 | | |
1100 | | /* |
1101 | | * [ownHostUserInfo]->[ownHostUserInfoNz] |
1102 | | * [ownHostUserInfo]-><NULL> |
1103 | | */ |
1104 | | static URI_INLINE const URI_CHAR * URI_FUNC(ParseOwnHostUserInfo)( |
1105 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
1106 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
1107 | 0 | if (first >= afterLast) { |
1108 | 0 | if (!URI_FUNC(OnExitOwnHostUserInfo)(state, first, memory)) { |
1109 | 0 | URI_FUNC(StopMalloc)(state, memory); |
1110 | 0 | return NULL; |
1111 | 0 | } |
1112 | 0 | return afterLast; |
1113 | 0 | } |
1114 | | |
1115 | 0 | switch (*first) { |
1116 | 0 | case _UT('!'): |
1117 | 0 | case _UT('$'): |
1118 | 0 | case _UT('%'): |
1119 | 0 | case _UT('&'): |
1120 | 0 | case _UT('('): |
1121 | 0 | case _UT(')'): |
1122 | 0 | case _UT('-'): |
1123 | 0 | case _UT('*'): |
1124 | 0 | case _UT(','): |
1125 | 0 | case _UT('.'): |
1126 | 0 | case _UT(':'): |
1127 | 0 | case _UT(';'): |
1128 | 0 | case _UT('@'): |
1129 | 0 | case _UT('\''): |
1130 | 0 | case _UT('_'): |
1131 | 0 | case _UT('~'): |
1132 | 0 | case _UT('+'): |
1133 | 0 | case _UT('='): |
1134 | 0 | case URI_SET_DIGIT: |
1135 | 0 | case URI_SET_ALPHA: |
1136 | 0 | return URI_FUNC(ParseOwnHostUserInfoNz)(state, first, afterLast, memory); |
1137 | | |
1138 | 0 | default: |
1139 | 0 | if (!URI_FUNC(OnExitOwnHostUserInfo)(state, first, memory)) { |
1140 | 0 | URI_FUNC(StopMalloc)(state, memory); |
1141 | 0 | return NULL; |
1142 | 0 | } |
1143 | 0 | return first; |
1144 | 0 | } |
1145 | 0 | } Unexecuted instantiation: UriParse.c:uriParseOwnHostUserInfoA Unexecuted instantiation: UriParse.c:uriParseOwnHostUserInfoW |
1146 | | |
1147 | | |
1148 | | |
1149 | | /* |
1150 | | * [ownHostUserInfoNz]->[pctSubUnres][ownHostUserInfo] |
1151 | | * [ownHostUserInfoNz]-><:>[ownPortUserInfo] |
1152 | | * [ownHostUserInfoNz]-><@>[ownHost] |
1153 | | */ |
1154 | | static const URI_CHAR * URI_FUNC(ParseOwnHostUserInfoNz)( |
1155 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
1156 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
1157 | 0 | if (first >= afterLast) { |
1158 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
1159 | 0 | return NULL; |
1160 | 0 | } |
1161 | | |
1162 | 0 | switch (*first) { |
1163 | 0 | case _UT('!'): |
1164 | 0 | case _UT('$'): |
1165 | 0 | case _UT('%'): |
1166 | 0 | case _UT('&'): |
1167 | 0 | case _UT('('): |
1168 | 0 | case _UT(')'): |
1169 | 0 | case _UT('-'): |
1170 | 0 | case _UT('*'): |
1171 | 0 | case _UT(','): |
1172 | 0 | case _UT('.'): |
1173 | 0 | case _UT(';'): |
1174 | 0 | case _UT('\''): |
1175 | 0 | case _UT('_'): |
1176 | 0 | case _UT('~'): |
1177 | 0 | case _UT('+'): |
1178 | 0 | case _UT('='): |
1179 | 0 | case URI_SET_DIGIT: |
1180 | 0 | case URI_SET_ALPHA: |
1181 | 0 | { |
1182 | 0 | const URI_CHAR * const afterPctSubUnres |
1183 | 0 | = URI_FUNC(ParsePctSubUnres)(state, first, afterLast, memory); |
1184 | 0 | if (afterPctSubUnres == NULL) { |
1185 | 0 | return NULL; |
1186 | 0 | } |
1187 | 0 | return URI_FUNC(ParseOwnHostUserInfo)(state, afterPctSubUnres, afterLast, memory); |
1188 | 0 | } |
1189 | | |
1190 | 0 | case _UT(':'): |
1191 | 0 | state->uri->hostText.afterLast = first; /* HOST END */ |
1192 | 0 | state->uri->portText.first = first + 1; /* PORT BEGIN */ |
1193 | 0 | return URI_FUNC(ParseOwnPortUserInfo)(state, first + 1, afterLast, memory); |
1194 | | |
1195 | 0 | case _UT('@'): |
1196 | 0 | state->uri->userInfo.afterLast = first; /* USERINFO END */ |
1197 | 0 | state->uri->hostText.first = first + 1; /* HOST BEGIN */ |
1198 | 0 | return URI_FUNC(ParseOwnHost)(state, first + 1, afterLast, memory); |
1199 | | |
1200 | 0 | default: |
1201 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
1202 | 0 | return NULL; |
1203 | 0 | } |
1204 | 0 | } Unexecuted instantiation: UriParse.c:uriParseOwnHostUserInfoNzA Unexecuted instantiation: UriParse.c:uriParseOwnHostUserInfoNzW |
1205 | | |
1206 | | |
1207 | | |
1208 | | static URI_INLINE UriBool URI_FUNC(OnExitOwnPortUserInfo)( |
1209 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
1210 | 0 | UriMemoryManager * memory) { |
1211 | 0 | state->uri->hostText.first = state->uri->userInfo.first; /* Host instead of userInfo, update */ |
1212 | 0 | state->uri->userInfo.first = NULL; /* Not a userInfo, reset */ |
1213 | 0 | state->uri->portText.afterLast = first; /* PORT END */ |
1214 | | |
1215 | | /* Valid IPv4 or just a regname? */ |
1216 | 0 | state->uri->hostData.ip4 = memory->malloc(memory, 1 * sizeof(UriIp4)); /* Freed when stopping on parse error */ |
1217 | 0 | if (state->uri->hostData.ip4 == NULL) { |
1218 | 0 | return URI_FALSE; /* Raises malloc error */ |
1219 | 0 | } |
1220 | 0 | if (URI_FUNC(ParseIpFourAddress)(state->uri->hostData.ip4->data, |
1221 | 0 | state->uri->hostText.first, state->uri->hostText.afterLast)) { |
1222 | | /* Not IPv4 */ |
1223 | 0 | memory->free(memory, state->uri->hostData.ip4); |
1224 | 0 | state->uri->hostData.ip4 = NULL; |
1225 | 0 | } |
1226 | 0 | return URI_TRUE; /* Success */ |
1227 | 0 | } Unexecuted instantiation: UriParse.c:uriOnExitOwnPortUserInfoA Unexecuted instantiation: UriParse.c:uriOnExitOwnPortUserInfoW |
1228 | | |
1229 | | |
1230 | | |
1231 | | /* |
1232 | | * [ownPortUserInfo]->[ALPHA][ownUserInfo] |
1233 | | * [ownPortUserInfo]->[DIGIT][ownPortUserInfo] |
1234 | | * [ownPortUserInfo]-><.>[ownUserInfo] |
1235 | | * [ownPortUserInfo]-><_>[ownUserInfo] |
1236 | | * [ownPortUserInfo]-><~>[ownUserInfo] |
1237 | | * [ownPortUserInfo]-><->[ownUserInfo] |
1238 | | * [ownPortUserInfo]->[subDelims][ownUserInfo] |
1239 | | * [ownPortUserInfo]->[pctEncoded][ownUserInfo] |
1240 | | * [ownPortUserInfo]-><:>[ownUserInfo] |
1241 | | * [ownPortUserInfo]-><@>[ownHost] |
1242 | | * [ownPortUserInfo]-><NULL> |
1243 | | */ |
1244 | | static const URI_CHAR * URI_FUNC(ParseOwnPortUserInfo)( |
1245 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
1246 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
1247 | 0 | if (first >= afterLast) { |
1248 | 0 | if (!URI_FUNC(OnExitOwnPortUserInfo)(state, first, memory)) { |
1249 | 0 | URI_FUNC(StopMalloc)(state, memory); |
1250 | 0 | return NULL; |
1251 | 0 | } |
1252 | 0 | return afterLast; |
1253 | 0 | } |
1254 | | |
1255 | 0 | switch (*first) { |
1256 | | /* begin sub-delims */ |
1257 | 0 | case _UT('!'): |
1258 | 0 | case _UT('$'): |
1259 | 0 | case _UT('&'): |
1260 | 0 | case _UT('\''): |
1261 | 0 | case _UT('('): |
1262 | 0 | case _UT(')'): |
1263 | 0 | case _UT('*'): |
1264 | 0 | case _UT('+'): |
1265 | 0 | case _UT(','): |
1266 | 0 | case _UT(';'): |
1267 | 0 | case _UT('='): |
1268 | | /* end sub-delims */ |
1269 | | /* begin unreserved (except alpha and digit) */ |
1270 | 0 | case _UT('-'): |
1271 | 0 | case _UT('.'): |
1272 | 0 | case _UT('_'): |
1273 | 0 | case _UT('~'): |
1274 | | /* end unreserved (except alpha and digit) */ |
1275 | 0 | case _UT(':'): |
1276 | 0 | case URI_SET_ALPHA: |
1277 | 0 | state->uri->hostText.afterLast = NULL; /* Not a host, reset */ |
1278 | 0 | state->uri->portText.first = NULL; /* Not a port, reset */ |
1279 | 0 | return URI_FUNC(ParseOwnUserInfo)(state, first + 1, afterLast, memory); |
1280 | | |
1281 | 0 | case URI_SET_DIGIT: |
1282 | 0 | return URI_FUNC(ParseOwnPortUserInfo)(state, first + 1, afterLast, memory); |
1283 | | |
1284 | 0 | case _UT('%'): |
1285 | 0 | state->uri->portText.first = NULL; /* Not a port, reset */ |
1286 | 0 | { |
1287 | 0 | const URI_CHAR * const afterPct |
1288 | 0 | = URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory); |
1289 | 0 | if (afterPct == NULL) { |
1290 | 0 | return NULL; |
1291 | 0 | } |
1292 | 0 | return URI_FUNC(ParseOwnUserInfo)(state, afterPct, afterLast, memory); |
1293 | 0 | } |
1294 | | |
1295 | 0 | case _UT('@'): |
1296 | 0 | state->uri->hostText.afterLast = NULL; /* Not a host, reset */ |
1297 | 0 | state->uri->portText.first = NULL; /* Not a port, reset */ |
1298 | 0 | state->uri->userInfo.afterLast = first; /* USERINFO END */ |
1299 | 0 | state->uri->hostText.first = first + 1; /* HOST BEGIN */ |
1300 | 0 | return URI_FUNC(ParseOwnHost)(state, first + 1, afterLast, memory); |
1301 | | |
1302 | 0 | default: |
1303 | 0 | if (!URI_FUNC(OnExitOwnPortUserInfo)(state, first, memory)) { |
1304 | 0 | URI_FUNC(StopMalloc)(state, memory); |
1305 | 0 | return NULL; |
1306 | 0 | } |
1307 | 0 | return first; |
1308 | 0 | } |
1309 | 0 | } Unexecuted instantiation: UriParse.c:uriParseOwnPortUserInfoA Unexecuted instantiation: UriParse.c:uriParseOwnPortUserInfoW |
1310 | | |
1311 | | |
1312 | | |
1313 | | /* |
1314 | | * [ownUserInfo]->[pctSubUnres][ownUserInfo] |
1315 | | * [ownUserInfo]-><:>[ownUserInfo] |
1316 | | * [ownUserInfo]-><@>[ownHost] |
1317 | | */ |
1318 | | static const URI_CHAR * URI_FUNC(ParseOwnUserInfo)( |
1319 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
1320 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
1321 | 0 | if (first >= afterLast) { |
1322 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
1323 | 0 | return NULL; |
1324 | 0 | } |
1325 | | |
1326 | 0 | switch (*first) { |
1327 | 0 | case _UT('!'): |
1328 | 0 | case _UT('$'): |
1329 | 0 | case _UT('%'): |
1330 | 0 | case _UT('&'): |
1331 | 0 | case _UT('('): |
1332 | 0 | case _UT(')'): |
1333 | 0 | case _UT('-'): |
1334 | 0 | case _UT('*'): |
1335 | 0 | case _UT(','): |
1336 | 0 | case _UT('.'): |
1337 | 0 | case _UT(';'): |
1338 | 0 | case _UT('\''): |
1339 | 0 | case _UT('_'): |
1340 | 0 | case _UT('~'): |
1341 | 0 | case _UT('+'): |
1342 | 0 | case _UT('='): |
1343 | 0 | case URI_SET_DIGIT: |
1344 | 0 | case URI_SET_ALPHA: |
1345 | 0 | { |
1346 | 0 | const URI_CHAR * const afterPctSubUnres |
1347 | 0 | = URI_FUNC(ParsePctSubUnres)(state, first, afterLast, memory); |
1348 | 0 | if (afterPctSubUnres == NULL) { |
1349 | 0 | return NULL; |
1350 | 0 | } |
1351 | 0 | return URI_FUNC(ParseOwnUserInfo)(state, afterPctSubUnres, afterLast, memory); |
1352 | 0 | } |
1353 | | |
1354 | 0 | case _UT(':'): |
1355 | 0 | return URI_FUNC(ParseOwnUserInfo)(state, first + 1, afterLast, memory); |
1356 | | |
1357 | 0 | case _UT('@'): |
1358 | | /* SURE */ |
1359 | 0 | state->uri->userInfo.afterLast = first; /* USERINFO END */ |
1360 | 0 | state->uri->hostText.first = first + 1; /* HOST BEGIN */ |
1361 | 0 | return URI_FUNC(ParseOwnHost)(state, first + 1, afterLast, memory); |
1362 | | |
1363 | 0 | default: |
1364 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
1365 | 0 | return NULL; |
1366 | 0 | } |
1367 | 0 | } Unexecuted instantiation: UriParse.c:uriParseOwnUserInfoA Unexecuted instantiation: UriParse.c:uriParseOwnUserInfoW |
1368 | | |
1369 | | |
1370 | | |
1371 | 0 | static URI_INLINE void URI_FUNC(OnExitPartHelperTwo)(URI_TYPE(ParserState) * state) { |
1372 | 0 | state->uri->absolutePath = URI_TRUE; |
1373 | 0 | } Unexecuted instantiation: UriParse.c:uriOnExitPartHelperTwoA Unexecuted instantiation: UriParse.c:uriOnExitPartHelperTwoW |
1374 | | |
1375 | | |
1376 | | |
1377 | | /* |
1378 | | * [partHelperTwo]->[pathAbsNoLeadSlash] // can take <NULL> |
1379 | | * [partHelperTwo]-></>[authority][pathAbsEmpty] |
1380 | | */ |
1381 | | static URI_INLINE const URI_CHAR * URI_FUNC(ParsePartHelperTwo)( |
1382 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
1383 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
1384 | 0 | if (first >= afterLast) { |
1385 | 0 | URI_FUNC(OnExitPartHelperTwo)(state); |
1386 | 0 | return afterLast; |
1387 | 0 | } |
1388 | | |
1389 | 0 | switch (*first) { |
1390 | 0 | case _UT('/'): |
1391 | 0 | { |
1392 | 0 | const URI_CHAR * const afterAuthority |
1393 | 0 | = URI_FUNC(ParseAuthority)(state, first + 1, afterLast, memory); |
1394 | 0 | const URI_CHAR * afterPathAbsEmpty; |
1395 | 0 | if (afterAuthority == NULL) { |
1396 | 0 | return NULL; |
1397 | 0 | } |
1398 | 0 | afterPathAbsEmpty = URI_FUNC(ParsePathAbsEmpty)(state, afterAuthority, afterLast, memory); |
1399 | |
|
1400 | 0 | URI_FUNC(FixEmptyTrailSegment)(state->uri, memory); |
1401 | |
|
1402 | 0 | return afterPathAbsEmpty; |
1403 | 0 | } |
1404 | | |
1405 | 0 | default: |
1406 | 0 | URI_FUNC(OnExitPartHelperTwo)(state); |
1407 | 0 | return URI_FUNC(ParsePathAbsNoLeadSlash)(state, first, afterLast, memory); |
1408 | 0 | } |
1409 | 0 | } Unexecuted instantiation: UriParse.c:uriParsePartHelperTwoA Unexecuted instantiation: UriParse.c:uriParsePartHelperTwoW |
1410 | | |
1411 | | |
1412 | | |
1413 | | /* |
1414 | | * [pathAbsEmpty]-></>[segment][pathAbsEmpty] |
1415 | | * [pathAbsEmpty]-><NULL> |
1416 | | */ |
1417 | | static const URI_CHAR * URI_FUNC(ParsePathAbsEmpty)( |
1418 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
1419 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
1420 | 0 | if (first >= afterLast) { |
1421 | 0 | return afterLast; |
1422 | 0 | } |
1423 | | |
1424 | 0 | switch (*first) { |
1425 | 0 | case _UT('/'): |
1426 | 0 | { |
1427 | 0 | const URI_CHAR * const afterSegment |
1428 | 0 | = URI_FUNC(ParseSegment)(state, first + 1, afterLast, memory); |
1429 | 0 | if (afterSegment == NULL) { |
1430 | 0 | return NULL; |
1431 | 0 | } |
1432 | 0 | if (!URI_FUNC(PushPathSegment)(state, first + 1, afterSegment, memory)) { /* SEGMENT BOTH */ |
1433 | 0 | URI_FUNC(StopMalloc)(state, memory); |
1434 | 0 | return NULL; |
1435 | 0 | } |
1436 | 0 | return URI_FUNC(ParsePathAbsEmpty)(state, afterSegment, afterLast, memory); |
1437 | 0 | } |
1438 | | |
1439 | 0 | default: |
1440 | 0 | return first; |
1441 | 0 | } |
1442 | 0 | } Unexecuted instantiation: UriParse.c:uriParsePathAbsEmptyA Unexecuted instantiation: UriParse.c:uriParsePathAbsEmptyW |
1443 | | |
1444 | | |
1445 | | |
1446 | | /* |
1447 | | * [pathAbsNoLeadSlash]->[segmentNz][zeroMoreSlashSegs] |
1448 | | * [pathAbsNoLeadSlash]-><NULL> |
1449 | | */ |
1450 | | static URI_INLINE const URI_CHAR * URI_FUNC(ParsePathAbsNoLeadSlash)( |
1451 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
1452 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
1453 | 0 | if (first >= afterLast) { |
1454 | 0 | return afterLast; |
1455 | 0 | } |
1456 | | |
1457 | 0 | switch (*first) { |
1458 | 0 | case _UT('!'): |
1459 | 0 | case _UT('$'): |
1460 | 0 | case _UT('%'): |
1461 | 0 | case _UT('&'): |
1462 | 0 | case _UT('('): |
1463 | 0 | case _UT(')'): |
1464 | 0 | case _UT('-'): |
1465 | 0 | case _UT('*'): |
1466 | 0 | case _UT(','): |
1467 | 0 | case _UT('.'): |
1468 | 0 | case _UT(':'): |
1469 | 0 | case _UT(';'): |
1470 | 0 | case _UT('@'): |
1471 | 0 | case _UT('\''): |
1472 | 0 | case _UT('_'): |
1473 | 0 | case _UT('~'): |
1474 | 0 | case _UT('+'): |
1475 | 0 | case _UT('='): |
1476 | 0 | case URI_SET_DIGIT: |
1477 | 0 | case URI_SET_ALPHA: |
1478 | 0 | { |
1479 | 0 | const URI_CHAR * const afterSegmentNz |
1480 | 0 | = URI_FUNC(ParseSegmentNz)(state, first, afterLast, memory); |
1481 | 0 | if (afterSegmentNz == NULL) { |
1482 | 0 | return NULL; |
1483 | 0 | } |
1484 | 0 | if (!URI_FUNC(PushPathSegment)(state, first, afterSegmentNz, memory)) { /* SEGMENT BOTH */ |
1485 | 0 | URI_FUNC(StopMalloc)(state, memory); |
1486 | 0 | return NULL; |
1487 | 0 | } |
1488 | 0 | return URI_FUNC(ParseZeroMoreSlashSegs)(state, afterSegmentNz, afterLast, memory); |
1489 | 0 | } |
1490 | | |
1491 | 0 | default: |
1492 | 0 | return first; |
1493 | 0 | } |
1494 | 0 | } Unexecuted instantiation: UriParse.c:uriParsePathAbsNoLeadSlashA Unexecuted instantiation: UriParse.c:uriParsePathAbsNoLeadSlashW |
1495 | | |
1496 | | |
1497 | | |
1498 | | /* |
1499 | | * [pathRootless]->[segmentNz][zeroMoreSlashSegs] |
1500 | | */ |
1501 | | static URI_INLINE const URI_CHAR * URI_FUNC(ParsePathRootless)( |
1502 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
1503 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
1504 | 0 | const URI_CHAR * const afterSegmentNz |
1505 | 0 | = URI_FUNC(ParseSegmentNz)(state, first, afterLast, memory); |
1506 | 0 | if (afterSegmentNz == NULL) { |
1507 | 0 | return NULL; |
1508 | 0 | } else { |
1509 | 0 | if (!URI_FUNC(PushPathSegment)(state, first, afterSegmentNz, memory)) { /* SEGMENT BOTH */ |
1510 | 0 | URI_FUNC(StopMalloc)(state, memory); |
1511 | 0 | return NULL; |
1512 | 0 | } |
1513 | 0 | } |
1514 | 0 | return URI_FUNC(ParseZeroMoreSlashSegs)(state, afterSegmentNz, afterLast, memory); |
1515 | 0 | } Unexecuted instantiation: UriParse.c:uriParsePathRootlessA Unexecuted instantiation: UriParse.c:uriParsePathRootlessW |
1516 | | |
1517 | | |
1518 | | |
1519 | | /* |
1520 | | * [pchar]->[pctEncoded] |
1521 | | * [pchar]->[subDelims] |
1522 | | * [pchar]->[unreserved] |
1523 | | * [pchar]-><:> |
1524 | | * [pchar]-><@> |
1525 | | */ |
1526 | | static const URI_CHAR * URI_FUNC(ParsePchar)(URI_TYPE(ParserState) * state, |
1527 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
1528 | 0 | UriMemoryManager * memory) { |
1529 | 0 | if (first >= afterLast) { |
1530 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
1531 | 0 | return NULL; |
1532 | 0 | } |
1533 | | |
1534 | 0 | switch (*first) { |
1535 | 0 | case _UT('%'): |
1536 | 0 | return URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory); |
1537 | | |
1538 | 0 | case _UT(':'): |
1539 | 0 | case _UT('@'): |
1540 | 0 | case _UT('!'): |
1541 | 0 | case _UT('$'): |
1542 | 0 | case _UT('&'): |
1543 | 0 | case _UT('('): |
1544 | 0 | case _UT(')'): |
1545 | 0 | case _UT('*'): |
1546 | 0 | case _UT(','): |
1547 | 0 | case _UT(';'): |
1548 | 0 | case _UT('\''): |
1549 | 0 | case _UT('+'): |
1550 | 0 | case _UT('='): |
1551 | 0 | case _UT('-'): |
1552 | 0 | case _UT('.'): |
1553 | 0 | case _UT('_'): |
1554 | 0 | case _UT('~'): |
1555 | 0 | case URI_SET_DIGIT: |
1556 | 0 | case URI_SET_ALPHA: |
1557 | 0 | return first + 1; |
1558 | | |
1559 | 0 | default: |
1560 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
1561 | 0 | return NULL; |
1562 | 0 | } |
1563 | 0 | } Unexecuted instantiation: UriParse.c:uriParsePcharA Unexecuted instantiation: UriParse.c:uriParsePcharW |
1564 | | |
1565 | | |
1566 | | |
1567 | | /* |
1568 | | * [pctEncoded]-><%>[HEXDIG][HEXDIG] |
1569 | | */ |
1570 | | static const URI_CHAR * URI_FUNC(ParsePctEncoded)( |
1571 | | URI_TYPE(ParserState) * state, |
1572 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
1573 | 0 | UriMemoryManager * memory) { |
1574 | 0 | if (first >= afterLast) { |
1575 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
1576 | 0 | return NULL; |
1577 | 0 | } |
1578 | | |
1579 | | /* |
1580 | | First character has already been |
1581 | | checked before entering this rule. |
1582 | | |
1583 | | switch (*first) { |
1584 | | case _UT('%'): |
1585 | | */ |
1586 | 0 | if (first + 1 >= afterLast) { |
1587 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
1588 | 0 | return NULL; |
1589 | 0 | } |
1590 | | |
1591 | 0 | switch (first[1]) { |
1592 | 0 | case URI_SET_HEXDIG: |
1593 | 0 | if (first + 2 >= afterLast) { |
1594 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
1595 | 0 | return NULL; |
1596 | 0 | } |
1597 | | |
1598 | 0 | switch (first[2]) { |
1599 | 0 | case URI_SET_HEXDIG: |
1600 | 0 | return first + 3; |
1601 | | |
1602 | 0 | default: |
1603 | 0 | URI_FUNC(StopSyntax)(state, first + 2, memory); |
1604 | 0 | return NULL; |
1605 | 0 | } |
1606 | | |
1607 | 0 | default: |
1608 | 0 | URI_FUNC(StopSyntax)(state, first + 1, memory); |
1609 | 0 | return NULL; |
1610 | 0 | } |
1611 | | |
1612 | | /* |
1613 | | default: |
1614 | | URI_FUNC(StopSyntax)(state, first, memory); |
1615 | | return NULL; |
1616 | | } |
1617 | | */ |
1618 | 0 | } Unexecuted instantiation: UriParse.c:uriParsePctEncodedA Unexecuted instantiation: UriParse.c:uriParsePctEncodedW |
1619 | | |
1620 | | |
1621 | | |
1622 | | /* |
1623 | | * [pctSubUnres]->[pctEncoded] |
1624 | | * [pctSubUnres]->[subDelims] |
1625 | | * [pctSubUnres]->[unreserved] |
1626 | | */ |
1627 | | static const URI_CHAR * URI_FUNC(ParsePctSubUnres)( |
1628 | | URI_TYPE(ParserState) * state, |
1629 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
1630 | 0 | UriMemoryManager * memory) { |
1631 | 0 | if (first >= afterLast) { |
1632 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
1633 | 0 | return NULL; |
1634 | 0 | } |
1635 | | |
1636 | 0 | switch (*first) { |
1637 | 0 | case _UT('%'): |
1638 | 0 | return URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory); |
1639 | | |
1640 | 0 | case _UT('!'): |
1641 | 0 | case _UT('$'): |
1642 | 0 | case _UT('&'): |
1643 | 0 | case _UT('('): |
1644 | 0 | case _UT(')'): |
1645 | 0 | case _UT('*'): |
1646 | 0 | case _UT(','): |
1647 | 0 | case _UT(';'): |
1648 | 0 | case _UT('\''): |
1649 | 0 | case _UT('+'): |
1650 | 0 | case _UT('='): |
1651 | 0 | case _UT('-'): |
1652 | 0 | case _UT('.'): |
1653 | 0 | case _UT('_'): |
1654 | 0 | case _UT('~'): |
1655 | 0 | case URI_SET_DIGIT: |
1656 | 0 | case URI_SET_ALPHA: |
1657 | 0 | return first + 1; |
1658 | | |
1659 | 0 | default: |
1660 | 0 | URI_FUNC(StopSyntax)(state, first, memory); |
1661 | 0 | return NULL; |
1662 | 0 | } |
1663 | 0 | } Unexecuted instantiation: UriParse.c:uriParsePctSubUnresA Unexecuted instantiation: UriParse.c:uriParsePctSubUnresW |
1664 | | |
1665 | | |
1666 | | |
1667 | | /* |
1668 | | * [port]->[DIGIT][port] |
1669 | | * [port]-><NULL> |
1670 | | */ |
1671 | 0 | static const URI_CHAR * URI_FUNC(ParsePort)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast) { |
1672 | 0 | if (first >= afterLast) { |
1673 | 0 | return afterLast; |
1674 | 0 | } |
1675 | | |
1676 | 0 | switch (*first) { |
1677 | 0 | case URI_SET_DIGIT: |
1678 | 0 | return URI_FUNC(ParsePort)(state, first + 1, afterLast); |
1679 | | |
1680 | 0 | default: |
1681 | 0 | return first; |
1682 | 0 | } |
1683 | 0 | } Unexecuted instantiation: UriParse.c:uriParsePortA Unexecuted instantiation: UriParse.c:uriParsePortW |
1684 | | |
1685 | | |
1686 | | |
1687 | | /* |
1688 | | * [queryFrag]->[pchar][queryFrag] |
1689 | | * [queryFrag]-></>[queryFrag] |
1690 | | * [queryFrag]-><?>[queryFrag] |
1691 | | * [queryFrag]-><NULL> |
1692 | | */ |
1693 | | static const URI_CHAR * URI_FUNC(ParseQueryFrag)(URI_TYPE(ParserState) * state, |
1694 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
1695 | 0 | UriMemoryManager * memory) { |
1696 | 0 | if (first >= afterLast) { |
1697 | 0 | return afterLast; |
1698 | 0 | } |
1699 | | |
1700 | 0 | switch (*first) { |
1701 | 0 | case _UT('!'): |
1702 | 0 | case _UT('$'): |
1703 | 0 | case _UT('%'): |
1704 | 0 | case _UT('&'): |
1705 | 0 | case _UT('('): |
1706 | 0 | case _UT(')'): |
1707 | 0 | case _UT('-'): |
1708 | 0 | case _UT('*'): |
1709 | 0 | case _UT(','): |
1710 | 0 | case _UT('.'): |
1711 | 0 | case _UT(':'): |
1712 | 0 | case _UT(';'): |
1713 | 0 | case _UT('@'): |
1714 | 0 | case _UT('\''): |
1715 | 0 | case _UT('_'): |
1716 | 0 | case _UT('~'): |
1717 | 0 | case _UT('+'): |
1718 | 0 | case _UT('='): |
1719 | 0 | case URI_SET_DIGIT: |
1720 | 0 | case URI_SET_ALPHA: |
1721 | 0 | { |
1722 | 0 | const URI_CHAR * const afterPchar |
1723 | 0 | = URI_FUNC(ParsePchar)(state, first, afterLast, memory); |
1724 | 0 | if (afterPchar == NULL) { |
1725 | 0 | return NULL; |
1726 | 0 | } |
1727 | 0 | return URI_FUNC(ParseQueryFrag)(state, afterPchar, afterLast, memory); |
1728 | 0 | } |
1729 | | |
1730 | 0 | case _UT('/'): |
1731 | 0 | case _UT('?'): |
1732 | 0 | return URI_FUNC(ParseQueryFrag)(state, first + 1, afterLast, memory); |
1733 | | |
1734 | 0 | default: |
1735 | 0 | return first; |
1736 | 0 | } |
1737 | 0 | } Unexecuted instantiation: UriParse.c:uriParseQueryFragA Unexecuted instantiation: UriParse.c:uriParseQueryFragW |
1738 | | |
1739 | | |
1740 | | |
1741 | | /* |
1742 | | * [segment]->[pchar][segment] |
1743 | | * [segment]-><NULL> |
1744 | | */ |
1745 | | static const URI_CHAR * URI_FUNC(ParseSegment)(URI_TYPE(ParserState) * state, |
1746 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
1747 | 0 | UriMemoryManager * memory) { |
1748 | 0 | if (first >= afterLast) { |
1749 | 0 | return afterLast; |
1750 | 0 | } |
1751 | | |
1752 | 0 | switch (*first) { |
1753 | 0 | case _UT('!'): |
1754 | 0 | case _UT('$'): |
1755 | 0 | case _UT('%'): |
1756 | 0 | case _UT('&'): |
1757 | 0 | case _UT('('): |
1758 | 0 | case _UT(')'): |
1759 | 0 | case _UT('-'): |
1760 | 0 | case _UT('*'): |
1761 | 0 | case _UT(','): |
1762 | 0 | case _UT('.'): |
1763 | 0 | case _UT(':'): |
1764 | 0 | case _UT(';'): |
1765 | 0 | case _UT('@'): |
1766 | 0 | case _UT('\''): |
1767 | 0 | case _UT('_'): |
1768 | 0 | case _UT('~'): |
1769 | 0 | case _UT('+'): |
1770 | 0 | case _UT('='): |
1771 | 0 | case URI_SET_DIGIT: |
1772 | 0 | case URI_SET_ALPHA: |
1773 | 0 | { |
1774 | 0 | const URI_CHAR * const afterPchar |
1775 | 0 | = URI_FUNC(ParsePchar)(state, first, afterLast, memory); |
1776 | 0 | if (afterPchar == NULL) { |
1777 | 0 | return NULL; |
1778 | 0 | } |
1779 | 0 | return URI_FUNC(ParseSegment)(state, afterPchar, afterLast, memory); |
1780 | 0 | } |
1781 | | |
1782 | 0 | default: |
1783 | 0 | return first; |
1784 | 0 | } |
1785 | 0 | } Unexecuted instantiation: UriParse.c:uriParseSegmentA Unexecuted instantiation: UriParse.c:uriParseSegmentW |
1786 | | |
1787 | | |
1788 | | |
1789 | | /* |
1790 | | * [segmentNz]->[pchar][segment] |
1791 | | */ |
1792 | | static URI_INLINE const URI_CHAR * URI_FUNC(ParseSegmentNz)( |
1793 | | URI_TYPE(ParserState) * state, |
1794 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
1795 | 0 | UriMemoryManager * memory) { |
1796 | 0 | const URI_CHAR * const afterPchar |
1797 | 0 | = URI_FUNC(ParsePchar)(state, first, afterLast, memory); |
1798 | 0 | if (afterPchar == NULL) { |
1799 | 0 | return NULL; |
1800 | 0 | } |
1801 | 0 | return URI_FUNC(ParseSegment)(state, afterPchar, afterLast, memory); |
1802 | 0 | } Unexecuted instantiation: UriParse.c:uriParseSegmentNzA Unexecuted instantiation: UriParse.c:uriParseSegmentNzW |
1803 | | |
1804 | | |
1805 | | |
1806 | | static URI_INLINE UriBool URI_FUNC(OnExitSegmentNzNcOrScheme2)( |
1807 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
1808 | 0 | UriMemoryManager * memory) { |
1809 | 0 | if (!URI_FUNC(PushPathSegment)(state, state->uri->scheme.first, first, memory)) { /* SEGMENT BOTH */ |
1810 | 0 | return URI_FALSE; /* Raises malloc error*/ |
1811 | 0 | } |
1812 | 0 | state->uri->scheme.first = NULL; /* Not a scheme, reset */ |
1813 | 0 | return URI_TRUE; /* Success */ |
1814 | 0 | } Unexecuted instantiation: UriParse.c:uriOnExitSegmentNzNcOrScheme2A Unexecuted instantiation: UriParse.c:uriOnExitSegmentNzNcOrScheme2W |
1815 | | |
1816 | | |
1817 | | |
1818 | | /* |
1819 | | * [segmentNzNcOrScheme2]->[ALPHA][segmentNzNcOrScheme2] |
1820 | | * [segmentNzNcOrScheme2]->[DIGIT][segmentNzNcOrScheme2] |
1821 | | * [segmentNzNcOrScheme2]->[pctEncoded][mustBeSegmentNzNc] |
1822 | | * [segmentNzNcOrScheme2]->[uriTail] // can take <NULL> |
1823 | | * [segmentNzNcOrScheme2]-><!>[mustBeSegmentNzNc] |
1824 | | * [segmentNzNcOrScheme2]-><$>[mustBeSegmentNzNc] |
1825 | | * [segmentNzNcOrScheme2]-><&>[mustBeSegmentNzNc] |
1826 | | * [segmentNzNcOrScheme2]-><(>[mustBeSegmentNzNc] |
1827 | | * [segmentNzNcOrScheme2]-><)>[mustBeSegmentNzNc] |
1828 | | * [segmentNzNcOrScheme2]-><*>[mustBeSegmentNzNc] |
1829 | | * [segmentNzNcOrScheme2]-><,>[mustBeSegmentNzNc] |
1830 | | * [segmentNzNcOrScheme2]-><.>[segmentNzNcOrScheme2] |
1831 | | * [segmentNzNcOrScheme2]-></>[segment][zeroMoreSlashSegs][uriTail] |
1832 | | * [segmentNzNcOrScheme2]-><:>[hierPart][uriTail] |
1833 | | * [segmentNzNcOrScheme2]-><;>[mustBeSegmentNzNc] |
1834 | | * [segmentNzNcOrScheme2]-><@>[mustBeSegmentNzNc] |
1835 | | * [segmentNzNcOrScheme2]-><_>[mustBeSegmentNzNc] |
1836 | | * [segmentNzNcOrScheme2]-><~>[mustBeSegmentNzNc] |
1837 | | * [segmentNzNcOrScheme2]-><+>[segmentNzNcOrScheme2] |
1838 | | * [segmentNzNcOrScheme2]-><=>[mustBeSegmentNzNc] |
1839 | | * [segmentNzNcOrScheme2]-><'>[mustBeSegmentNzNc] |
1840 | | * [segmentNzNcOrScheme2]-><->[segmentNzNcOrScheme2] |
1841 | | */ |
1842 | | static const URI_CHAR * URI_FUNC(ParseSegmentNzNcOrScheme2)( |
1843 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
1844 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
1845 | 0 | if (first >= afterLast) { |
1846 | 0 | if (!URI_FUNC(OnExitSegmentNzNcOrScheme2)(state, first, memory)) { |
1847 | 0 | URI_FUNC(StopMalloc)(state, memory); |
1848 | 0 | return NULL; |
1849 | 0 | } |
1850 | 0 | return afterLast; |
1851 | 0 | } |
1852 | | |
1853 | 0 | switch (*first) { |
1854 | 0 | case _UT('.'): |
1855 | 0 | case _UT('+'): |
1856 | 0 | case _UT('-'): |
1857 | 0 | case URI_SET_ALPHA: |
1858 | 0 | case URI_SET_DIGIT: |
1859 | 0 | return URI_FUNC(ParseSegmentNzNcOrScheme2)(state, first + 1, afterLast, memory); |
1860 | | |
1861 | 0 | case _UT('%'): |
1862 | 0 | { |
1863 | 0 | const URI_CHAR * const afterPctEncoded |
1864 | 0 | = URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory); |
1865 | 0 | if (afterPctEncoded == NULL) { |
1866 | 0 | return NULL; |
1867 | 0 | } |
1868 | 0 | return URI_FUNC(ParseMustBeSegmentNzNc)(state, afterPctEncoded, afterLast, memory); |
1869 | 0 | } |
1870 | | |
1871 | 0 | case _UT('!'): |
1872 | 0 | case _UT('$'): |
1873 | 0 | case _UT('&'): |
1874 | 0 | case _UT('('): |
1875 | 0 | case _UT(')'): |
1876 | 0 | case _UT('*'): |
1877 | 0 | case _UT(','): |
1878 | 0 | case _UT(';'): |
1879 | 0 | case _UT('@'): |
1880 | 0 | case _UT('_'): |
1881 | 0 | case _UT('~'): |
1882 | 0 | case _UT('='): |
1883 | 0 | case _UT('\''): |
1884 | 0 | return URI_FUNC(ParseMustBeSegmentNzNc)(state, first + 1, afterLast, memory); |
1885 | | |
1886 | 0 | case _UT('/'): |
1887 | 0 | { |
1888 | 0 | const URI_CHAR * afterZeroMoreSlashSegs; |
1889 | 0 | const URI_CHAR * const afterSegment |
1890 | 0 | = URI_FUNC(ParseSegment)(state, first + 1, afterLast, memory); |
1891 | 0 | if (afterSegment == NULL) { |
1892 | 0 | return NULL; |
1893 | 0 | } |
1894 | 0 | if (!URI_FUNC(PushPathSegment)(state, state->uri->scheme.first, first, memory)) { /* SEGMENT BOTH */ |
1895 | 0 | URI_FUNC(StopMalloc)(state, memory); |
1896 | 0 | return NULL; |
1897 | 0 | } |
1898 | 0 | state->uri->scheme.first = NULL; /* Not a scheme, reset */ |
1899 | 0 | if (!URI_FUNC(PushPathSegment)(state, first + 1, afterSegment, memory)) { /* SEGMENT BOTH */ |
1900 | 0 | URI_FUNC(StopMalloc)(state, memory); |
1901 | 0 | return NULL; |
1902 | 0 | } |
1903 | 0 | afterZeroMoreSlashSegs |
1904 | 0 | = URI_FUNC(ParseZeroMoreSlashSegs)(state, afterSegment, afterLast, memory); |
1905 | 0 | if (afterZeroMoreSlashSegs == NULL) { |
1906 | 0 | return NULL; |
1907 | 0 | } |
1908 | 0 | return URI_FUNC(ParseUriTail)(state, afterZeroMoreSlashSegs, afterLast, memory); |
1909 | 0 | } |
1910 | | |
1911 | 0 | case _UT(':'): |
1912 | 0 | { |
1913 | 0 | const URI_CHAR * const afterHierPart |
1914 | 0 | = URI_FUNC(ParseHierPart)(state, first + 1, afterLast, memory); |
1915 | 0 | state->uri->scheme.afterLast = first; /* SCHEME END */ |
1916 | 0 | if (afterHierPart == NULL) { |
1917 | 0 | return NULL; |
1918 | 0 | } |
1919 | 0 | return URI_FUNC(ParseUriTail)(state, afterHierPart, afterLast, memory); |
1920 | 0 | } |
1921 | | |
1922 | 0 | default: |
1923 | 0 | if (!URI_FUNC(OnExitSegmentNzNcOrScheme2)(state, first, memory)) { |
1924 | 0 | URI_FUNC(StopMalloc)(state, memory); |
1925 | 0 | return NULL; |
1926 | 0 | } |
1927 | 0 | return URI_FUNC(ParseUriTail)(state, first, afterLast, memory); |
1928 | 0 | } |
1929 | 0 | } Unexecuted instantiation: UriParse.c:uriParseSegmentNzNcOrScheme2A Unexecuted instantiation: UriParse.c:uriParseSegmentNzNcOrScheme2W |
1930 | | |
1931 | | |
1932 | | |
1933 | | /* |
1934 | | * [uriReference]->[ALPHA][segmentNzNcOrScheme2] |
1935 | | * [uriReference]->[DIGIT][mustBeSegmentNzNc] |
1936 | | * [uriReference]->[pctEncoded][mustBeSegmentNzNc] |
1937 | | * [uriReference]->[subDelims][mustBeSegmentNzNc] |
1938 | | * [uriReference]->[uriTail] // can take <NULL> |
1939 | | * [uriReference]-><.>[mustBeSegmentNzNc] |
1940 | | * [uriReference]-></>[partHelperTwo][uriTail] |
1941 | | * [uriReference]-><@>[mustBeSegmentNzNc] |
1942 | | * [uriReference]-><_>[mustBeSegmentNzNc] |
1943 | | * [uriReference]-><~>[mustBeSegmentNzNc] |
1944 | | * [uriReference]-><->[mustBeSegmentNzNc] |
1945 | | */ |
1946 | | static const URI_CHAR * URI_FUNC(ParseUriReference)( |
1947 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
1948 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
1949 | 0 | if (first >= afterLast) { |
1950 | 0 | return afterLast; |
1951 | 0 | } |
1952 | | |
1953 | 0 | switch (*first) { |
1954 | 0 | case URI_SET_ALPHA: |
1955 | 0 | state->uri->scheme.first = first; /* SCHEME BEGIN */ |
1956 | 0 | return URI_FUNC(ParseSegmentNzNcOrScheme2)(state, first + 1, afterLast, memory); |
1957 | | |
1958 | 0 | case URI_SET_DIGIT: |
1959 | 0 | case _UT('!'): |
1960 | 0 | case _UT('$'): |
1961 | 0 | case _UT('&'): |
1962 | 0 | case _UT('('): |
1963 | 0 | case _UT(')'): |
1964 | 0 | case _UT('*'): |
1965 | 0 | case _UT(','): |
1966 | 0 | case _UT(';'): |
1967 | 0 | case _UT('\''): |
1968 | 0 | case _UT('+'): |
1969 | 0 | case _UT('='): |
1970 | 0 | case _UT('.'): |
1971 | 0 | case _UT('_'): |
1972 | 0 | case _UT('~'): |
1973 | 0 | case _UT('-'): |
1974 | 0 | case _UT('@'): |
1975 | 0 | state->uri->scheme.first = first; /* SEGMENT BEGIN, ABUSE SCHEME POINTER */ |
1976 | 0 | return URI_FUNC(ParseMustBeSegmentNzNc)(state, first + 1, afterLast, memory); |
1977 | | |
1978 | 0 | case _UT('%'): |
1979 | 0 | { |
1980 | 0 | const URI_CHAR * const afterPctEncoded |
1981 | 0 | = URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory); |
1982 | 0 | if (afterPctEncoded == NULL) { |
1983 | 0 | return NULL; |
1984 | 0 | } |
1985 | 0 | state->uri->scheme.first = first; /* SEGMENT BEGIN, ABUSE SCHEME POINTER */ |
1986 | 0 | return URI_FUNC(ParseMustBeSegmentNzNc)(state, afterPctEncoded, afterLast, memory); |
1987 | 0 | } |
1988 | | |
1989 | 0 | case _UT('/'): |
1990 | 0 | { |
1991 | 0 | const URI_CHAR * const afterPartHelperTwo |
1992 | 0 | = URI_FUNC(ParsePartHelperTwo)(state, first + 1, afterLast, memory); |
1993 | 0 | if (afterPartHelperTwo == NULL) { |
1994 | 0 | return NULL; |
1995 | 0 | } |
1996 | 0 | return URI_FUNC(ParseUriTail)(state, afterPartHelperTwo, afterLast, memory); |
1997 | 0 | } |
1998 | | |
1999 | 0 | default: |
2000 | 0 | return URI_FUNC(ParseUriTail)(state, first, afterLast, memory); |
2001 | 0 | } |
2002 | 0 | } Unexecuted instantiation: UriParse.c:uriParseUriReferenceA Unexecuted instantiation: UriParse.c:uriParseUriReferenceW |
2003 | | |
2004 | | |
2005 | | |
2006 | | /* |
2007 | | * [uriTail]-><#>[queryFrag] |
2008 | | * [uriTail]-><?>[queryFrag][uriTailTwo] |
2009 | | * [uriTail]-><NULL> |
2010 | | */ |
2011 | | static URI_INLINE const URI_CHAR * URI_FUNC(ParseUriTail)( |
2012 | | URI_TYPE(ParserState) * state, |
2013 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
2014 | 0 | UriMemoryManager * memory) { |
2015 | 0 | if (first >= afterLast) { |
2016 | 0 | return afterLast; |
2017 | 0 | } |
2018 | | |
2019 | 0 | switch (*first) { |
2020 | 0 | case _UT('#'): |
2021 | 0 | { |
2022 | 0 | const URI_CHAR * const afterQueryFrag = URI_FUNC(ParseQueryFrag)(state, first + 1, afterLast, memory); |
2023 | 0 | if (afterQueryFrag == NULL) { |
2024 | 0 | return NULL; |
2025 | 0 | } |
2026 | 0 | state->uri->fragment.first = first + 1; /* FRAGMENT BEGIN */ |
2027 | 0 | state->uri->fragment.afterLast = afterQueryFrag; /* FRAGMENT END */ |
2028 | 0 | return afterQueryFrag; |
2029 | 0 | } |
2030 | | |
2031 | 0 | case _UT('?'): |
2032 | 0 | { |
2033 | 0 | const URI_CHAR * const afterQueryFrag |
2034 | 0 | = URI_FUNC(ParseQueryFrag)(state, first + 1, afterLast, memory); |
2035 | 0 | if (afterQueryFrag == NULL) { |
2036 | 0 | return NULL; |
2037 | 0 | } |
2038 | 0 | state->uri->query.first = first + 1; /* QUERY BEGIN */ |
2039 | 0 | state->uri->query.afterLast = afterQueryFrag; /* QUERY END */ |
2040 | 0 | return URI_FUNC(ParseUriTailTwo)(state, afterQueryFrag, afterLast, memory); |
2041 | 0 | } |
2042 | | |
2043 | 0 | default: |
2044 | 0 | return first; |
2045 | 0 | } |
2046 | 0 | } Unexecuted instantiation: UriParse.c:uriParseUriTailA Unexecuted instantiation: UriParse.c:uriParseUriTailW |
2047 | | |
2048 | | |
2049 | | |
2050 | | /* |
2051 | | * [uriTailTwo]-><#>[queryFrag] |
2052 | | * [uriTailTwo]-><NULL> |
2053 | | */ |
2054 | | static URI_INLINE const URI_CHAR * URI_FUNC(ParseUriTailTwo)( |
2055 | | URI_TYPE(ParserState) * state, |
2056 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
2057 | 0 | UriMemoryManager * memory) { |
2058 | 0 | if (first >= afterLast) { |
2059 | 0 | return afterLast; |
2060 | 0 | } |
2061 | | |
2062 | 0 | switch (*first) { |
2063 | 0 | case _UT('#'): |
2064 | 0 | { |
2065 | 0 | const URI_CHAR * const afterQueryFrag = URI_FUNC(ParseQueryFrag)(state, first + 1, afterLast, memory); |
2066 | 0 | if (afterQueryFrag == NULL) { |
2067 | 0 | return NULL; |
2068 | 0 | } |
2069 | 0 | state->uri->fragment.first = first + 1; /* FRAGMENT BEGIN */ |
2070 | 0 | state->uri->fragment.afterLast = afterQueryFrag; /* FRAGMENT END */ |
2071 | 0 | return afterQueryFrag; |
2072 | 0 | } |
2073 | | |
2074 | 0 | default: |
2075 | 0 | return first; |
2076 | 0 | } |
2077 | 0 | } Unexecuted instantiation: UriParse.c:uriParseUriTailTwoA Unexecuted instantiation: UriParse.c:uriParseUriTailTwoW |
2078 | | |
2079 | | |
2080 | | |
2081 | | /* |
2082 | | * [zeroMoreSlashSegs]-></>[segment][zeroMoreSlashSegs] |
2083 | | * [zeroMoreSlashSegs]-><NULL> |
2084 | | */ |
2085 | | static const URI_CHAR * URI_FUNC(ParseZeroMoreSlashSegs)( |
2086 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
2087 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
2088 | 0 | if (first >= afterLast) { |
2089 | 0 | return afterLast; |
2090 | 0 | } |
2091 | | |
2092 | 0 | switch (*first) { |
2093 | 0 | case _UT('/'): |
2094 | 0 | { |
2095 | 0 | const URI_CHAR * const afterSegment |
2096 | 0 | = URI_FUNC(ParseSegment)(state, first + 1, afterLast, memory); |
2097 | 0 | if (afterSegment == NULL) { |
2098 | 0 | return NULL; |
2099 | 0 | } |
2100 | 0 | if (!URI_FUNC(PushPathSegment)(state, first + 1, afterSegment, memory)) { /* SEGMENT BOTH */ |
2101 | 0 | URI_FUNC(StopMalloc)(state, memory); |
2102 | 0 | return NULL; |
2103 | 0 | } |
2104 | 0 | return URI_FUNC(ParseZeroMoreSlashSegs)(state, afterSegment, afterLast, memory); |
2105 | 0 | } |
2106 | | |
2107 | 0 | default: |
2108 | 0 | return first; |
2109 | 0 | } |
2110 | 0 | } Unexecuted instantiation: UriParse.c:uriParseZeroMoreSlashSegsA Unexecuted instantiation: UriParse.c:uriParseZeroMoreSlashSegsW |
2111 | | |
2112 | | |
2113 | | |
2114 | 0 | static URI_INLINE void URI_FUNC(ResetParserStateExceptUri)(URI_TYPE(ParserState) * state) { |
2115 | 0 | URI_TYPE(Uri) * const uriBackup = state->uri; |
2116 | 0 | memset(state, 0, sizeof(URI_TYPE(ParserState))); |
2117 | 0 | state->uri = uriBackup; |
2118 | 0 | } Unexecuted instantiation: UriParse.c:uriResetParserStateExceptUriA Unexecuted instantiation: UriParse.c:uriResetParserStateExceptUriW |
2119 | | |
2120 | | |
2121 | | |
2122 | | static URI_INLINE UriBool URI_FUNC(PushPathSegment)( |
2123 | | URI_TYPE(ParserState) * state, const URI_CHAR * first, |
2124 | 0 | const URI_CHAR * afterLast, UriMemoryManager * memory) { |
2125 | 0 | URI_TYPE(PathSegment) * segment = memory->calloc(memory, 1, sizeof(URI_TYPE(PathSegment))); |
2126 | 0 | if (segment == NULL) { |
2127 | 0 | return URI_FALSE; /* Raises malloc error */ |
2128 | 0 | } |
2129 | 0 | if (first == afterLast) { |
2130 | 0 | segment->text.first = URI_FUNC(SafeToPointTo); |
2131 | 0 | segment->text.afterLast = URI_FUNC(SafeToPointTo); |
2132 | 0 | } else { |
2133 | 0 | segment->text.first = first; |
2134 | 0 | segment->text.afterLast = afterLast; |
2135 | 0 | } |
2136 | | |
2137 | | /* First segment ever? */ |
2138 | 0 | if (state->uri->pathHead == NULL) { |
2139 | | /* First segment ever, set head and tail */ |
2140 | 0 | state->uri->pathHead = segment; |
2141 | 0 | state->uri->pathTail = segment; |
2142 | 0 | } else { |
2143 | | /* Append, update tail */ |
2144 | 0 | state->uri->pathTail->next = segment; |
2145 | 0 | state->uri->pathTail = segment; |
2146 | 0 | } |
2147 | |
|
2148 | 0 | return URI_TRUE; /* Success */ |
2149 | 0 | } Unexecuted instantiation: UriParse.c:uriPushPathSegmentA Unexecuted instantiation: UriParse.c:uriPushPathSegmentW |
2150 | | |
2151 | | |
2152 | | |
2153 | | int URI_FUNC(ParseUriEx)(URI_TYPE(ParserState) * state, |
2154 | 0 | const URI_CHAR * first, const URI_CHAR * afterLast) { |
2155 | 0 | return URI_FUNC(ParseUriExMm)(state, first, afterLast, NULL); |
2156 | 0 | } Unexecuted instantiation: uriParseUriExA Unexecuted instantiation: uriParseUriExW |
2157 | | |
2158 | | |
2159 | | |
2160 | | static int URI_FUNC(ParseUriExMm)(URI_TYPE(ParserState) * state, |
2161 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
2162 | 0 | UriMemoryManager * memory) { |
2163 | 0 | const URI_CHAR * afterUriReference; |
2164 | 0 | URI_TYPE(Uri) * uri; |
2165 | | |
2166 | | /* Check params */ |
2167 | 0 | if ((state == NULL) || (first == NULL) || (afterLast == NULL)) { |
2168 | 0 | return URI_ERROR_NULL; |
2169 | 0 | } |
2170 | 0 | URI_CHECK_MEMORY_MANAGER(memory); /* may return */ |
2171 | | |
2172 | 0 | uri = state->uri; |
2173 | | |
2174 | | /* Init parser */ |
2175 | 0 | URI_FUNC(ResetParserStateExceptUri)(state); |
2176 | 0 | URI_FUNC(ResetUri)(uri); |
2177 | | |
2178 | | /* Parse */ |
2179 | 0 | afterUriReference = URI_FUNC(ParseUriReference)(state, first, afterLast, memory); |
2180 | 0 | if (afterUriReference == NULL) { |
2181 | | /* Waterproof errorPos <= afterLast */ |
2182 | 0 | if (state->errorPos && (state->errorPos > afterLast)) { |
2183 | 0 | state->errorPos = afterLast; |
2184 | 0 | } |
2185 | 0 | return state->errorCode; |
2186 | 0 | } |
2187 | 0 | if (afterUriReference != afterLast) { |
2188 | 0 | if (afterUriReference < afterLast) { |
2189 | 0 | URI_FUNC(StopSyntax)(state, afterUriReference, memory); |
2190 | 0 | } else { |
2191 | 0 | URI_FUNC(StopSyntax)(state, afterLast, memory); |
2192 | 0 | } |
2193 | 0 | return state->errorCode; |
2194 | 0 | } |
2195 | 0 | return URI_SUCCESS; |
2196 | 0 | } Unexecuted instantiation: UriParse.c:uriParseUriExMmA Unexecuted instantiation: UriParse.c:uriParseUriExMmW |
2197 | | |
2198 | | |
2199 | | |
2200 | 0 | int URI_FUNC(ParseUri)(URI_TYPE(ParserState) * state, const URI_CHAR * text) { |
2201 | 0 | if ((state == NULL) || (text == NULL)) { |
2202 | 0 | return URI_ERROR_NULL; |
2203 | 0 | } |
2204 | 0 | return URI_FUNC(ParseUriEx)(state, text, text + URI_STRLEN(text)); |
2205 | 0 | } Unexecuted instantiation: uriParseUriA Unexecuted instantiation: uriParseUriW |
2206 | | |
2207 | | |
2208 | | |
2209 | | int URI_FUNC(ParseSingleUri)(URI_TYPE(Uri) * uri, const URI_CHAR * text, |
2210 | 0 | const URI_CHAR ** errorPos) { |
2211 | 0 | return URI_FUNC(ParseSingleUriEx)(uri, text, NULL, errorPos); |
2212 | 0 | } Unexecuted instantiation: uriParseSingleUriA Unexecuted instantiation: uriParseSingleUriW |
2213 | | |
2214 | | |
2215 | | |
2216 | | int URI_FUNC(ParseSingleUriEx)(URI_TYPE(Uri) * uri, |
2217 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
2218 | 0 | const URI_CHAR ** errorPos) { |
2219 | 0 | if ((afterLast == NULL) && (first != NULL)) { |
2220 | 0 | afterLast = first + URI_STRLEN(first); |
2221 | 0 | } |
2222 | 0 | return URI_FUNC(ParseSingleUriExMm)(uri, first, afterLast, errorPos, NULL); |
2223 | 0 | } Unexecuted instantiation: uriParseSingleUriExA Unexecuted instantiation: uriParseSingleUriExW |
2224 | | |
2225 | | |
2226 | | |
2227 | | int URI_FUNC(ParseSingleUriExMm)(URI_TYPE(Uri) * uri, |
2228 | | const URI_CHAR * first, const URI_CHAR * afterLast, |
2229 | 0 | const URI_CHAR ** errorPos, UriMemoryManager * memory) { |
2230 | 0 | URI_TYPE(ParserState) state; |
2231 | 0 | int res; |
2232 | | |
2233 | | /* Check params */ |
2234 | 0 | if ((uri == NULL) || (first == NULL) || (afterLast == NULL)) { |
2235 | 0 | return URI_ERROR_NULL; |
2236 | 0 | } |
2237 | 0 | URI_CHECK_MEMORY_MANAGER(memory); /* may return */ |
2238 | | |
2239 | 0 | state.uri = uri; |
2240 | |
|
2241 | 0 | res = URI_FUNC(ParseUriExMm)(&state, first, afterLast, memory); |
2242 | |
|
2243 | 0 | if (res != URI_SUCCESS) { |
2244 | 0 | if (errorPos != NULL) { |
2245 | 0 | *errorPos = state.errorPos; |
2246 | 0 | } |
2247 | 0 | URI_FUNC(FreeUriMembersMm)(uri, memory); |
2248 | 0 | } |
2249 | |
|
2250 | 0 | return res; |
2251 | 0 | } Unexecuted instantiation: uriParseSingleUriExMmA Unexecuted instantiation: uriParseSingleUriExMmW |
2252 | | |
2253 | | |
2254 | | |
2255 | 0 | void URI_FUNC(FreeUriMembers)(URI_TYPE(Uri) * uri) { |
2256 | 0 | URI_FUNC(FreeUriMembersMm)(uri, NULL); |
2257 | 0 | } Unexecuted instantiation: uriFreeUriMembersA Unexecuted instantiation: uriFreeUriMembersW |
2258 | | |
2259 | | |
2260 | | |
2261 | 0 | int URI_FUNC(FreeUriMembersMm)(URI_TYPE(Uri) * uri, UriMemoryManager * memory) { |
2262 | 0 | if (uri == NULL) { |
2263 | 0 | return URI_ERROR_NULL; |
2264 | 0 | } |
2265 | | |
2266 | 0 | URI_CHECK_MEMORY_MANAGER(memory); /* may return */ |
2267 | | |
2268 | 0 | if (uri->owner) { |
2269 | | /* Scheme */ |
2270 | 0 | if (uri->scheme.first != NULL) { |
2271 | 0 | if (uri->scheme.first != uri->scheme.afterLast) { |
2272 | 0 | memory->free(memory, (URI_CHAR *)uri->scheme.first); |
2273 | 0 | } |
2274 | 0 | uri->scheme.first = NULL; |
2275 | 0 | uri->scheme.afterLast = NULL; |
2276 | 0 | } |
2277 | | |
2278 | | /* User info */ |
2279 | 0 | if (uri->userInfo.first != NULL) { |
2280 | 0 | if (uri->userInfo.first != uri->userInfo.afterLast) { |
2281 | 0 | memory->free(memory, (URI_CHAR *)uri->userInfo.first); |
2282 | 0 | } |
2283 | 0 | uri->userInfo.first = NULL; |
2284 | 0 | uri->userInfo.afterLast = NULL; |
2285 | 0 | } |
2286 | | |
2287 | | /* Host data - IPvFuture (may affect host text) */ |
2288 | 0 | if (uri->hostData.ipFuture.first != NULL) { |
2289 | | /* NOTE: .hostData.ipFuture may hold the very same range pointers |
2290 | | * as .hostText; then we need to prevent freeing memory twice. */ |
2291 | 0 | if (uri->hostText.first == uri->hostData.ipFuture.first) { |
2292 | 0 | uri->hostText.first = NULL; |
2293 | 0 | uri->hostText.afterLast = NULL; |
2294 | 0 | } |
2295 | |
|
2296 | 0 | if (uri->hostData.ipFuture.first != uri->hostData.ipFuture.afterLast) { |
2297 | 0 | memory->free(memory, (URI_CHAR *)uri->hostData.ipFuture.first); |
2298 | 0 | } |
2299 | 0 | uri->hostData.ipFuture.first = NULL; |
2300 | 0 | uri->hostData.ipFuture.afterLast = NULL; |
2301 | 0 | } |
2302 | | |
2303 | | /* Host text (after IPvFuture, see above) */ |
2304 | 0 | if (uri->hostText.first != NULL) { |
2305 | 0 | if (uri->hostText.first != uri->hostText.afterLast) { |
2306 | 0 | memory->free(memory, (URI_CHAR *)uri->hostText.first); |
2307 | 0 | } |
2308 | 0 | uri->hostText.first = NULL; |
2309 | 0 | uri->hostText.afterLast = NULL; |
2310 | 0 | } |
2311 | 0 | } |
2312 | | |
2313 | | /* Host data - IPv4 */ |
2314 | 0 | if (uri->hostData.ip4 != NULL) { |
2315 | 0 | memory->free(memory, uri->hostData.ip4); |
2316 | 0 | uri->hostData.ip4 = NULL; |
2317 | 0 | } |
2318 | | |
2319 | | /* Host data - IPv6 */ |
2320 | 0 | if (uri->hostData.ip6 != NULL) { |
2321 | 0 | memory->free(memory, uri->hostData.ip6); |
2322 | 0 | uri->hostData.ip6 = NULL; |
2323 | 0 | } |
2324 | | |
2325 | | /* Port text */ |
2326 | 0 | if (uri->owner && (uri->portText.first != NULL)) { |
2327 | 0 | if (uri->portText.first != uri->portText.afterLast) { |
2328 | 0 | memory->free(memory, (URI_CHAR *)uri->portText.first); |
2329 | 0 | } |
2330 | 0 | uri->portText.first = NULL; |
2331 | 0 | uri->portText.afterLast = NULL; |
2332 | 0 | } |
2333 | | |
2334 | | /* Path */ |
2335 | 0 | if (uri->pathHead != NULL) { |
2336 | 0 | URI_TYPE(PathSegment) * segWalk = uri->pathHead; |
2337 | 0 | while (segWalk != NULL) { |
2338 | 0 | URI_TYPE(PathSegment) * const next = segWalk->next; |
2339 | 0 | if (uri->owner && (segWalk->text.first != NULL) |
2340 | 0 | && (segWalk->text.first < segWalk->text.afterLast)) { |
2341 | 0 | memory->free(memory, (URI_CHAR *)segWalk->text.first); |
2342 | 0 | } |
2343 | 0 | memory->free(memory, segWalk); |
2344 | 0 | segWalk = next; |
2345 | 0 | } |
2346 | 0 | uri->pathHead = NULL; |
2347 | 0 | uri->pathTail = NULL; |
2348 | 0 | } |
2349 | |
|
2350 | 0 | if (uri->owner) { |
2351 | | /* Query */ |
2352 | 0 | if (uri->query.first != NULL) { |
2353 | 0 | if (uri->query.first != uri->query.afterLast) { |
2354 | 0 | memory->free(memory, (URI_CHAR *)uri->query.first); |
2355 | 0 | } |
2356 | 0 | uri->query.first = NULL; |
2357 | 0 | uri->query.afterLast = NULL; |
2358 | 0 | } |
2359 | | |
2360 | | /* Fragment */ |
2361 | 0 | if (uri->fragment.first != NULL) { |
2362 | 0 | if (uri->fragment.first != uri->fragment.afterLast) { |
2363 | 0 | memory->free(memory, (URI_CHAR *)uri->fragment.first); |
2364 | 0 | } |
2365 | 0 | uri->fragment.first = NULL; |
2366 | 0 | uri->fragment.afterLast = NULL; |
2367 | 0 | } |
2368 | 0 | } |
2369 | |
|
2370 | 0 | return URI_SUCCESS; |
2371 | 0 | } Unexecuted instantiation: uriFreeUriMembersMmA Unexecuted instantiation: uriFreeUriMembersMmW |
2372 | | |
2373 | | |
2374 | | |
2375 | 0 | UriBool URI_FUNC(_TESTING_ONLY_ParseIpSix)(const URI_CHAR * text) { |
2376 | 0 | UriMemoryManager * const memory = &defaultMemoryManager; |
2377 | 0 | URI_TYPE(Uri) uri; |
2378 | 0 | URI_TYPE(ParserState) parser; |
2379 | 0 | const URI_CHAR * const afterIpSix = text + URI_STRLEN(text); |
2380 | 0 | const URI_CHAR * res; |
2381 | |
|
2382 | 0 | URI_FUNC(ResetUri)(&uri); |
2383 | 0 | parser.uri = &uri; |
2384 | 0 | URI_FUNC(ResetParserStateExceptUri)(&parser); |
2385 | 0 | parser.uri->hostData.ip6 = memory->malloc(memory, 1 * sizeof(UriIp6)); |
2386 | 0 | res = URI_FUNC(ParseIPv6address2)(&parser, text, afterIpSix, memory); |
2387 | 0 | URI_FUNC(FreeUriMembersMm)(&uri, memory); |
2388 | 0 | return res == afterIpSix ? URI_TRUE : URI_FALSE; |
2389 | 0 | } Unexecuted instantiation: uri_TESTING_ONLY_ParseIpSixA Unexecuted instantiation: uri_TESTING_ONLY_ParseIpSixW |
2390 | | |
2391 | | |
2392 | | |
2393 | 0 | UriBool URI_FUNC(_TESTING_ONLY_ParseIpFour)(const URI_CHAR * text) { |
2394 | 0 | unsigned char octets[4]; |
2395 | 0 | int res = URI_FUNC(ParseIpFourAddress)(octets, text, text + URI_STRLEN(text)); |
2396 | 0 | return (res == URI_SUCCESS) ? URI_TRUE : URI_FALSE; |
2397 | 0 | } Unexecuted instantiation: uri_TESTING_ONLY_ParseIpFourA Unexecuted instantiation: uri_TESTING_ONLY_ParseIpFourW |
2398 | | |
2399 | | |
2400 | | |
2401 | | #undef URI_SET_DIGIT |
2402 | | #undef URI_SET_HEX_LETTER_UPPER |
2403 | | #undef URI_SET_HEX_LETTER_LOWER |
2404 | | #undef URI_SET_HEXDIG |
2405 | | #undef URI_SET_ALPHA |
2406 | | |
2407 | | |
2408 | | |
2409 | | #endif |