Coverage Report

Created: 2025-12-14 06:06

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