Coverage Report

Created: 2026-02-14 06:52

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