Alien-nghttp3
view release on metacpan or search on metacpan
vendor/nghttp3-1.18.0/lib/sfparse/sfparse.c view on Meta::CPAN
default:
return SFPARSE_ERR_PARSE;
}
++sfp->pos;
if (dest) {
dest->type = SFPARSE_TYPE_BOOLEAN;
dest->flags = SFPARSE_VALUE_FLAG_NONE;
dest->boolean = b;
}
return 0;
}
static const uint8_t pct_tbl[256] = {
DIGITS(1),
HEXALPHAS(2),
};
static int pctdecode(uint8_t *pc, const uint8_t **ppos) {
uint8_t c, b = **ppos;
switch (pct_tbl[b]) {
case 0:
return -1;
case 1:
c = (uint8_t)((b - '0') << 4);
break;
case 2:
c = (uint8_t)((b - 'a' + 10) << 4);
break;
default:
assert(0);
abort();
}
b = *++*ppos;
switch (pct_tbl[b]) {
case 0:
return -1;
case 1:
c |= (uint8_t)(b - '0');
break;
case 2:
c |= (uint8_t)(b - 'a' + 10);
break;
}
*pc = c;
++*ppos;
return 0;
}
/* Start of utf8 dfa */
/* Copyright (c) 2008-2010 Bjoern Hoehrmann <bjoern@hoehrmann.de>
* See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
*
* Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#define UTF8_ACCEPT 0
#define UTF8_REJECT 12
/* clang-format off */
static const uint8_t utf8d[] = {
/*
* The first part of the table maps bytes to character classes that
* to reduce the size of the transition table and create bitmasks.
*/
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8,
/*
* The second part is a transition table that maps a combination
* of a state of the automaton and a character class to a state.
*/
0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12,
12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12,
12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
12,36,12,12,12,12,12,12,12,12,12,12,
};
/* clang-format on */
static void utf8_decode(uint32_t *state, uint8_t byte) {
*state = utf8d[256 + *state + utf8d[byte]];
}
/* End of utf8 dfa */
static const uint8_t dispstring_tbl[256] = {
[' '] = 1, ['!'] = 1, ['#'] = 1, ['$'] = 1, ['&'] = 1, ['\''] = 1, ['('] = 1,
[')'] = 1, ['*'] = 1, ['+'] = 1, [','] = 1, ['-'] = 1, ['.'] = 1, ['/'] = 1,
DIGITS(1), [':'] = 1, [';'] = 1, ['<'] = 1, ['='] = 1, ['>'] = 1, ['?'] = 1,
['@'] = 1, ALPHAS(1), ['['] = 1, ['\\'] = 1, [']'] = 1, ['^'] = 1, ['_'] = 1,
['`'] = 1, ['{'] = 1, ['|'] = 1, ['}'] = 1, ['~'] = 1, ['%'] = 2, ['"'] = 3,
};
static int parser_dispstring(sfparse_parser *sfp, sfparse_value *dest) {
const uint8_t *base;
uint8_t c;
uint32_t utf8state = UTF8_ACCEPT;
assert('%' == *sfp->pos);
++sfp->pos;
if (parser_eof(sfp) || *sfp->pos != '"') {
return SFPARSE_ERR_PARSE;
}
base = ++sfp->pos;
for (; !parser_eof(sfp);) {
switch (dispstring_tbl[*sfp->pos]) {
case 0:
return SFPARSE_ERR_PARSE;
case 1:
++sfp->pos;
break;
case 2:
for (;;) {
++sfp->pos;
if (sfp->pos + 2 > sfp->end || pctdecode(&c, &sfp->pos) != 0) {
return SFPARSE_ERR_PARSE;
}
utf8_decode(&utf8state, c);
if (utf8state == UTF8_ACCEPT) {
if (sfp->pos != sfp->end && *sfp->pos == '%') {
continue;
}
break;
}
if (utf8state == UTF8_REJECT || sfp->pos + 1 > sfp->end ||
*sfp->pos != '%') {
return SFPARSE_ERR_PARSE;
}
}
break;
case 3:
assert(utf8state == UTF8_ACCEPT);
if (dest) {
dest->type = SFPARSE_TYPE_DISPSTRING;
dest->flags = SFPARSE_VALUE_FLAG_NONE;
dest->vec.len = (size_t)(sfp->pos - base);
dest->vec.base = dest->vec.len == 0 ? NULL : (uint8_t *)base;
}
++sfp->pos;
return 0;
}
}
return SFPARSE_ERR_PARSE;
}
static const uint8_t bare_item_tbl[256] = {
['"'] = 1, ['-'] = 2, DIGITS(2), ['@'] = 3, [':'] = 4,
['?'] = 5, ['*'] = 6, ALPHAS(6), ['%'] = 7,
};
static int parser_bare_item(sfparse_parser *sfp, sfparse_value *dest) {
switch (bare_item_tbl[*sfp->pos]) {
case 0:
return SFPARSE_ERR_PARSE;
case 1:
return parser_string(sfp, dest);
case 2:
return parser_number(sfp, dest);
case 3:
return parser_date(sfp, dest);
case 4:
return parser_byteseq(sfp, dest);
case 5:
return parser_boolean(sfp, dest);
case 6:
return parser_token(sfp, dest);
case 7:
return parser_dispstring(sfp, dest);
default:
assert(0);
abort();
}
}
static int parser_skip_inner_list(sfparse_parser *sfp);
int sfparse_parser_param(sfparse_parser *sfp, sfparse_vec *dest_key,
sfparse_value *dest_value) {
int rv;
switch (sfp->state & SFPARSE_STATE_OP_MASK) {
case SFPARSE_STATE_BEFORE:
rv = parser_skip_inner_list(sfp);
if (rv != 0) {
return rv;
}
/* fall through */
( run in 0.882 second using v1.01-cache-2.11-cpan-234fa220139 )