11cb0ef41Sopenharmony_ci/*
21cb0ef41Sopenharmony_ci * nghttp3
31cb0ef41Sopenharmony_ci *
41cb0ef41Sopenharmony_ci * Copyright (c) 2019 nghttp3 contributors
51cb0ef41Sopenharmony_ci * Copyright (c) 2015 nghttp2 contributors
61cb0ef41Sopenharmony_ci *
71cb0ef41Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining
81cb0ef41Sopenharmony_ci * a copy of this software and associated documentation files (the
91cb0ef41Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
101cb0ef41Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
111cb0ef41Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to
121cb0ef41Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
131cb0ef41Sopenharmony_ci * the following conditions:
141cb0ef41Sopenharmony_ci *
151cb0ef41Sopenharmony_ci * The above copyright notice and this permission notice shall be
161cb0ef41Sopenharmony_ci * included in all copies or substantial portions of the Software.
171cb0ef41Sopenharmony_ci *
181cb0ef41Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
191cb0ef41Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
201cb0ef41Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
211cb0ef41Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
221cb0ef41Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
231cb0ef41Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
241cb0ef41Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
251cb0ef41Sopenharmony_ci */
261cb0ef41Sopenharmony_ci#include "nghttp3_http.h"
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci#include <string.h>
291cb0ef41Sopenharmony_ci#include <assert.h>
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci#include "nghttp3_stream.h"
321cb0ef41Sopenharmony_ci#include "nghttp3_macro.h"
331cb0ef41Sopenharmony_ci#include "nghttp3_conv.h"
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_cistatic uint8_t downcase(uint8_t c) {
361cb0ef41Sopenharmony_ci  return 'A' <= c && c <= 'Z' ? (uint8_t)(c - 'A' + 'a') : c;
371cb0ef41Sopenharmony_ci}
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci/*
401cb0ef41Sopenharmony_ci * memieq returns 1 if the data pointed by |a| of length |n| equals to
411cb0ef41Sopenharmony_ci * |b| of the same length in case-insensitive manner.  The data
421cb0ef41Sopenharmony_ci * pointed by |a| must not include upper cased letters (A-Z).
431cb0ef41Sopenharmony_ci */
441cb0ef41Sopenharmony_cistatic int memieq(const void *a, const void *b, size_t n) {
451cb0ef41Sopenharmony_ci  size_t i;
461cb0ef41Sopenharmony_ci  const uint8_t *aa = a, *bb = b;
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci  for (i = 0; i < n; ++i) {
491cb0ef41Sopenharmony_ci    if (aa[i] != downcase(bb[i])) {
501cb0ef41Sopenharmony_ci      return 0;
511cb0ef41Sopenharmony_ci    }
521cb0ef41Sopenharmony_ci  }
531cb0ef41Sopenharmony_ci  return 1;
541cb0ef41Sopenharmony_ci}
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci#define lstrieq(A, B, N) ((sizeof((A)) - 1) == (N) && memieq((A), (B), (N)))
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_cistatic int64_t parse_uint(const uint8_t *s, size_t len) {
591cb0ef41Sopenharmony_ci  int64_t n = 0;
601cb0ef41Sopenharmony_ci  size_t i;
611cb0ef41Sopenharmony_ci  if (len == 0) {
621cb0ef41Sopenharmony_ci    return -1;
631cb0ef41Sopenharmony_ci  }
641cb0ef41Sopenharmony_ci  for (i = 0; i < len; ++i) {
651cb0ef41Sopenharmony_ci    if ('0' <= s[i] && s[i] <= '9') {
661cb0ef41Sopenharmony_ci      if (n > INT64_MAX / 10) {
671cb0ef41Sopenharmony_ci        return -1;
681cb0ef41Sopenharmony_ci      }
691cb0ef41Sopenharmony_ci      n *= 10;
701cb0ef41Sopenharmony_ci      if (n > INT64_MAX - (s[i] - '0')) {
711cb0ef41Sopenharmony_ci        return -1;
721cb0ef41Sopenharmony_ci      }
731cb0ef41Sopenharmony_ci      n += s[i] - '0';
741cb0ef41Sopenharmony_ci      continue;
751cb0ef41Sopenharmony_ci    }
761cb0ef41Sopenharmony_ci    return -1;
771cb0ef41Sopenharmony_ci  }
781cb0ef41Sopenharmony_ci  return n;
791cb0ef41Sopenharmony_ci}
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_cistatic int check_pseudo_header(nghttp3_http_state *http,
821cb0ef41Sopenharmony_ci                               const nghttp3_qpack_nv *nv, uint32_t flag) {
831cb0ef41Sopenharmony_ci  if ((http->flags & flag) || nv->value->len == 0) {
841cb0ef41Sopenharmony_ci    return 0;
851cb0ef41Sopenharmony_ci  }
861cb0ef41Sopenharmony_ci  http->flags |= flag;
871cb0ef41Sopenharmony_ci  return 1;
881cb0ef41Sopenharmony_ci}
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_cistatic int expect_response_body(nghttp3_http_state *http) {
911cb0ef41Sopenharmony_ci  return (http->flags & NGHTTP3_HTTP_FLAG_METH_HEAD) == 0 &&
921cb0ef41Sopenharmony_ci         http->status_code / 100 != 1 && http->status_code != 304 &&
931cb0ef41Sopenharmony_ci         http->status_code != 204;
941cb0ef41Sopenharmony_ci}
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_ci/* For "http" or "https" URIs, OPTIONS request may have "*" in :path
971cb0ef41Sopenharmony_ci   header field to represent system-wide OPTIONS request.  Otherwise,
981cb0ef41Sopenharmony_ci   :path header field value must start with "/".  This function must
991cb0ef41Sopenharmony_ci   be called after ":method" header field was received.  This function
1001cb0ef41Sopenharmony_ci   returns nonzero if path is valid.*/
1011cb0ef41Sopenharmony_cistatic int check_path_flags(nghttp3_http_state *http) {
1021cb0ef41Sopenharmony_ci  return (http->flags & NGHTTP3_HTTP_FLAG_SCHEME_HTTP) == 0 ||
1031cb0ef41Sopenharmony_ci         ((http->flags & NGHTTP3_HTTP_FLAG_PATH_REGULAR) ||
1041cb0ef41Sopenharmony_ci          ((http->flags & NGHTTP3_HTTP_FLAG_METH_OPTIONS) &&
1051cb0ef41Sopenharmony_ci           (http->flags & NGHTTP3_HTTP_FLAG_PATH_ASTERISK)));
1061cb0ef41Sopenharmony_ci}
1071cb0ef41Sopenharmony_ci
1081cb0ef41Sopenharmony_ci/* Generated by genchartbl.py */
1091cb0ef41Sopenharmony_cistatic const int SF_KEY_CHARS[] = {
1101cb0ef41Sopenharmony_ci    0 /* NUL  */, 0 /* SOH  */, 0 /* STX  */, 0 /* ETX  */, 0 /* EOT  */,
1111cb0ef41Sopenharmony_ci    0 /* ENQ  */, 0 /* ACK  */, 0 /* BEL  */, 0 /* BS   */, 0 /* HT   */,
1121cb0ef41Sopenharmony_ci    0 /* LF   */, 0 /* VT   */, 0 /* FF   */, 0 /* CR   */, 0 /* SO   */,
1131cb0ef41Sopenharmony_ci    0 /* SI   */, 0 /* DLE  */, 0 /* DC1  */, 0 /* DC2  */, 0 /* DC3  */,
1141cb0ef41Sopenharmony_ci    0 /* DC4  */, 0 /* NAK  */, 0 /* SYN  */, 0 /* ETB  */, 0 /* CAN  */,
1151cb0ef41Sopenharmony_ci    0 /* EM   */, 0 /* SUB  */, 0 /* ESC  */, 0 /* FS   */, 0 /* GS   */,
1161cb0ef41Sopenharmony_ci    0 /* RS   */, 0 /* US   */, 0 /* SPC  */, 0 /* !    */, 0 /* "    */,
1171cb0ef41Sopenharmony_ci    0 /* #    */, 0 /* $    */, 0 /* %    */, 0 /* &    */, 0 /* '    */,
1181cb0ef41Sopenharmony_ci    0 /* (    */, 0 /* )    */, 1 /* *    */, 0 /* +    */, 0 /* ,    */,
1191cb0ef41Sopenharmony_ci    1 /* -    */, 1 /* .    */, 0 /* /    */, 1 /* 0    */, 1 /* 1    */,
1201cb0ef41Sopenharmony_ci    1 /* 2    */, 1 /* 3    */, 1 /* 4    */, 1 /* 5    */, 1 /* 6    */,
1211cb0ef41Sopenharmony_ci    1 /* 7    */, 1 /* 8    */, 1 /* 9    */, 0 /* :    */, 0 /* ;    */,
1221cb0ef41Sopenharmony_ci    0 /* <    */, 0 /* =    */, 0 /* >    */, 0 /* ?    */, 0 /* @    */,
1231cb0ef41Sopenharmony_ci    0 /* A    */, 0 /* B    */, 0 /* C    */, 0 /* D    */, 0 /* E    */,
1241cb0ef41Sopenharmony_ci    0 /* F    */, 0 /* G    */, 0 /* H    */, 0 /* I    */, 0 /* J    */,
1251cb0ef41Sopenharmony_ci    0 /* K    */, 0 /* L    */, 0 /* M    */, 0 /* N    */, 0 /* O    */,
1261cb0ef41Sopenharmony_ci    0 /* P    */, 0 /* Q    */, 0 /* R    */, 0 /* S    */, 0 /* T    */,
1271cb0ef41Sopenharmony_ci    0 /* U    */, 0 /* V    */, 0 /* W    */, 0 /* X    */, 0 /* Y    */,
1281cb0ef41Sopenharmony_ci    0 /* Z    */, 0 /* [    */, 0 /* \    */, 0 /* ]    */, 0 /* ^    */,
1291cb0ef41Sopenharmony_ci    1 /* _    */, 0 /* `    */, 1 /* a    */, 1 /* b    */, 1 /* c    */,
1301cb0ef41Sopenharmony_ci    1 /* d    */, 1 /* e    */, 1 /* f    */, 1 /* g    */, 1 /* h    */,
1311cb0ef41Sopenharmony_ci    1 /* i    */, 1 /* j    */, 1 /* k    */, 1 /* l    */, 1 /* m    */,
1321cb0ef41Sopenharmony_ci    1 /* n    */, 1 /* o    */, 1 /* p    */, 1 /* q    */, 1 /* r    */,
1331cb0ef41Sopenharmony_ci    1 /* s    */, 1 /* t    */, 1 /* u    */, 1 /* v    */, 1 /* w    */,
1341cb0ef41Sopenharmony_ci    1 /* x    */, 1 /* y    */, 1 /* z    */, 0 /* {    */, 0 /* |    */,
1351cb0ef41Sopenharmony_ci    0 /* }    */, 0 /* ~    */, 0 /* DEL  */, 0 /* 0x80 */, 0 /* 0x81 */,
1361cb0ef41Sopenharmony_ci    0 /* 0x82 */, 0 /* 0x83 */, 0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */,
1371cb0ef41Sopenharmony_ci    0 /* 0x87 */, 0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */,
1381cb0ef41Sopenharmony_ci    0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */, 0 /* 0x90 */,
1391cb0ef41Sopenharmony_ci    0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */, 0 /* 0x94 */, 0 /* 0x95 */,
1401cb0ef41Sopenharmony_ci    0 /* 0x96 */, 0 /* 0x97 */, 0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */,
1411cb0ef41Sopenharmony_ci    0 /* 0x9b */, 0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */,
1421cb0ef41Sopenharmony_ci    0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */, 0 /* 0xa4 */,
1431cb0ef41Sopenharmony_ci    0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */, 0 /* 0xa8 */, 0 /* 0xa9 */,
1441cb0ef41Sopenharmony_ci    0 /* 0xaa */, 0 /* 0xab */, 0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */,
1451cb0ef41Sopenharmony_ci    0 /* 0xaf */, 0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */,
1461cb0ef41Sopenharmony_ci    0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */, 0 /* 0xb8 */,
1471cb0ef41Sopenharmony_ci    0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */, 0 /* 0xbc */, 0 /* 0xbd */,
1481cb0ef41Sopenharmony_ci    0 /* 0xbe */, 0 /* 0xbf */, 0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */,
1491cb0ef41Sopenharmony_ci    0 /* 0xc3 */, 0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */,
1501cb0ef41Sopenharmony_ci    0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */, 0 /* 0xcc */,
1511cb0ef41Sopenharmony_ci    0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */, 0 /* 0xd0 */, 0 /* 0xd1 */,
1521cb0ef41Sopenharmony_ci    0 /* 0xd2 */, 0 /* 0xd3 */, 0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */,
1531cb0ef41Sopenharmony_ci    0 /* 0xd7 */, 0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */,
1541cb0ef41Sopenharmony_ci    0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */, 0 /* 0xe0 */,
1551cb0ef41Sopenharmony_ci    0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */, 0 /* 0xe4 */, 0 /* 0xe5 */,
1561cb0ef41Sopenharmony_ci    0 /* 0xe6 */, 0 /* 0xe7 */, 0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */,
1571cb0ef41Sopenharmony_ci    0 /* 0xeb */, 0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */,
1581cb0ef41Sopenharmony_ci    0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */, 0 /* 0xf4 */,
1591cb0ef41Sopenharmony_ci    0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */, 0 /* 0xf8 */, 0 /* 0xf9 */,
1601cb0ef41Sopenharmony_ci    0 /* 0xfa */, 0 /* 0xfb */, 0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */,
1611cb0ef41Sopenharmony_ci    0 /* 0xff */,
1621cb0ef41Sopenharmony_ci};
1631cb0ef41Sopenharmony_ci
1641cb0ef41Sopenharmony_cistatic nghttp3_ssize sf_parse_key(const uint8_t *begin, const uint8_t *end) {
1651cb0ef41Sopenharmony_ci  const uint8_t *p = begin;
1661cb0ef41Sopenharmony_ci
1671cb0ef41Sopenharmony_ci  if ((*p < 'a' || 'z' < *p) && *p != '*') {
1681cb0ef41Sopenharmony_ci    return -1;
1691cb0ef41Sopenharmony_ci  }
1701cb0ef41Sopenharmony_ci
1711cb0ef41Sopenharmony_ci  for (; p != end && SF_KEY_CHARS[*p]; ++p)
1721cb0ef41Sopenharmony_ci    ;
1731cb0ef41Sopenharmony_ci
1741cb0ef41Sopenharmony_ci  return p - begin;
1751cb0ef41Sopenharmony_ci}
1761cb0ef41Sopenharmony_ci
1771cb0ef41Sopenharmony_cistatic nghttp3_ssize sf_parse_integer_or_decimal(nghttp3_sf_value *dest,
1781cb0ef41Sopenharmony_ci                                                 const uint8_t *begin,
1791cb0ef41Sopenharmony_ci                                                 const uint8_t *end) {
1801cb0ef41Sopenharmony_ci  const uint8_t *p = begin;
1811cb0ef41Sopenharmony_ci  int sign = 1;
1821cb0ef41Sopenharmony_ci  int64_t value = 0;
1831cb0ef41Sopenharmony_ci  int type = NGHTTP3_SF_VALUE_TYPE_INTEGER;
1841cb0ef41Sopenharmony_ci  size_t len = 0;
1851cb0ef41Sopenharmony_ci  size_t fpos = 0;
1861cb0ef41Sopenharmony_ci  size_t i;
1871cb0ef41Sopenharmony_ci
1881cb0ef41Sopenharmony_ci  if (*p == '-') {
1891cb0ef41Sopenharmony_ci    if (++p == end) {
1901cb0ef41Sopenharmony_ci      return -1;
1911cb0ef41Sopenharmony_ci    }
1921cb0ef41Sopenharmony_ci
1931cb0ef41Sopenharmony_ci    sign = -1;
1941cb0ef41Sopenharmony_ci  }
1951cb0ef41Sopenharmony_ci
1961cb0ef41Sopenharmony_ci  if (*p < '0' || '9' < *p) {
1971cb0ef41Sopenharmony_ci    return -1;
1981cb0ef41Sopenharmony_ci  }
1991cb0ef41Sopenharmony_ci
2001cb0ef41Sopenharmony_ci  for (; p != end; ++p) {
2011cb0ef41Sopenharmony_ci    switch (*p) {
2021cb0ef41Sopenharmony_ci    case '0':
2031cb0ef41Sopenharmony_ci    case '1':
2041cb0ef41Sopenharmony_ci    case '2':
2051cb0ef41Sopenharmony_ci    case '3':
2061cb0ef41Sopenharmony_ci    case '4':
2071cb0ef41Sopenharmony_ci    case '5':
2081cb0ef41Sopenharmony_ci    case '6':
2091cb0ef41Sopenharmony_ci    case '7':
2101cb0ef41Sopenharmony_ci    case '8':
2111cb0ef41Sopenharmony_ci    case '9':
2121cb0ef41Sopenharmony_ci      value *= 10;
2131cb0ef41Sopenharmony_ci      value += *p - '0';
2141cb0ef41Sopenharmony_ci
2151cb0ef41Sopenharmony_ci      if (++len > 15) {
2161cb0ef41Sopenharmony_ci        return -1;
2171cb0ef41Sopenharmony_ci      }
2181cb0ef41Sopenharmony_ci
2191cb0ef41Sopenharmony_ci      break;
2201cb0ef41Sopenharmony_ci    case '.':
2211cb0ef41Sopenharmony_ci      if (type != NGHTTP3_SF_VALUE_TYPE_INTEGER) {
2221cb0ef41Sopenharmony_ci        goto fin;
2231cb0ef41Sopenharmony_ci      }
2241cb0ef41Sopenharmony_ci
2251cb0ef41Sopenharmony_ci      if (len > 12) {
2261cb0ef41Sopenharmony_ci        return -1;
2271cb0ef41Sopenharmony_ci      }
2281cb0ef41Sopenharmony_ci      fpos = len;
2291cb0ef41Sopenharmony_ci      type = NGHTTP3_SF_VALUE_TYPE_DECIMAL;
2301cb0ef41Sopenharmony_ci
2311cb0ef41Sopenharmony_ci      break;
2321cb0ef41Sopenharmony_ci    default:
2331cb0ef41Sopenharmony_ci      goto fin;
2341cb0ef41Sopenharmony_ci    };
2351cb0ef41Sopenharmony_ci  }
2361cb0ef41Sopenharmony_ci
2371cb0ef41Sopenharmony_cifin:
2381cb0ef41Sopenharmony_ci  switch (type) {
2391cb0ef41Sopenharmony_ci  case NGHTTP3_SF_VALUE_TYPE_INTEGER:
2401cb0ef41Sopenharmony_ci    if (dest) {
2411cb0ef41Sopenharmony_ci      dest->type = (uint8_t)type;
2421cb0ef41Sopenharmony_ci      dest->i = value * sign;
2431cb0ef41Sopenharmony_ci    }
2441cb0ef41Sopenharmony_ci
2451cb0ef41Sopenharmony_ci    return p - begin;
2461cb0ef41Sopenharmony_ci  case NGHTTP3_SF_VALUE_TYPE_DECIMAL:
2471cb0ef41Sopenharmony_ci    if (fpos == len || len - fpos > 3) {
2481cb0ef41Sopenharmony_ci      return -1;
2491cb0ef41Sopenharmony_ci    }
2501cb0ef41Sopenharmony_ci
2511cb0ef41Sopenharmony_ci    if (dest) {
2521cb0ef41Sopenharmony_ci      dest->type = (uint8_t)type;
2531cb0ef41Sopenharmony_ci      dest->d = (double)value;
2541cb0ef41Sopenharmony_ci      for (i = len - fpos; i > 0; --i) {
2551cb0ef41Sopenharmony_ci        dest->d /= (double)10;
2561cb0ef41Sopenharmony_ci      }
2571cb0ef41Sopenharmony_ci      dest->d *= sign;
2581cb0ef41Sopenharmony_ci    }
2591cb0ef41Sopenharmony_ci
2601cb0ef41Sopenharmony_ci    return p - begin;
2611cb0ef41Sopenharmony_ci  default:
2621cb0ef41Sopenharmony_ci    assert(0);
2631cb0ef41Sopenharmony_ci    abort();
2641cb0ef41Sopenharmony_ci  }
2651cb0ef41Sopenharmony_ci}
2661cb0ef41Sopenharmony_ci
2671cb0ef41Sopenharmony_ci/* Generated by genchartbl.py */
2681cb0ef41Sopenharmony_cistatic const int SF_DQUOTE_CHARS[] = {
2691cb0ef41Sopenharmony_ci    0 /* NUL  */, 0 /* SOH  */, 0 /* STX  */, 0 /* ETX  */, 0 /* EOT  */,
2701cb0ef41Sopenharmony_ci    0 /* ENQ  */, 0 /* ACK  */, 0 /* BEL  */, 0 /* BS   */, 0 /* HT   */,
2711cb0ef41Sopenharmony_ci    0 /* LF   */, 0 /* VT   */, 0 /* FF   */, 0 /* CR   */, 0 /* SO   */,
2721cb0ef41Sopenharmony_ci    0 /* SI   */, 0 /* DLE  */, 0 /* DC1  */, 0 /* DC2  */, 0 /* DC3  */,
2731cb0ef41Sopenharmony_ci    0 /* DC4  */, 0 /* NAK  */, 0 /* SYN  */, 0 /* ETB  */, 0 /* CAN  */,
2741cb0ef41Sopenharmony_ci    0 /* EM   */, 0 /* SUB  */, 0 /* ESC  */, 0 /* FS   */, 0 /* GS   */,
2751cb0ef41Sopenharmony_ci    0 /* RS   */, 0 /* US   */, 1 /* SPC  */, 1 /* !    */, 0 /* "    */,
2761cb0ef41Sopenharmony_ci    1 /* #    */, 1 /* $    */, 1 /* %    */, 1 /* &    */, 1 /* '    */,
2771cb0ef41Sopenharmony_ci    1 /* (    */, 1 /* )    */, 1 /* *    */, 1 /* +    */, 1 /* ,    */,
2781cb0ef41Sopenharmony_ci    1 /* -    */, 1 /* .    */, 1 /* /    */, 1 /* 0    */, 1 /* 1    */,
2791cb0ef41Sopenharmony_ci    1 /* 2    */, 1 /* 3    */, 1 /* 4    */, 1 /* 5    */, 1 /* 6    */,
2801cb0ef41Sopenharmony_ci    1 /* 7    */, 1 /* 8    */, 1 /* 9    */, 1 /* :    */, 1 /* ;    */,
2811cb0ef41Sopenharmony_ci    1 /* <    */, 1 /* =    */, 1 /* >    */, 1 /* ?    */, 1 /* @    */,
2821cb0ef41Sopenharmony_ci    1 /* A    */, 1 /* B    */, 1 /* C    */, 1 /* D    */, 1 /* E    */,
2831cb0ef41Sopenharmony_ci    1 /* F    */, 1 /* G    */, 1 /* H    */, 1 /* I    */, 1 /* J    */,
2841cb0ef41Sopenharmony_ci    1 /* K    */, 1 /* L    */, 1 /* M    */, 1 /* N    */, 1 /* O    */,
2851cb0ef41Sopenharmony_ci    1 /* P    */, 1 /* Q    */, 1 /* R    */, 1 /* S    */, 1 /* T    */,
2861cb0ef41Sopenharmony_ci    1 /* U    */, 1 /* V    */, 1 /* W    */, 1 /* X    */, 1 /* Y    */,
2871cb0ef41Sopenharmony_ci    1 /* Z    */, 1 /* [    */, 0 /* \    */, 1 /* ]    */, 1 /* ^    */,
2881cb0ef41Sopenharmony_ci    1 /* _    */, 1 /* `    */, 1 /* a    */, 1 /* b    */, 1 /* c    */,
2891cb0ef41Sopenharmony_ci    1 /* d    */, 1 /* e    */, 1 /* f    */, 1 /* g    */, 1 /* h    */,
2901cb0ef41Sopenharmony_ci    1 /* i    */, 1 /* j    */, 1 /* k    */, 1 /* l    */, 1 /* m    */,
2911cb0ef41Sopenharmony_ci    1 /* n    */, 1 /* o    */, 1 /* p    */, 1 /* q    */, 1 /* r    */,
2921cb0ef41Sopenharmony_ci    1 /* s    */, 1 /* t    */, 1 /* u    */, 1 /* v    */, 1 /* w    */,
2931cb0ef41Sopenharmony_ci    1 /* x    */, 1 /* y    */, 1 /* z    */, 1 /* {    */, 1 /* |    */,
2941cb0ef41Sopenharmony_ci    1 /* }    */, 1 /* ~    */, 0 /* DEL  */, 0 /* 0x80 */, 0 /* 0x81 */,
2951cb0ef41Sopenharmony_ci    0 /* 0x82 */, 0 /* 0x83 */, 0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */,
2961cb0ef41Sopenharmony_ci    0 /* 0x87 */, 0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */,
2971cb0ef41Sopenharmony_ci    0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */, 0 /* 0x90 */,
2981cb0ef41Sopenharmony_ci    0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */, 0 /* 0x94 */, 0 /* 0x95 */,
2991cb0ef41Sopenharmony_ci    0 /* 0x96 */, 0 /* 0x97 */, 0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */,
3001cb0ef41Sopenharmony_ci    0 /* 0x9b */, 0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */,
3011cb0ef41Sopenharmony_ci    0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */, 0 /* 0xa4 */,
3021cb0ef41Sopenharmony_ci    0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */, 0 /* 0xa8 */, 0 /* 0xa9 */,
3031cb0ef41Sopenharmony_ci    0 /* 0xaa */, 0 /* 0xab */, 0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */,
3041cb0ef41Sopenharmony_ci    0 /* 0xaf */, 0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */,
3051cb0ef41Sopenharmony_ci    0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */, 0 /* 0xb8 */,
3061cb0ef41Sopenharmony_ci    0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */, 0 /* 0xbc */, 0 /* 0xbd */,
3071cb0ef41Sopenharmony_ci    0 /* 0xbe */, 0 /* 0xbf */, 0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */,
3081cb0ef41Sopenharmony_ci    0 /* 0xc3 */, 0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */,
3091cb0ef41Sopenharmony_ci    0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */, 0 /* 0xcc */,
3101cb0ef41Sopenharmony_ci    0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */, 0 /* 0xd0 */, 0 /* 0xd1 */,
3111cb0ef41Sopenharmony_ci    0 /* 0xd2 */, 0 /* 0xd3 */, 0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */,
3121cb0ef41Sopenharmony_ci    0 /* 0xd7 */, 0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */,
3131cb0ef41Sopenharmony_ci    0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */, 0 /* 0xe0 */,
3141cb0ef41Sopenharmony_ci    0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */, 0 /* 0xe4 */, 0 /* 0xe5 */,
3151cb0ef41Sopenharmony_ci    0 /* 0xe6 */, 0 /* 0xe7 */, 0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */,
3161cb0ef41Sopenharmony_ci    0 /* 0xeb */, 0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */,
3171cb0ef41Sopenharmony_ci    0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */, 0 /* 0xf4 */,
3181cb0ef41Sopenharmony_ci    0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */, 0 /* 0xf8 */, 0 /* 0xf9 */,
3191cb0ef41Sopenharmony_ci    0 /* 0xfa */, 0 /* 0xfb */, 0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */,
3201cb0ef41Sopenharmony_ci    0 /* 0xff */,
3211cb0ef41Sopenharmony_ci};
3221cb0ef41Sopenharmony_ci
3231cb0ef41Sopenharmony_cistatic nghttp3_ssize sf_parse_string(nghttp3_sf_value *dest,
3241cb0ef41Sopenharmony_ci                                     const uint8_t *begin, const uint8_t *end) {
3251cb0ef41Sopenharmony_ci  const uint8_t *p = begin;
3261cb0ef41Sopenharmony_ci
3271cb0ef41Sopenharmony_ci  if (*p++ != '"') {
3281cb0ef41Sopenharmony_ci    return -1;
3291cb0ef41Sopenharmony_ci  }
3301cb0ef41Sopenharmony_ci
3311cb0ef41Sopenharmony_ci  for (; p != end; ++p) {
3321cb0ef41Sopenharmony_ci    switch (*p) {
3331cb0ef41Sopenharmony_ci    case '\\':
3341cb0ef41Sopenharmony_ci      if (++p == end) {
3351cb0ef41Sopenharmony_ci        return -1;
3361cb0ef41Sopenharmony_ci      }
3371cb0ef41Sopenharmony_ci
3381cb0ef41Sopenharmony_ci      switch (*p) {
3391cb0ef41Sopenharmony_ci      case '"':
3401cb0ef41Sopenharmony_ci      case '\\':
3411cb0ef41Sopenharmony_ci        break;
3421cb0ef41Sopenharmony_ci      default:
3431cb0ef41Sopenharmony_ci        return -1;
3441cb0ef41Sopenharmony_ci      }
3451cb0ef41Sopenharmony_ci
3461cb0ef41Sopenharmony_ci      break;
3471cb0ef41Sopenharmony_ci    case '"':
3481cb0ef41Sopenharmony_ci      if (dest) {
3491cb0ef41Sopenharmony_ci        dest->type = NGHTTP3_SF_VALUE_TYPE_STRING;
3501cb0ef41Sopenharmony_ci        dest->s.base = begin + 1;
3511cb0ef41Sopenharmony_ci        dest->s.len = (size_t)(p - dest->s.base);
3521cb0ef41Sopenharmony_ci      }
3531cb0ef41Sopenharmony_ci
3541cb0ef41Sopenharmony_ci      ++p;
3551cb0ef41Sopenharmony_ci
3561cb0ef41Sopenharmony_ci      return p - begin;
3571cb0ef41Sopenharmony_ci    default:
3581cb0ef41Sopenharmony_ci      if (!SF_DQUOTE_CHARS[*p]) {
3591cb0ef41Sopenharmony_ci        return -1;
3601cb0ef41Sopenharmony_ci      }
3611cb0ef41Sopenharmony_ci    }
3621cb0ef41Sopenharmony_ci  }
3631cb0ef41Sopenharmony_ci
3641cb0ef41Sopenharmony_ci  return -1;
3651cb0ef41Sopenharmony_ci}
3661cb0ef41Sopenharmony_ci
3671cb0ef41Sopenharmony_ci/* Generated by genchartbl.py */
3681cb0ef41Sopenharmony_cistatic const int SF_TOKEN_CHARS[] = {
3691cb0ef41Sopenharmony_ci    0 /* NUL  */, 0 /* SOH  */, 0 /* STX  */, 0 /* ETX  */, 0 /* EOT  */,
3701cb0ef41Sopenharmony_ci    0 /* ENQ  */, 0 /* ACK  */, 0 /* BEL  */, 0 /* BS   */, 0 /* HT   */,
3711cb0ef41Sopenharmony_ci    0 /* LF   */, 0 /* VT   */, 0 /* FF   */, 0 /* CR   */, 0 /* SO   */,
3721cb0ef41Sopenharmony_ci    0 /* SI   */, 0 /* DLE  */, 0 /* DC1  */, 0 /* DC2  */, 0 /* DC3  */,
3731cb0ef41Sopenharmony_ci    0 /* DC4  */, 0 /* NAK  */, 0 /* SYN  */, 0 /* ETB  */, 0 /* CAN  */,
3741cb0ef41Sopenharmony_ci    0 /* EM   */, 0 /* SUB  */, 0 /* ESC  */, 0 /* FS   */, 0 /* GS   */,
3751cb0ef41Sopenharmony_ci    0 /* RS   */, 0 /* US   */, 0 /* SPC  */, 1 /* !    */, 0 /* "    */,
3761cb0ef41Sopenharmony_ci    1 /* #    */, 1 /* $    */, 1 /* %    */, 1 /* &    */, 1 /* '    */,
3771cb0ef41Sopenharmony_ci    0 /* (    */, 0 /* )    */, 1 /* *    */, 1 /* +    */, 0 /* ,    */,
3781cb0ef41Sopenharmony_ci    1 /* -    */, 1 /* .    */, 1 /* /    */, 1 /* 0    */, 1 /* 1    */,
3791cb0ef41Sopenharmony_ci    1 /* 2    */, 1 /* 3    */, 1 /* 4    */, 1 /* 5    */, 1 /* 6    */,
3801cb0ef41Sopenharmony_ci    1 /* 7    */, 1 /* 8    */, 1 /* 9    */, 1 /* :    */, 0 /* ;    */,
3811cb0ef41Sopenharmony_ci    0 /* <    */, 0 /* =    */, 0 /* >    */, 0 /* ?    */, 0 /* @    */,
3821cb0ef41Sopenharmony_ci    1 /* A    */, 1 /* B    */, 1 /* C    */, 1 /* D    */, 1 /* E    */,
3831cb0ef41Sopenharmony_ci    1 /* F    */, 1 /* G    */, 1 /* H    */, 1 /* I    */, 1 /* J    */,
3841cb0ef41Sopenharmony_ci    1 /* K    */, 1 /* L    */, 1 /* M    */, 1 /* N    */, 1 /* O    */,
3851cb0ef41Sopenharmony_ci    1 /* P    */, 1 /* Q    */, 1 /* R    */, 1 /* S    */, 1 /* T    */,
3861cb0ef41Sopenharmony_ci    1 /* U    */, 1 /* V    */, 1 /* W    */, 1 /* X    */, 1 /* Y    */,
3871cb0ef41Sopenharmony_ci    1 /* Z    */, 0 /* [    */, 0 /* \    */, 0 /* ]    */, 1 /* ^    */,
3881cb0ef41Sopenharmony_ci    1 /* _    */, 1 /* `    */, 1 /* a    */, 1 /* b    */, 1 /* c    */,
3891cb0ef41Sopenharmony_ci    1 /* d    */, 1 /* e    */, 1 /* f    */, 1 /* g    */, 1 /* h    */,
3901cb0ef41Sopenharmony_ci    1 /* i    */, 1 /* j    */, 1 /* k    */, 1 /* l    */, 1 /* m    */,
3911cb0ef41Sopenharmony_ci    1 /* n    */, 1 /* o    */, 1 /* p    */, 1 /* q    */, 1 /* r    */,
3921cb0ef41Sopenharmony_ci    1 /* s    */, 1 /* t    */, 1 /* u    */, 1 /* v    */, 1 /* w    */,
3931cb0ef41Sopenharmony_ci    1 /* x    */, 1 /* y    */, 1 /* z    */, 0 /* {    */, 1 /* |    */,
3941cb0ef41Sopenharmony_ci    0 /* }    */, 1 /* ~    */, 0 /* DEL  */, 0 /* 0x80 */, 0 /* 0x81 */,
3951cb0ef41Sopenharmony_ci    0 /* 0x82 */, 0 /* 0x83 */, 0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */,
3961cb0ef41Sopenharmony_ci    0 /* 0x87 */, 0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */,
3971cb0ef41Sopenharmony_ci    0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */, 0 /* 0x90 */,
3981cb0ef41Sopenharmony_ci    0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */, 0 /* 0x94 */, 0 /* 0x95 */,
3991cb0ef41Sopenharmony_ci    0 /* 0x96 */, 0 /* 0x97 */, 0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */,
4001cb0ef41Sopenharmony_ci    0 /* 0x9b */, 0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */,
4011cb0ef41Sopenharmony_ci    0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */, 0 /* 0xa4 */,
4021cb0ef41Sopenharmony_ci    0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */, 0 /* 0xa8 */, 0 /* 0xa9 */,
4031cb0ef41Sopenharmony_ci    0 /* 0xaa */, 0 /* 0xab */, 0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */,
4041cb0ef41Sopenharmony_ci    0 /* 0xaf */, 0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */,
4051cb0ef41Sopenharmony_ci    0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */, 0 /* 0xb8 */,
4061cb0ef41Sopenharmony_ci    0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */, 0 /* 0xbc */, 0 /* 0xbd */,
4071cb0ef41Sopenharmony_ci    0 /* 0xbe */, 0 /* 0xbf */, 0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */,
4081cb0ef41Sopenharmony_ci    0 /* 0xc3 */, 0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */,
4091cb0ef41Sopenharmony_ci    0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */, 0 /* 0xcc */,
4101cb0ef41Sopenharmony_ci    0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */, 0 /* 0xd0 */, 0 /* 0xd1 */,
4111cb0ef41Sopenharmony_ci    0 /* 0xd2 */, 0 /* 0xd3 */, 0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */,
4121cb0ef41Sopenharmony_ci    0 /* 0xd7 */, 0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */,
4131cb0ef41Sopenharmony_ci    0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */, 0 /* 0xe0 */,
4141cb0ef41Sopenharmony_ci    0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */, 0 /* 0xe4 */, 0 /* 0xe5 */,
4151cb0ef41Sopenharmony_ci    0 /* 0xe6 */, 0 /* 0xe7 */, 0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */,
4161cb0ef41Sopenharmony_ci    0 /* 0xeb */, 0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */,
4171cb0ef41Sopenharmony_ci    0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */, 0 /* 0xf4 */,
4181cb0ef41Sopenharmony_ci    0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */, 0 /* 0xf8 */, 0 /* 0xf9 */,
4191cb0ef41Sopenharmony_ci    0 /* 0xfa */, 0 /* 0xfb */, 0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */,
4201cb0ef41Sopenharmony_ci    0 /* 0xff */,
4211cb0ef41Sopenharmony_ci};
4221cb0ef41Sopenharmony_ci
4231cb0ef41Sopenharmony_cistatic nghttp3_ssize sf_parse_token(nghttp3_sf_value *dest,
4241cb0ef41Sopenharmony_ci                                    const uint8_t *begin, const uint8_t *end) {
4251cb0ef41Sopenharmony_ci  const uint8_t *p = begin;
4261cb0ef41Sopenharmony_ci
4271cb0ef41Sopenharmony_ci  if ((*p < 'A' || 'Z' < *p) && (*p < 'a' || 'z' < *p) && *p != '*') {
4281cb0ef41Sopenharmony_ci    return -1;
4291cb0ef41Sopenharmony_ci  }
4301cb0ef41Sopenharmony_ci
4311cb0ef41Sopenharmony_ci  for (; p != end && SF_TOKEN_CHARS[*p]; ++p)
4321cb0ef41Sopenharmony_ci    ;
4331cb0ef41Sopenharmony_ci
4341cb0ef41Sopenharmony_ci  if (dest) {
4351cb0ef41Sopenharmony_ci    dest->type = NGHTTP3_SF_VALUE_TYPE_TOKEN;
4361cb0ef41Sopenharmony_ci    dest->s.base = begin;
4371cb0ef41Sopenharmony_ci    dest->s.len = (size_t)(p - begin);
4381cb0ef41Sopenharmony_ci  }
4391cb0ef41Sopenharmony_ci
4401cb0ef41Sopenharmony_ci  return p - begin;
4411cb0ef41Sopenharmony_ci}
4421cb0ef41Sopenharmony_ci
4431cb0ef41Sopenharmony_ci/* Generated by genchartbl.py */
4441cb0ef41Sopenharmony_cistatic const int SF_BYTESEQ_CHARS[] = {
4451cb0ef41Sopenharmony_ci    0 /* NUL  */, 0 /* SOH  */, 0 /* STX  */, 0 /* ETX  */, 0 /* EOT  */,
4461cb0ef41Sopenharmony_ci    0 /* ENQ  */, 0 /* ACK  */, 0 /* BEL  */, 0 /* BS   */, 0 /* HT   */,
4471cb0ef41Sopenharmony_ci    0 /* LF   */, 0 /* VT   */, 0 /* FF   */, 0 /* CR   */, 0 /* SO   */,
4481cb0ef41Sopenharmony_ci    0 /* SI   */, 0 /* DLE  */, 0 /* DC1  */, 0 /* DC2  */, 0 /* DC3  */,
4491cb0ef41Sopenharmony_ci    0 /* DC4  */, 0 /* NAK  */, 0 /* SYN  */, 0 /* ETB  */, 0 /* CAN  */,
4501cb0ef41Sopenharmony_ci    0 /* EM   */, 0 /* SUB  */, 0 /* ESC  */, 0 /* FS   */, 0 /* GS   */,
4511cb0ef41Sopenharmony_ci    0 /* RS   */, 0 /* US   */, 0 /* SPC  */, 0 /* !    */, 0 /* "    */,
4521cb0ef41Sopenharmony_ci    0 /* #    */, 0 /* $    */, 0 /* %    */, 0 /* &    */, 0 /* '    */,
4531cb0ef41Sopenharmony_ci    0 /* (    */, 0 /* )    */, 0 /* *    */, 1 /* +    */, 0 /* ,    */,
4541cb0ef41Sopenharmony_ci    0 /* -    */, 0 /* .    */, 1 /* /    */, 1 /* 0    */, 1 /* 1    */,
4551cb0ef41Sopenharmony_ci    1 /* 2    */, 1 /* 3    */, 1 /* 4    */, 1 /* 5    */, 1 /* 6    */,
4561cb0ef41Sopenharmony_ci    1 /* 7    */, 1 /* 8    */, 1 /* 9    */, 0 /* :    */, 0 /* ;    */,
4571cb0ef41Sopenharmony_ci    0 /* <    */, 1 /* =    */, 0 /* >    */, 0 /* ?    */, 0 /* @    */,
4581cb0ef41Sopenharmony_ci    1 /* A    */, 1 /* B    */, 1 /* C    */, 1 /* D    */, 1 /* E    */,
4591cb0ef41Sopenharmony_ci    1 /* F    */, 1 /* G    */, 1 /* H    */, 1 /* I    */, 1 /* J    */,
4601cb0ef41Sopenharmony_ci    1 /* K    */, 1 /* L    */, 1 /* M    */, 1 /* N    */, 1 /* O    */,
4611cb0ef41Sopenharmony_ci    1 /* P    */, 1 /* Q    */, 1 /* R    */, 1 /* S    */, 1 /* T    */,
4621cb0ef41Sopenharmony_ci    1 /* U    */, 1 /* V    */, 1 /* W    */, 1 /* X    */, 1 /* Y    */,
4631cb0ef41Sopenharmony_ci    1 /* Z    */, 0 /* [    */, 0 /* \    */, 0 /* ]    */, 0 /* ^    */,
4641cb0ef41Sopenharmony_ci    0 /* _    */, 0 /* `    */, 1 /* a    */, 1 /* b    */, 1 /* c    */,
4651cb0ef41Sopenharmony_ci    1 /* d    */, 1 /* e    */, 1 /* f    */, 1 /* g    */, 1 /* h    */,
4661cb0ef41Sopenharmony_ci    1 /* i    */, 1 /* j    */, 1 /* k    */, 1 /* l    */, 1 /* m    */,
4671cb0ef41Sopenharmony_ci    1 /* n    */, 1 /* o    */, 1 /* p    */, 1 /* q    */, 1 /* r    */,
4681cb0ef41Sopenharmony_ci    1 /* s    */, 1 /* t    */, 1 /* u    */, 1 /* v    */, 1 /* w    */,
4691cb0ef41Sopenharmony_ci    1 /* x    */, 1 /* y    */, 1 /* z    */, 0 /* {    */, 0 /* |    */,
4701cb0ef41Sopenharmony_ci    0 /* }    */, 0 /* ~    */, 0 /* DEL  */, 0 /* 0x80 */, 0 /* 0x81 */,
4711cb0ef41Sopenharmony_ci    0 /* 0x82 */, 0 /* 0x83 */, 0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */,
4721cb0ef41Sopenharmony_ci    0 /* 0x87 */, 0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */,
4731cb0ef41Sopenharmony_ci    0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */, 0 /* 0x90 */,
4741cb0ef41Sopenharmony_ci    0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */, 0 /* 0x94 */, 0 /* 0x95 */,
4751cb0ef41Sopenharmony_ci    0 /* 0x96 */, 0 /* 0x97 */, 0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */,
4761cb0ef41Sopenharmony_ci    0 /* 0x9b */, 0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */,
4771cb0ef41Sopenharmony_ci    0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */, 0 /* 0xa4 */,
4781cb0ef41Sopenharmony_ci    0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */, 0 /* 0xa8 */, 0 /* 0xa9 */,
4791cb0ef41Sopenharmony_ci    0 /* 0xaa */, 0 /* 0xab */, 0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */,
4801cb0ef41Sopenharmony_ci    0 /* 0xaf */, 0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */,
4811cb0ef41Sopenharmony_ci    0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */, 0 /* 0xb8 */,
4821cb0ef41Sopenharmony_ci    0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */, 0 /* 0xbc */, 0 /* 0xbd */,
4831cb0ef41Sopenharmony_ci    0 /* 0xbe */, 0 /* 0xbf */, 0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */,
4841cb0ef41Sopenharmony_ci    0 /* 0xc3 */, 0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */,
4851cb0ef41Sopenharmony_ci    0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */, 0 /* 0xcc */,
4861cb0ef41Sopenharmony_ci    0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */, 0 /* 0xd0 */, 0 /* 0xd1 */,
4871cb0ef41Sopenharmony_ci    0 /* 0xd2 */, 0 /* 0xd3 */, 0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */,
4881cb0ef41Sopenharmony_ci    0 /* 0xd7 */, 0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */,
4891cb0ef41Sopenharmony_ci    0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */, 0 /* 0xe0 */,
4901cb0ef41Sopenharmony_ci    0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */, 0 /* 0xe4 */, 0 /* 0xe5 */,
4911cb0ef41Sopenharmony_ci    0 /* 0xe6 */, 0 /* 0xe7 */, 0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */,
4921cb0ef41Sopenharmony_ci    0 /* 0xeb */, 0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */,
4931cb0ef41Sopenharmony_ci    0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */, 0 /* 0xf4 */,
4941cb0ef41Sopenharmony_ci    0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */, 0 /* 0xf8 */, 0 /* 0xf9 */,
4951cb0ef41Sopenharmony_ci    0 /* 0xfa */, 0 /* 0xfb */, 0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */,
4961cb0ef41Sopenharmony_ci    0 /* 0xff */,
4971cb0ef41Sopenharmony_ci};
4981cb0ef41Sopenharmony_ci
4991cb0ef41Sopenharmony_cistatic nghttp3_ssize sf_parse_byteseq(nghttp3_sf_value *dest,
5001cb0ef41Sopenharmony_ci                                      const uint8_t *begin,
5011cb0ef41Sopenharmony_ci                                      const uint8_t *end) {
5021cb0ef41Sopenharmony_ci  const uint8_t *p = begin;
5031cb0ef41Sopenharmony_ci
5041cb0ef41Sopenharmony_ci  if (*p++ != ':') {
5051cb0ef41Sopenharmony_ci    return -1;
5061cb0ef41Sopenharmony_ci  }
5071cb0ef41Sopenharmony_ci
5081cb0ef41Sopenharmony_ci  for (; p != end; ++p) {
5091cb0ef41Sopenharmony_ci    switch (*p) {
5101cb0ef41Sopenharmony_ci    case ':':
5111cb0ef41Sopenharmony_ci      if (dest) {
5121cb0ef41Sopenharmony_ci        dest->type = NGHTTP3_SF_VALUE_TYPE_BYTESEQ;
5131cb0ef41Sopenharmony_ci        dest->s.base = begin + 1;
5141cb0ef41Sopenharmony_ci        dest->s.len = (size_t)(p - dest->s.base);
5151cb0ef41Sopenharmony_ci      }
5161cb0ef41Sopenharmony_ci
5171cb0ef41Sopenharmony_ci      ++p;
5181cb0ef41Sopenharmony_ci
5191cb0ef41Sopenharmony_ci      return p - begin;
5201cb0ef41Sopenharmony_ci    default:
5211cb0ef41Sopenharmony_ci      if (!SF_BYTESEQ_CHARS[*p]) {
5221cb0ef41Sopenharmony_ci        return -1;
5231cb0ef41Sopenharmony_ci      }
5241cb0ef41Sopenharmony_ci    }
5251cb0ef41Sopenharmony_ci  }
5261cb0ef41Sopenharmony_ci
5271cb0ef41Sopenharmony_ci  return -1;
5281cb0ef41Sopenharmony_ci}
5291cb0ef41Sopenharmony_ci
5301cb0ef41Sopenharmony_cistatic nghttp3_ssize sf_parse_boolean(nghttp3_sf_value *dest,
5311cb0ef41Sopenharmony_ci                                      const uint8_t *begin,
5321cb0ef41Sopenharmony_ci                                      const uint8_t *end) {
5331cb0ef41Sopenharmony_ci  const uint8_t *p = begin;
5341cb0ef41Sopenharmony_ci  int b;
5351cb0ef41Sopenharmony_ci
5361cb0ef41Sopenharmony_ci  if (*p++ != '?') {
5371cb0ef41Sopenharmony_ci    return -1;
5381cb0ef41Sopenharmony_ci  }
5391cb0ef41Sopenharmony_ci
5401cb0ef41Sopenharmony_ci  if (p == end) {
5411cb0ef41Sopenharmony_ci    return -1;
5421cb0ef41Sopenharmony_ci  }
5431cb0ef41Sopenharmony_ci
5441cb0ef41Sopenharmony_ci  switch (*p++) {
5451cb0ef41Sopenharmony_ci  case '0':
5461cb0ef41Sopenharmony_ci    b = 0;
5471cb0ef41Sopenharmony_ci    break;
5481cb0ef41Sopenharmony_ci  case '1':
5491cb0ef41Sopenharmony_ci    b = 1;
5501cb0ef41Sopenharmony_ci    break;
5511cb0ef41Sopenharmony_ci  default:
5521cb0ef41Sopenharmony_ci    return -1;
5531cb0ef41Sopenharmony_ci  }
5541cb0ef41Sopenharmony_ci
5551cb0ef41Sopenharmony_ci  if (dest) {
5561cb0ef41Sopenharmony_ci    dest->type = NGHTTP3_SF_VALUE_TYPE_BOOLEAN;
5571cb0ef41Sopenharmony_ci    dest->b = b;
5581cb0ef41Sopenharmony_ci  }
5591cb0ef41Sopenharmony_ci
5601cb0ef41Sopenharmony_ci  return p - begin;
5611cb0ef41Sopenharmony_ci}
5621cb0ef41Sopenharmony_ci
5631cb0ef41Sopenharmony_cistatic nghttp3_ssize sf_parse_bare_item(nghttp3_sf_value *dest,
5641cb0ef41Sopenharmony_ci                                        const uint8_t *begin,
5651cb0ef41Sopenharmony_ci                                        const uint8_t *end) {
5661cb0ef41Sopenharmony_ci  switch (*begin) {
5671cb0ef41Sopenharmony_ci  case '-':
5681cb0ef41Sopenharmony_ci  case '0':
5691cb0ef41Sopenharmony_ci  case '1':
5701cb0ef41Sopenharmony_ci  case '2':
5711cb0ef41Sopenharmony_ci  case '3':
5721cb0ef41Sopenharmony_ci  case '4':
5731cb0ef41Sopenharmony_ci  case '5':
5741cb0ef41Sopenharmony_ci  case '6':
5751cb0ef41Sopenharmony_ci  case '7':
5761cb0ef41Sopenharmony_ci  case '8':
5771cb0ef41Sopenharmony_ci  case '9':
5781cb0ef41Sopenharmony_ci    return sf_parse_integer_or_decimal(dest, begin, end);
5791cb0ef41Sopenharmony_ci  case '"':
5801cb0ef41Sopenharmony_ci    return sf_parse_string(dest, begin, end);
5811cb0ef41Sopenharmony_ci  case '*':
5821cb0ef41Sopenharmony_ci    return sf_parse_token(dest, begin, end);
5831cb0ef41Sopenharmony_ci  case ':':
5841cb0ef41Sopenharmony_ci    return sf_parse_byteseq(dest, begin, end);
5851cb0ef41Sopenharmony_ci  case '?':
5861cb0ef41Sopenharmony_ci    return sf_parse_boolean(dest, begin, end);
5871cb0ef41Sopenharmony_ci  default:
5881cb0ef41Sopenharmony_ci    if (('A' <= *begin && *begin <= 'Z') || ('a' <= *begin && *begin <= 'z')) {
5891cb0ef41Sopenharmony_ci      return sf_parse_token(dest, begin, end);
5901cb0ef41Sopenharmony_ci    }
5911cb0ef41Sopenharmony_ci    return -1;
5921cb0ef41Sopenharmony_ci  }
5931cb0ef41Sopenharmony_ci}
5941cb0ef41Sopenharmony_ci
5951cb0ef41Sopenharmony_ci#define sf_discard_sp_end_err(BEGIN, END, ERR)                                 \
5961cb0ef41Sopenharmony_ci  for (;; ++(BEGIN)) {                                                         \
5971cb0ef41Sopenharmony_ci    if ((BEGIN) == (END)) {                                                    \
5981cb0ef41Sopenharmony_ci      return (ERR);                                                            \
5991cb0ef41Sopenharmony_ci    }                                                                          \
6001cb0ef41Sopenharmony_ci    if (*(BEGIN) != ' ') {                                                     \
6011cb0ef41Sopenharmony_ci      break;                                                                   \
6021cb0ef41Sopenharmony_ci    }                                                                          \
6031cb0ef41Sopenharmony_ci  }
6041cb0ef41Sopenharmony_ci
6051cb0ef41Sopenharmony_cistatic nghttp3_ssize sf_parse_params(const uint8_t *begin, const uint8_t *end) {
6061cb0ef41Sopenharmony_ci  const uint8_t *p = begin;
6071cb0ef41Sopenharmony_ci  nghttp3_ssize slen;
6081cb0ef41Sopenharmony_ci
6091cb0ef41Sopenharmony_ci  for (; p != end && *p == ';';) {
6101cb0ef41Sopenharmony_ci    ++p;
6111cb0ef41Sopenharmony_ci
6121cb0ef41Sopenharmony_ci    sf_discard_sp_end_err(p, end, -1);
6131cb0ef41Sopenharmony_ci
6141cb0ef41Sopenharmony_ci    slen = sf_parse_key(p, end);
6151cb0ef41Sopenharmony_ci    if (slen < 0) {
6161cb0ef41Sopenharmony_ci      return -1;
6171cb0ef41Sopenharmony_ci    }
6181cb0ef41Sopenharmony_ci
6191cb0ef41Sopenharmony_ci    p += slen;
6201cb0ef41Sopenharmony_ci
6211cb0ef41Sopenharmony_ci    if (p == end || *p != '=') {
6221cb0ef41Sopenharmony_ci      /* Boolean true */
6231cb0ef41Sopenharmony_ci    } else if (++p == end) {
6241cb0ef41Sopenharmony_ci      return -1;
6251cb0ef41Sopenharmony_ci    } else {
6261cb0ef41Sopenharmony_ci      slen = sf_parse_bare_item(NULL, p, end);
6271cb0ef41Sopenharmony_ci      if (slen < 0) {
6281cb0ef41Sopenharmony_ci        return -1;
6291cb0ef41Sopenharmony_ci      }
6301cb0ef41Sopenharmony_ci
6311cb0ef41Sopenharmony_ci      p += slen;
6321cb0ef41Sopenharmony_ci    }
6331cb0ef41Sopenharmony_ci  }
6341cb0ef41Sopenharmony_ci
6351cb0ef41Sopenharmony_ci  return p - begin;
6361cb0ef41Sopenharmony_ci}
6371cb0ef41Sopenharmony_ci
6381cb0ef41Sopenharmony_cistatic nghttp3_ssize sf_parse_item(nghttp3_sf_value *dest, const uint8_t *begin,
6391cb0ef41Sopenharmony_ci                                   const uint8_t *end) {
6401cb0ef41Sopenharmony_ci  const uint8_t *p = begin;
6411cb0ef41Sopenharmony_ci  nghttp3_ssize slen;
6421cb0ef41Sopenharmony_ci
6431cb0ef41Sopenharmony_ci  slen = sf_parse_bare_item(dest, p, end);
6441cb0ef41Sopenharmony_ci  if (slen < 0) {
6451cb0ef41Sopenharmony_ci    return -1;
6461cb0ef41Sopenharmony_ci  }
6471cb0ef41Sopenharmony_ci
6481cb0ef41Sopenharmony_ci  p += slen;
6491cb0ef41Sopenharmony_ci
6501cb0ef41Sopenharmony_ci  slen = sf_parse_params(p, end);
6511cb0ef41Sopenharmony_ci  if (slen < 0) {
6521cb0ef41Sopenharmony_ci    return -1;
6531cb0ef41Sopenharmony_ci  }
6541cb0ef41Sopenharmony_ci
6551cb0ef41Sopenharmony_ci  p += slen;
6561cb0ef41Sopenharmony_ci
6571cb0ef41Sopenharmony_ci  return p - begin;
6581cb0ef41Sopenharmony_ci}
6591cb0ef41Sopenharmony_ci
6601cb0ef41Sopenharmony_cinghttp3_ssize nghttp3_sf_parse_item(nghttp3_sf_value *dest,
6611cb0ef41Sopenharmony_ci                                    const uint8_t *begin, const uint8_t *end) {
6621cb0ef41Sopenharmony_ci  return sf_parse_item(dest, begin, end);
6631cb0ef41Sopenharmony_ci}
6641cb0ef41Sopenharmony_ci
6651cb0ef41Sopenharmony_cistatic nghttp3_ssize sf_parse_inner_list(nghttp3_sf_value *dest,
6661cb0ef41Sopenharmony_ci                                         const uint8_t *begin,
6671cb0ef41Sopenharmony_ci                                         const uint8_t *end) {
6681cb0ef41Sopenharmony_ci  const uint8_t *p = begin;
6691cb0ef41Sopenharmony_ci  nghttp3_ssize slen;
6701cb0ef41Sopenharmony_ci
6711cb0ef41Sopenharmony_ci  if (*p++ != '(') {
6721cb0ef41Sopenharmony_ci    return -1;
6731cb0ef41Sopenharmony_ci  }
6741cb0ef41Sopenharmony_ci
6751cb0ef41Sopenharmony_ci  for (;;) {
6761cb0ef41Sopenharmony_ci    sf_discard_sp_end_err(p, end, -1);
6771cb0ef41Sopenharmony_ci
6781cb0ef41Sopenharmony_ci    if (*p == ')') {
6791cb0ef41Sopenharmony_ci      ++p;
6801cb0ef41Sopenharmony_ci
6811cb0ef41Sopenharmony_ci      slen = sf_parse_params(p, end);
6821cb0ef41Sopenharmony_ci      if (slen < 0) {
6831cb0ef41Sopenharmony_ci        return -1;
6841cb0ef41Sopenharmony_ci      }
6851cb0ef41Sopenharmony_ci
6861cb0ef41Sopenharmony_ci      p += slen;
6871cb0ef41Sopenharmony_ci
6881cb0ef41Sopenharmony_ci      if (dest) {
6891cb0ef41Sopenharmony_ci        dest->type = NGHTTP3_SF_VALUE_TYPE_INNER_LIST;
6901cb0ef41Sopenharmony_ci      }
6911cb0ef41Sopenharmony_ci
6921cb0ef41Sopenharmony_ci      return p - begin;
6931cb0ef41Sopenharmony_ci    }
6941cb0ef41Sopenharmony_ci
6951cb0ef41Sopenharmony_ci    slen = sf_parse_item(NULL, p, end);
6961cb0ef41Sopenharmony_ci    if (slen < 0) {
6971cb0ef41Sopenharmony_ci      return -1;
6981cb0ef41Sopenharmony_ci    }
6991cb0ef41Sopenharmony_ci
7001cb0ef41Sopenharmony_ci    p += slen;
7011cb0ef41Sopenharmony_ci
7021cb0ef41Sopenharmony_ci    if (p == end || (*p != ' ' && *p != ')')) {
7031cb0ef41Sopenharmony_ci      return -1;
7041cb0ef41Sopenharmony_ci    }
7051cb0ef41Sopenharmony_ci  }
7061cb0ef41Sopenharmony_ci}
7071cb0ef41Sopenharmony_ci
7081cb0ef41Sopenharmony_cinghttp3_ssize nghttp3_sf_parse_inner_list(nghttp3_sf_value *dest,
7091cb0ef41Sopenharmony_ci                                          const uint8_t *begin,
7101cb0ef41Sopenharmony_ci                                          const uint8_t *end) {
7111cb0ef41Sopenharmony_ci  return sf_parse_inner_list(dest, begin, end);
7121cb0ef41Sopenharmony_ci}
7131cb0ef41Sopenharmony_ci
7141cb0ef41Sopenharmony_cistatic nghttp3_ssize sf_parse_item_or_inner_list(nghttp3_sf_value *dest,
7151cb0ef41Sopenharmony_ci                                                 const uint8_t *begin,
7161cb0ef41Sopenharmony_ci                                                 const uint8_t *end) {
7171cb0ef41Sopenharmony_ci  if (*begin == '(') {
7181cb0ef41Sopenharmony_ci    return sf_parse_inner_list(dest, begin, end);
7191cb0ef41Sopenharmony_ci  }
7201cb0ef41Sopenharmony_ci
7211cb0ef41Sopenharmony_ci  return sf_parse_item(dest, begin, end);
7221cb0ef41Sopenharmony_ci}
7231cb0ef41Sopenharmony_ci
7241cb0ef41Sopenharmony_ci#define sf_discard_ows(BEGIN, END)                                             \
7251cb0ef41Sopenharmony_ci  for (;; ++(BEGIN)) {                                                         \
7261cb0ef41Sopenharmony_ci    if ((BEGIN) == (END)) {                                                    \
7271cb0ef41Sopenharmony_ci      goto fin;                                                                \
7281cb0ef41Sopenharmony_ci    }                                                                          \
7291cb0ef41Sopenharmony_ci    if (*(BEGIN) != ' ' && *(BEGIN) != '\t') {                                 \
7301cb0ef41Sopenharmony_ci      break;                                                                   \
7311cb0ef41Sopenharmony_ci    }                                                                          \
7321cb0ef41Sopenharmony_ci  }
7331cb0ef41Sopenharmony_ci
7341cb0ef41Sopenharmony_ci#define sf_discard_ows_end_err(BEGIN, END, ERR)                                \
7351cb0ef41Sopenharmony_ci  for (;; ++(BEGIN)) {                                                         \
7361cb0ef41Sopenharmony_ci    if ((BEGIN) == (END)) {                                                    \
7371cb0ef41Sopenharmony_ci      return (ERR);                                                            \
7381cb0ef41Sopenharmony_ci    }                                                                          \
7391cb0ef41Sopenharmony_ci    if (*(BEGIN) != ' ' && *(BEGIN) != '\t') {                                 \
7401cb0ef41Sopenharmony_ci      break;                                                                   \
7411cb0ef41Sopenharmony_ci    }                                                                          \
7421cb0ef41Sopenharmony_ci  }
7431cb0ef41Sopenharmony_ci
7441cb0ef41Sopenharmony_ciint nghttp3_http_parse_priority(nghttp3_pri *dest, const uint8_t *value,
7451cb0ef41Sopenharmony_ci                                size_t valuelen) {
7461cb0ef41Sopenharmony_ci  const uint8_t *p = value, *end = value + valuelen;
7471cb0ef41Sopenharmony_ci  nghttp3_ssize slen;
7481cb0ef41Sopenharmony_ci  nghttp3_sf_value val;
7491cb0ef41Sopenharmony_ci  nghttp3_pri pri = *dest;
7501cb0ef41Sopenharmony_ci  const uint8_t *key;
7511cb0ef41Sopenharmony_ci  size_t keylen;
7521cb0ef41Sopenharmony_ci
7531cb0ef41Sopenharmony_ci  for (; p != end && *p == ' '; ++p)
7541cb0ef41Sopenharmony_ci    ;
7551cb0ef41Sopenharmony_ci
7561cb0ef41Sopenharmony_ci  for (; p != end;) {
7571cb0ef41Sopenharmony_ci    slen = sf_parse_key(p, end);
7581cb0ef41Sopenharmony_ci    if (slen < 0) {
7591cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_INVALID_ARGUMENT;
7601cb0ef41Sopenharmony_ci    }
7611cb0ef41Sopenharmony_ci
7621cb0ef41Sopenharmony_ci    key = p;
7631cb0ef41Sopenharmony_ci    keylen = (size_t)slen;
7641cb0ef41Sopenharmony_ci
7651cb0ef41Sopenharmony_ci    p += slen;
7661cb0ef41Sopenharmony_ci
7671cb0ef41Sopenharmony_ci    if (p == end || *p != '=') {
7681cb0ef41Sopenharmony_ci      /* Boolean true */
7691cb0ef41Sopenharmony_ci      val.type = NGHTTP3_SF_VALUE_TYPE_BOOLEAN;
7701cb0ef41Sopenharmony_ci      val.b = 1;
7711cb0ef41Sopenharmony_ci
7721cb0ef41Sopenharmony_ci      slen = sf_parse_params(p, end);
7731cb0ef41Sopenharmony_ci      if (slen < 0) {
7741cb0ef41Sopenharmony_ci        return NGHTTP3_ERR_INVALID_ARGUMENT;
7751cb0ef41Sopenharmony_ci      }
7761cb0ef41Sopenharmony_ci    } else if (++p == end) {
7771cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_INVALID_ARGUMENT;
7781cb0ef41Sopenharmony_ci    } else {
7791cb0ef41Sopenharmony_ci      slen = sf_parse_item_or_inner_list(&val, p, end);
7801cb0ef41Sopenharmony_ci      if (slen < 0) {
7811cb0ef41Sopenharmony_ci        return NGHTTP3_ERR_INVALID_ARGUMENT;
7821cb0ef41Sopenharmony_ci      }
7831cb0ef41Sopenharmony_ci    }
7841cb0ef41Sopenharmony_ci
7851cb0ef41Sopenharmony_ci    p += slen;
7861cb0ef41Sopenharmony_ci
7871cb0ef41Sopenharmony_ci    if (keylen == 1) {
7881cb0ef41Sopenharmony_ci      switch (key[0]) {
7891cb0ef41Sopenharmony_ci      case 'i':
7901cb0ef41Sopenharmony_ci        if (val.type != NGHTTP3_SF_VALUE_TYPE_BOOLEAN) {
7911cb0ef41Sopenharmony_ci          return NGHTTP3_ERR_INVALID_ARGUMENT;
7921cb0ef41Sopenharmony_ci        }
7931cb0ef41Sopenharmony_ci
7941cb0ef41Sopenharmony_ci        pri.inc = val.b;
7951cb0ef41Sopenharmony_ci
7961cb0ef41Sopenharmony_ci        break;
7971cb0ef41Sopenharmony_ci      case 'u':
7981cb0ef41Sopenharmony_ci        if (val.type != NGHTTP3_SF_VALUE_TYPE_INTEGER ||
7991cb0ef41Sopenharmony_ci            val.i < NGHTTP3_URGENCY_HIGH || NGHTTP3_URGENCY_LOW < val.i) {
8001cb0ef41Sopenharmony_ci          return NGHTTP3_ERR_INVALID_ARGUMENT;
8011cb0ef41Sopenharmony_ci        }
8021cb0ef41Sopenharmony_ci
8031cb0ef41Sopenharmony_ci        pri.urgency = (uint32_t)val.i;
8041cb0ef41Sopenharmony_ci
8051cb0ef41Sopenharmony_ci        break;
8061cb0ef41Sopenharmony_ci      }
8071cb0ef41Sopenharmony_ci    }
8081cb0ef41Sopenharmony_ci
8091cb0ef41Sopenharmony_ci    sf_discard_ows(p, end);
8101cb0ef41Sopenharmony_ci
8111cb0ef41Sopenharmony_ci    if (*p++ != ',') {
8121cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_INVALID_ARGUMENT;
8131cb0ef41Sopenharmony_ci    }
8141cb0ef41Sopenharmony_ci
8151cb0ef41Sopenharmony_ci    sf_discard_ows_end_err(p, end, NGHTTP3_ERR_INVALID_ARGUMENT);
8161cb0ef41Sopenharmony_ci  }
8171cb0ef41Sopenharmony_ci
8181cb0ef41Sopenharmony_cifin:
8191cb0ef41Sopenharmony_ci  *dest = pri;
8201cb0ef41Sopenharmony_ci
8211cb0ef41Sopenharmony_ci  return 0;
8221cb0ef41Sopenharmony_ci}
8231cb0ef41Sopenharmony_ci
8241cb0ef41Sopenharmony_cistatic int http_request_on_header(nghttp3_http_state *http,
8251cb0ef41Sopenharmony_ci                                  nghttp3_qpack_nv *nv, int trailers,
8261cb0ef41Sopenharmony_ci                                  int connect_protocol) {
8271cb0ef41Sopenharmony_ci  nghttp3_pri pri;
8281cb0ef41Sopenharmony_ci
8291cb0ef41Sopenharmony_ci  if (nv->name->base[0] == ':') {
8301cb0ef41Sopenharmony_ci    if (trailers ||
8311cb0ef41Sopenharmony_ci        (http->flags & NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED)) {
8321cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
8331cb0ef41Sopenharmony_ci    }
8341cb0ef41Sopenharmony_ci  }
8351cb0ef41Sopenharmony_ci
8361cb0ef41Sopenharmony_ci  switch (nv->token) {
8371cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN__AUTHORITY:
8381cb0ef41Sopenharmony_ci    if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG__AUTHORITY)) {
8391cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
8401cb0ef41Sopenharmony_ci    }
8411cb0ef41Sopenharmony_ci    break;
8421cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN__METHOD:
8431cb0ef41Sopenharmony_ci    if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG__METHOD)) {
8441cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
8451cb0ef41Sopenharmony_ci    }
8461cb0ef41Sopenharmony_ci    switch (nv->value->len) {
8471cb0ef41Sopenharmony_ci    case 4:
8481cb0ef41Sopenharmony_ci      if (lstreq("HEAD", nv->value->base, nv->value->len)) {
8491cb0ef41Sopenharmony_ci        http->flags |= NGHTTP3_HTTP_FLAG_METH_HEAD;
8501cb0ef41Sopenharmony_ci      }
8511cb0ef41Sopenharmony_ci      break;
8521cb0ef41Sopenharmony_ci    case 7:
8531cb0ef41Sopenharmony_ci      switch (nv->value->base[6]) {
8541cb0ef41Sopenharmony_ci      case 'T':
8551cb0ef41Sopenharmony_ci        if (lstreq("CONNECT", nv->value->base, nv->value->len)) {
8561cb0ef41Sopenharmony_ci          http->flags |= NGHTTP3_HTTP_FLAG_METH_CONNECT;
8571cb0ef41Sopenharmony_ci        }
8581cb0ef41Sopenharmony_ci        break;
8591cb0ef41Sopenharmony_ci      case 'S':
8601cb0ef41Sopenharmony_ci        if (lstreq("OPTIONS", nv->value->base, nv->value->len)) {
8611cb0ef41Sopenharmony_ci          http->flags |= NGHTTP3_HTTP_FLAG_METH_OPTIONS;
8621cb0ef41Sopenharmony_ci        }
8631cb0ef41Sopenharmony_ci        break;
8641cb0ef41Sopenharmony_ci      }
8651cb0ef41Sopenharmony_ci      break;
8661cb0ef41Sopenharmony_ci    }
8671cb0ef41Sopenharmony_ci    break;
8681cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN__PATH:
8691cb0ef41Sopenharmony_ci    if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG__PATH)) {
8701cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
8711cb0ef41Sopenharmony_ci    }
8721cb0ef41Sopenharmony_ci    if (nv->value->base[0] == '/') {
8731cb0ef41Sopenharmony_ci      http->flags |= NGHTTP3_HTTP_FLAG_PATH_REGULAR;
8741cb0ef41Sopenharmony_ci    } else if (nv->value->len == 1 && nv->value->base[0] == '*') {
8751cb0ef41Sopenharmony_ci      http->flags |= NGHTTP3_HTTP_FLAG_PATH_ASTERISK;
8761cb0ef41Sopenharmony_ci    }
8771cb0ef41Sopenharmony_ci    break;
8781cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN__SCHEME:
8791cb0ef41Sopenharmony_ci    if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG__SCHEME)) {
8801cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
8811cb0ef41Sopenharmony_ci    }
8821cb0ef41Sopenharmony_ci    /* scheme is case-insensitive:
8831cb0ef41Sopenharmony_ci       https://datatracker.ietf.org/doc/html/rfc3986#section-3.1 */
8841cb0ef41Sopenharmony_ci    if (lstrieq("http", nv->value->base, nv->value->len) ||
8851cb0ef41Sopenharmony_ci        lstrieq("https", nv->value->base, nv->value->len)) {
8861cb0ef41Sopenharmony_ci      http->flags |= NGHTTP3_HTTP_FLAG_SCHEME_HTTP;
8871cb0ef41Sopenharmony_ci    }
8881cb0ef41Sopenharmony_ci    break;
8891cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN__PROTOCOL:
8901cb0ef41Sopenharmony_ci    if (!connect_protocol) {
8911cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
8921cb0ef41Sopenharmony_ci    }
8931cb0ef41Sopenharmony_ci
8941cb0ef41Sopenharmony_ci    if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG__PROTOCOL)) {
8951cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
8961cb0ef41Sopenharmony_ci    }
8971cb0ef41Sopenharmony_ci    break;
8981cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_HOST:
8991cb0ef41Sopenharmony_ci    if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG_HOST)) {
9001cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
9011cb0ef41Sopenharmony_ci    }
9021cb0ef41Sopenharmony_ci    break;
9031cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_CONTENT_LENGTH: {
9041cb0ef41Sopenharmony_ci    /* https://tools.ietf.org/html/rfc7230#section-4.1.2: A sender
9051cb0ef41Sopenharmony_ci       MUST NOT generate a trailer that contains a field necessary for
9061cb0ef41Sopenharmony_ci       message framing (e.g., Transfer-Encoding and Content-Length),
9071cb0ef41Sopenharmony_ci       ... */
9081cb0ef41Sopenharmony_ci    if (trailers) {
9091cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_REMOVE_HTTP_HEADER;
9101cb0ef41Sopenharmony_ci    }
9111cb0ef41Sopenharmony_ci    if (http->content_length != -1) {
9121cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
9131cb0ef41Sopenharmony_ci    }
9141cb0ef41Sopenharmony_ci    http->content_length = parse_uint(nv->value->base, nv->value->len);
9151cb0ef41Sopenharmony_ci    if (http->content_length == -1) {
9161cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
9171cb0ef41Sopenharmony_ci    }
9181cb0ef41Sopenharmony_ci    break;
9191cb0ef41Sopenharmony_ci  }
9201cb0ef41Sopenharmony_ci  /* disallowed header fields */
9211cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_CONNECTION:
9221cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_KEEP_ALIVE:
9231cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_PROXY_CONNECTION:
9241cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_TRANSFER_ENCODING:
9251cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_UPGRADE:
9261cb0ef41Sopenharmony_ci    return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
9271cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_TE:
9281cb0ef41Sopenharmony_ci    if (!lstrieq("trailers", nv->value->base, nv->value->len)) {
9291cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
9301cb0ef41Sopenharmony_ci    }
9311cb0ef41Sopenharmony_ci    break;
9321cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_PRIORITY:
9331cb0ef41Sopenharmony_ci    if (!trailers && !(http->flags & NGHTTP3_HTTP_FLAG_BAD_PRIORITY)) {
9341cb0ef41Sopenharmony_ci      pri.urgency = nghttp3_pri_uint8_urgency(http->pri);
9351cb0ef41Sopenharmony_ci      pri.inc = nghttp3_pri_uint8_inc(http->pri);
9361cb0ef41Sopenharmony_ci      if (nghttp3_http_parse_priority(&pri, nv->value->base, nv->value->len) ==
9371cb0ef41Sopenharmony_ci          0) {
9381cb0ef41Sopenharmony_ci        http->pri = nghttp3_pri_to_uint8(&pri);
9391cb0ef41Sopenharmony_ci        http->flags |= NGHTTP3_HTTP_FLAG_PRIORITY;
9401cb0ef41Sopenharmony_ci      } else {
9411cb0ef41Sopenharmony_ci        http->flags &= ~NGHTTP3_HTTP_FLAG_PRIORITY;
9421cb0ef41Sopenharmony_ci        http->flags |= NGHTTP3_HTTP_FLAG_BAD_PRIORITY;
9431cb0ef41Sopenharmony_ci      }
9441cb0ef41Sopenharmony_ci    }
9451cb0ef41Sopenharmony_ci    break;
9461cb0ef41Sopenharmony_ci  default:
9471cb0ef41Sopenharmony_ci    if (nv->name->base[0] == ':') {
9481cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
9491cb0ef41Sopenharmony_ci    }
9501cb0ef41Sopenharmony_ci  }
9511cb0ef41Sopenharmony_ci
9521cb0ef41Sopenharmony_ci  return 0;
9531cb0ef41Sopenharmony_ci}
9541cb0ef41Sopenharmony_ci
9551cb0ef41Sopenharmony_cistatic int http_response_on_header(nghttp3_http_state *http,
9561cb0ef41Sopenharmony_ci                                   nghttp3_qpack_nv *nv, int trailers) {
9571cb0ef41Sopenharmony_ci  if (nv->name->base[0] == ':') {
9581cb0ef41Sopenharmony_ci    if (trailers ||
9591cb0ef41Sopenharmony_ci        (http->flags & NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED)) {
9601cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
9611cb0ef41Sopenharmony_ci    }
9621cb0ef41Sopenharmony_ci  }
9631cb0ef41Sopenharmony_ci
9641cb0ef41Sopenharmony_ci  switch (nv->token) {
9651cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN__STATUS: {
9661cb0ef41Sopenharmony_ci    if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG__STATUS)) {
9671cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
9681cb0ef41Sopenharmony_ci    }
9691cb0ef41Sopenharmony_ci    if (nv->value->len != 3) {
9701cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
9711cb0ef41Sopenharmony_ci    }
9721cb0ef41Sopenharmony_ci    http->status_code = (int16_t)parse_uint(nv->value->base, nv->value->len);
9731cb0ef41Sopenharmony_ci    if (http->status_code < 100 || http->status_code == 101) {
9741cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
9751cb0ef41Sopenharmony_ci    }
9761cb0ef41Sopenharmony_ci    break;
9771cb0ef41Sopenharmony_ci  }
9781cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_CONTENT_LENGTH: {
9791cb0ef41Sopenharmony_ci    /* https://tools.ietf.org/html/rfc7230#section-4.1.2: A sender
9801cb0ef41Sopenharmony_ci       MUST NOT generate a trailer that contains a field necessary for
9811cb0ef41Sopenharmony_ci       message framing (e.g., Transfer-Encoding and Content-Length),
9821cb0ef41Sopenharmony_ci       ... */
9831cb0ef41Sopenharmony_ci    if (trailers) {
9841cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_REMOVE_HTTP_HEADER;
9851cb0ef41Sopenharmony_ci    }
9861cb0ef41Sopenharmony_ci    if (http->status_code == 204) {
9871cb0ef41Sopenharmony_ci      /* content-length header field in 204 response is prohibited by
9881cb0ef41Sopenharmony_ci         RFC 7230.  But some widely used servers send content-length:
9891cb0ef41Sopenharmony_ci         0.  Until they get fixed, we ignore it. */
9901cb0ef41Sopenharmony_ci      if (http->content_length != -1) {
9911cb0ef41Sopenharmony_ci        /* Found multiple content-length field */
9921cb0ef41Sopenharmony_ci        return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
9931cb0ef41Sopenharmony_ci      }
9941cb0ef41Sopenharmony_ci      if (!lstrieq("0", nv->value->base, nv->value->len)) {
9951cb0ef41Sopenharmony_ci        return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
9961cb0ef41Sopenharmony_ci      }
9971cb0ef41Sopenharmony_ci      http->content_length = 0;
9981cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_REMOVE_HTTP_HEADER;
9991cb0ef41Sopenharmony_ci    }
10001cb0ef41Sopenharmony_ci    if (http->status_code / 100 == 1) {
10011cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_REMOVE_HTTP_HEADER;
10021cb0ef41Sopenharmony_ci    }
10031cb0ef41Sopenharmony_ci    /* https://tools.ietf.org/html/rfc7230#section-3.3.3 */
10041cb0ef41Sopenharmony_ci    if (http->status_code / 100 == 2 &&
10051cb0ef41Sopenharmony_ci        (http->flags & NGHTTP3_HTTP_FLAG_METH_CONNECT)) {
10061cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_REMOVE_HTTP_HEADER;
10071cb0ef41Sopenharmony_ci    }
10081cb0ef41Sopenharmony_ci    if (http->content_length != -1) {
10091cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
10101cb0ef41Sopenharmony_ci    }
10111cb0ef41Sopenharmony_ci    http->content_length = parse_uint(nv->value->base, nv->value->len);
10121cb0ef41Sopenharmony_ci    if (http->content_length == -1) {
10131cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
10141cb0ef41Sopenharmony_ci    }
10151cb0ef41Sopenharmony_ci    break;
10161cb0ef41Sopenharmony_ci  }
10171cb0ef41Sopenharmony_ci  /* disallowed header fields */
10181cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_CONNECTION:
10191cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_KEEP_ALIVE:
10201cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_PROXY_CONNECTION:
10211cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_TRANSFER_ENCODING:
10221cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_UPGRADE:
10231cb0ef41Sopenharmony_ci    return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
10241cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_TE:
10251cb0ef41Sopenharmony_ci    if (!lstrieq("trailers", nv->value->base, nv->value->len)) {
10261cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
10271cb0ef41Sopenharmony_ci    }
10281cb0ef41Sopenharmony_ci    break;
10291cb0ef41Sopenharmony_ci  default:
10301cb0ef41Sopenharmony_ci    if (nv->name->base[0] == ':') {
10311cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
10321cb0ef41Sopenharmony_ci    }
10331cb0ef41Sopenharmony_ci  }
10341cb0ef41Sopenharmony_ci
10351cb0ef41Sopenharmony_ci  return 0;
10361cb0ef41Sopenharmony_ci}
10371cb0ef41Sopenharmony_ci
10381cb0ef41Sopenharmony_ci/* Generated by genauthroitychartbl.py */
10391cb0ef41Sopenharmony_cistatic char VALID_AUTHORITY_CHARS[] = {
10401cb0ef41Sopenharmony_ci    0 /* NUL  */, 0 /* SOH  */, 0 /* STX  */, 0 /* ETX  */,
10411cb0ef41Sopenharmony_ci    0 /* EOT  */, 0 /* ENQ  */, 0 /* ACK  */, 0 /* BEL  */,
10421cb0ef41Sopenharmony_ci    0 /* BS   */, 0 /* HT   */, 0 /* LF   */, 0 /* VT   */,
10431cb0ef41Sopenharmony_ci    0 /* FF   */, 0 /* CR   */, 0 /* SO   */, 0 /* SI   */,
10441cb0ef41Sopenharmony_ci    0 /* DLE  */, 0 /* DC1  */, 0 /* DC2  */, 0 /* DC3  */,
10451cb0ef41Sopenharmony_ci    0 /* DC4  */, 0 /* NAK  */, 0 /* SYN  */, 0 /* ETB  */,
10461cb0ef41Sopenharmony_ci    0 /* CAN  */, 0 /* EM   */, 0 /* SUB  */, 0 /* ESC  */,
10471cb0ef41Sopenharmony_ci    0 /* FS   */, 0 /* GS   */, 0 /* RS   */, 0 /* US   */,
10481cb0ef41Sopenharmony_ci    0 /* SPC  */, 1 /* !    */, 0 /* "    */, 0 /* #    */,
10491cb0ef41Sopenharmony_ci    1 /* $    */, 1 /* %    */, 1 /* &    */, 1 /* '    */,
10501cb0ef41Sopenharmony_ci    1 /* (    */, 1 /* )    */, 1 /* *    */, 1 /* +    */,
10511cb0ef41Sopenharmony_ci    1 /* ,    */, 1 /* -    */, 1 /* .    */, 0 /* /    */,
10521cb0ef41Sopenharmony_ci    1 /* 0    */, 1 /* 1    */, 1 /* 2    */, 1 /* 3    */,
10531cb0ef41Sopenharmony_ci    1 /* 4    */, 1 /* 5    */, 1 /* 6    */, 1 /* 7    */,
10541cb0ef41Sopenharmony_ci    1 /* 8    */, 1 /* 9    */, 1 /* :    */, 1 /* ;    */,
10551cb0ef41Sopenharmony_ci    0 /* <    */, 1 /* =    */, 0 /* >    */, 0 /* ?    */,
10561cb0ef41Sopenharmony_ci    1 /* @    */, 1 /* A    */, 1 /* B    */, 1 /* C    */,
10571cb0ef41Sopenharmony_ci    1 /* D    */, 1 /* E    */, 1 /* F    */, 1 /* G    */,
10581cb0ef41Sopenharmony_ci    1 /* H    */, 1 /* I    */, 1 /* J    */, 1 /* K    */,
10591cb0ef41Sopenharmony_ci    1 /* L    */, 1 /* M    */, 1 /* N    */, 1 /* O    */,
10601cb0ef41Sopenharmony_ci    1 /* P    */, 1 /* Q    */, 1 /* R    */, 1 /* S    */,
10611cb0ef41Sopenharmony_ci    1 /* T    */, 1 /* U    */, 1 /* V    */, 1 /* W    */,
10621cb0ef41Sopenharmony_ci    1 /* X    */, 1 /* Y    */, 1 /* Z    */, 1 /* [    */,
10631cb0ef41Sopenharmony_ci    0 /* \    */, 1 /* ]    */, 0 /* ^    */, 1 /* _    */,
10641cb0ef41Sopenharmony_ci    0 /* `    */, 1 /* a    */, 1 /* b    */, 1 /* c    */,
10651cb0ef41Sopenharmony_ci    1 /* d    */, 1 /* e    */, 1 /* f    */, 1 /* g    */,
10661cb0ef41Sopenharmony_ci    1 /* h    */, 1 /* i    */, 1 /* j    */, 1 /* k    */,
10671cb0ef41Sopenharmony_ci    1 /* l    */, 1 /* m    */, 1 /* n    */, 1 /* o    */,
10681cb0ef41Sopenharmony_ci    1 /* p    */, 1 /* q    */, 1 /* r    */, 1 /* s    */,
10691cb0ef41Sopenharmony_ci    1 /* t    */, 1 /* u    */, 1 /* v    */, 1 /* w    */,
10701cb0ef41Sopenharmony_ci    1 /* x    */, 1 /* y    */, 1 /* z    */, 0 /* {    */,
10711cb0ef41Sopenharmony_ci    0 /* |    */, 0 /* }    */, 1 /* ~    */, 0 /* DEL  */,
10721cb0ef41Sopenharmony_ci    0 /* 0x80 */, 0 /* 0x81 */, 0 /* 0x82 */, 0 /* 0x83 */,
10731cb0ef41Sopenharmony_ci    0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */, 0 /* 0x87 */,
10741cb0ef41Sopenharmony_ci    0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */,
10751cb0ef41Sopenharmony_ci    0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */,
10761cb0ef41Sopenharmony_ci    0 /* 0x90 */, 0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */,
10771cb0ef41Sopenharmony_ci    0 /* 0x94 */, 0 /* 0x95 */, 0 /* 0x96 */, 0 /* 0x97 */,
10781cb0ef41Sopenharmony_ci    0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */, 0 /* 0x9b */,
10791cb0ef41Sopenharmony_ci    0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */,
10801cb0ef41Sopenharmony_ci    0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */,
10811cb0ef41Sopenharmony_ci    0 /* 0xa4 */, 0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */,
10821cb0ef41Sopenharmony_ci    0 /* 0xa8 */, 0 /* 0xa9 */, 0 /* 0xaa */, 0 /* 0xab */,
10831cb0ef41Sopenharmony_ci    0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */, 0 /* 0xaf */,
10841cb0ef41Sopenharmony_ci    0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */,
10851cb0ef41Sopenharmony_ci    0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */,
10861cb0ef41Sopenharmony_ci    0 /* 0xb8 */, 0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */,
10871cb0ef41Sopenharmony_ci    0 /* 0xbc */, 0 /* 0xbd */, 0 /* 0xbe */, 0 /* 0xbf */,
10881cb0ef41Sopenharmony_ci    0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */, 0 /* 0xc3 */,
10891cb0ef41Sopenharmony_ci    0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */,
10901cb0ef41Sopenharmony_ci    0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */,
10911cb0ef41Sopenharmony_ci    0 /* 0xcc */, 0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */,
10921cb0ef41Sopenharmony_ci    0 /* 0xd0 */, 0 /* 0xd1 */, 0 /* 0xd2 */, 0 /* 0xd3 */,
10931cb0ef41Sopenharmony_ci    0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */, 0 /* 0xd7 */,
10941cb0ef41Sopenharmony_ci    0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */,
10951cb0ef41Sopenharmony_ci    0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */,
10961cb0ef41Sopenharmony_ci    0 /* 0xe0 */, 0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */,
10971cb0ef41Sopenharmony_ci    0 /* 0xe4 */, 0 /* 0xe5 */, 0 /* 0xe6 */, 0 /* 0xe7 */,
10981cb0ef41Sopenharmony_ci    0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */, 0 /* 0xeb */,
10991cb0ef41Sopenharmony_ci    0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */,
11001cb0ef41Sopenharmony_ci    0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */,
11011cb0ef41Sopenharmony_ci    0 /* 0xf4 */, 0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */,
11021cb0ef41Sopenharmony_ci    0 /* 0xf8 */, 0 /* 0xf9 */, 0 /* 0xfa */, 0 /* 0xfb */,
11031cb0ef41Sopenharmony_ci    0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */, 0 /* 0xff */
11041cb0ef41Sopenharmony_ci};
11051cb0ef41Sopenharmony_ci
11061cb0ef41Sopenharmony_cistatic int check_authority(const uint8_t *value, size_t len) {
11071cb0ef41Sopenharmony_ci  const uint8_t *last;
11081cb0ef41Sopenharmony_ci  for (last = value + len; value != last; ++value) {
11091cb0ef41Sopenharmony_ci    if (!VALID_AUTHORITY_CHARS[*value]) {
11101cb0ef41Sopenharmony_ci      return 0;
11111cb0ef41Sopenharmony_ci    }
11121cb0ef41Sopenharmony_ci  }
11131cb0ef41Sopenharmony_ci  return 1;
11141cb0ef41Sopenharmony_ci}
11151cb0ef41Sopenharmony_ci
11161cb0ef41Sopenharmony_cistatic int check_scheme(const uint8_t *value, size_t len) {
11171cb0ef41Sopenharmony_ci  const uint8_t *last;
11181cb0ef41Sopenharmony_ci  if (len == 0) {
11191cb0ef41Sopenharmony_ci    return 0;
11201cb0ef41Sopenharmony_ci  }
11211cb0ef41Sopenharmony_ci
11221cb0ef41Sopenharmony_ci  if (!(('A' <= *value && *value <= 'Z') || ('a' <= *value && *value <= 'z'))) {
11231cb0ef41Sopenharmony_ci    return 0;
11241cb0ef41Sopenharmony_ci  }
11251cb0ef41Sopenharmony_ci
11261cb0ef41Sopenharmony_ci  last = value + len;
11271cb0ef41Sopenharmony_ci  ++value;
11281cb0ef41Sopenharmony_ci
11291cb0ef41Sopenharmony_ci  for (; value != last; ++value) {
11301cb0ef41Sopenharmony_ci    if (!(('A' <= *value && *value <= 'Z') ||
11311cb0ef41Sopenharmony_ci          ('a' <= *value && *value <= 'z') ||
11321cb0ef41Sopenharmony_ci          ('0' <= *value && *value <= '9') || *value == '+' || *value == '-' ||
11331cb0ef41Sopenharmony_ci          *value == '.')) {
11341cb0ef41Sopenharmony_ci      return 0;
11351cb0ef41Sopenharmony_ci    }
11361cb0ef41Sopenharmony_ci  }
11371cb0ef41Sopenharmony_ci  return 1;
11381cb0ef41Sopenharmony_ci}
11391cb0ef41Sopenharmony_ci
11401cb0ef41Sopenharmony_ci/* Generated by genmethodchartbl.py */
11411cb0ef41Sopenharmony_cistatic char VALID_METHOD_CHARS[] = {
11421cb0ef41Sopenharmony_ci    0 /* NUL  */, 0 /* SOH  */, 0 /* STX  */, 0 /* ETX  */,
11431cb0ef41Sopenharmony_ci    0 /* EOT  */, 0 /* ENQ  */, 0 /* ACK  */, 0 /* BEL  */,
11441cb0ef41Sopenharmony_ci    0 /* BS   */, 0 /* HT   */, 0 /* LF   */, 0 /* VT   */,
11451cb0ef41Sopenharmony_ci    0 /* FF   */, 0 /* CR   */, 0 /* SO   */, 0 /* SI   */,
11461cb0ef41Sopenharmony_ci    0 /* DLE  */, 0 /* DC1  */, 0 /* DC2  */, 0 /* DC3  */,
11471cb0ef41Sopenharmony_ci    0 /* DC4  */, 0 /* NAK  */, 0 /* SYN  */, 0 /* ETB  */,
11481cb0ef41Sopenharmony_ci    0 /* CAN  */, 0 /* EM   */, 0 /* SUB  */, 0 /* ESC  */,
11491cb0ef41Sopenharmony_ci    0 /* FS   */, 0 /* GS   */, 0 /* RS   */, 0 /* US   */,
11501cb0ef41Sopenharmony_ci    0 /* SPC  */, 1 /* !    */, 0 /* "    */, 1 /* #    */,
11511cb0ef41Sopenharmony_ci    1 /* $    */, 1 /* %    */, 1 /* &    */, 1 /* '    */,
11521cb0ef41Sopenharmony_ci    0 /* (    */, 0 /* )    */, 1 /* *    */, 1 /* +    */,
11531cb0ef41Sopenharmony_ci    0 /* ,    */, 1 /* -    */, 1 /* .    */, 0 /* /    */,
11541cb0ef41Sopenharmony_ci    1 /* 0    */, 1 /* 1    */, 1 /* 2    */, 1 /* 3    */,
11551cb0ef41Sopenharmony_ci    1 /* 4    */, 1 /* 5    */, 1 /* 6    */, 1 /* 7    */,
11561cb0ef41Sopenharmony_ci    1 /* 8    */, 1 /* 9    */, 0 /* :    */, 0 /* ;    */,
11571cb0ef41Sopenharmony_ci    0 /* <    */, 0 /* =    */, 0 /* >    */, 0 /* ?    */,
11581cb0ef41Sopenharmony_ci    0 /* @    */, 1 /* A    */, 1 /* B    */, 1 /* C    */,
11591cb0ef41Sopenharmony_ci    1 /* D    */, 1 /* E    */, 1 /* F    */, 1 /* G    */,
11601cb0ef41Sopenharmony_ci    1 /* H    */, 1 /* I    */, 1 /* J    */, 1 /* K    */,
11611cb0ef41Sopenharmony_ci    1 /* L    */, 1 /* M    */, 1 /* N    */, 1 /* O    */,
11621cb0ef41Sopenharmony_ci    1 /* P    */, 1 /* Q    */, 1 /* R    */, 1 /* S    */,
11631cb0ef41Sopenharmony_ci    1 /* T    */, 1 /* U    */, 1 /* V    */, 1 /* W    */,
11641cb0ef41Sopenharmony_ci    1 /* X    */, 1 /* Y    */, 1 /* Z    */, 0 /* [    */,
11651cb0ef41Sopenharmony_ci    0 /* \    */, 0 /* ]    */, 1 /* ^    */, 1 /* _    */,
11661cb0ef41Sopenharmony_ci    1 /* `    */, 1 /* a    */, 1 /* b    */, 1 /* c    */,
11671cb0ef41Sopenharmony_ci    1 /* d    */, 1 /* e    */, 1 /* f    */, 1 /* g    */,
11681cb0ef41Sopenharmony_ci    1 /* h    */, 1 /* i    */, 1 /* j    */, 1 /* k    */,
11691cb0ef41Sopenharmony_ci    1 /* l    */, 1 /* m    */, 1 /* n    */, 1 /* o    */,
11701cb0ef41Sopenharmony_ci    1 /* p    */, 1 /* q    */, 1 /* r    */, 1 /* s    */,
11711cb0ef41Sopenharmony_ci    1 /* t    */, 1 /* u    */, 1 /* v    */, 1 /* w    */,
11721cb0ef41Sopenharmony_ci    1 /* x    */, 1 /* y    */, 1 /* z    */, 0 /* {    */,
11731cb0ef41Sopenharmony_ci    1 /* |    */, 0 /* }    */, 1 /* ~    */, 0 /* DEL  */,
11741cb0ef41Sopenharmony_ci    0 /* 0x80 */, 0 /* 0x81 */, 0 /* 0x82 */, 0 /* 0x83 */,
11751cb0ef41Sopenharmony_ci    0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */, 0 /* 0x87 */,
11761cb0ef41Sopenharmony_ci    0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */,
11771cb0ef41Sopenharmony_ci    0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */,
11781cb0ef41Sopenharmony_ci    0 /* 0x90 */, 0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */,
11791cb0ef41Sopenharmony_ci    0 /* 0x94 */, 0 /* 0x95 */, 0 /* 0x96 */, 0 /* 0x97 */,
11801cb0ef41Sopenharmony_ci    0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */, 0 /* 0x9b */,
11811cb0ef41Sopenharmony_ci    0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */,
11821cb0ef41Sopenharmony_ci    0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */,
11831cb0ef41Sopenharmony_ci    0 /* 0xa4 */, 0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */,
11841cb0ef41Sopenharmony_ci    0 /* 0xa8 */, 0 /* 0xa9 */, 0 /* 0xaa */, 0 /* 0xab */,
11851cb0ef41Sopenharmony_ci    0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */, 0 /* 0xaf */,
11861cb0ef41Sopenharmony_ci    0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */,
11871cb0ef41Sopenharmony_ci    0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */,
11881cb0ef41Sopenharmony_ci    0 /* 0xb8 */, 0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */,
11891cb0ef41Sopenharmony_ci    0 /* 0xbc */, 0 /* 0xbd */, 0 /* 0xbe */, 0 /* 0xbf */,
11901cb0ef41Sopenharmony_ci    0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */, 0 /* 0xc3 */,
11911cb0ef41Sopenharmony_ci    0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */,
11921cb0ef41Sopenharmony_ci    0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */,
11931cb0ef41Sopenharmony_ci    0 /* 0xcc */, 0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */,
11941cb0ef41Sopenharmony_ci    0 /* 0xd0 */, 0 /* 0xd1 */, 0 /* 0xd2 */, 0 /* 0xd3 */,
11951cb0ef41Sopenharmony_ci    0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */, 0 /* 0xd7 */,
11961cb0ef41Sopenharmony_ci    0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */,
11971cb0ef41Sopenharmony_ci    0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */,
11981cb0ef41Sopenharmony_ci    0 /* 0xe0 */, 0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */,
11991cb0ef41Sopenharmony_ci    0 /* 0xe4 */, 0 /* 0xe5 */, 0 /* 0xe6 */, 0 /* 0xe7 */,
12001cb0ef41Sopenharmony_ci    0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */, 0 /* 0xeb */,
12011cb0ef41Sopenharmony_ci    0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */,
12021cb0ef41Sopenharmony_ci    0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */,
12031cb0ef41Sopenharmony_ci    0 /* 0xf4 */, 0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */,
12041cb0ef41Sopenharmony_ci    0 /* 0xf8 */, 0 /* 0xf9 */, 0 /* 0xfa */, 0 /* 0xfb */,
12051cb0ef41Sopenharmony_ci    0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */, 0 /* 0xff */
12061cb0ef41Sopenharmony_ci};
12071cb0ef41Sopenharmony_ci
12081cb0ef41Sopenharmony_cistatic int check_method(const uint8_t *value, size_t len) {
12091cb0ef41Sopenharmony_ci  const uint8_t *last;
12101cb0ef41Sopenharmony_ci  if (len == 0) {
12111cb0ef41Sopenharmony_ci    return 0;
12121cb0ef41Sopenharmony_ci  }
12131cb0ef41Sopenharmony_ci  for (last = value + len; value != last; ++value) {
12141cb0ef41Sopenharmony_ci    if (!VALID_METHOD_CHARS[*value]) {
12151cb0ef41Sopenharmony_ci      return 0;
12161cb0ef41Sopenharmony_ci    }
12171cb0ef41Sopenharmony_ci  }
12181cb0ef41Sopenharmony_ci  return 1;
12191cb0ef41Sopenharmony_ci}
12201cb0ef41Sopenharmony_ci
12211cb0ef41Sopenharmony_ci/* Generated by genpathchartbl.py */
12221cb0ef41Sopenharmony_cistatic char VALID_PATH_CHARS[] = {
12231cb0ef41Sopenharmony_ci    0 /* NUL  */, 0 /* SOH  */, 0 /* STX  */, 0 /* ETX  */,
12241cb0ef41Sopenharmony_ci    0 /* EOT  */, 0 /* ENQ  */, 0 /* ACK  */, 0 /* BEL  */,
12251cb0ef41Sopenharmony_ci    0 /* BS   */, 0 /* HT   */, 0 /* LF   */, 0 /* VT   */,
12261cb0ef41Sopenharmony_ci    0 /* FF   */, 0 /* CR   */, 0 /* SO   */, 0 /* SI   */,
12271cb0ef41Sopenharmony_ci    0 /* DLE  */, 0 /* DC1  */, 0 /* DC2  */, 0 /* DC3  */,
12281cb0ef41Sopenharmony_ci    0 /* DC4  */, 0 /* NAK  */, 0 /* SYN  */, 0 /* ETB  */,
12291cb0ef41Sopenharmony_ci    0 /* CAN  */, 0 /* EM   */, 0 /* SUB  */, 0 /* ESC  */,
12301cb0ef41Sopenharmony_ci    0 /* FS   */, 0 /* GS   */, 0 /* RS   */, 0 /* US   */,
12311cb0ef41Sopenharmony_ci    0 /* SPC  */, 1 /* !    */, 1 /* "    */, 1 /* #    */,
12321cb0ef41Sopenharmony_ci    1 /* $    */, 1 /* %    */, 1 /* &    */, 1 /* '    */,
12331cb0ef41Sopenharmony_ci    1 /* (    */, 1 /* )    */, 1 /* *    */, 1 /* +    */,
12341cb0ef41Sopenharmony_ci    1 /* ,    */, 1 /* -    */, 1 /* .    */, 1 /* /    */,
12351cb0ef41Sopenharmony_ci    1 /* 0    */, 1 /* 1    */, 1 /* 2    */, 1 /* 3    */,
12361cb0ef41Sopenharmony_ci    1 /* 4    */, 1 /* 5    */, 1 /* 6    */, 1 /* 7    */,
12371cb0ef41Sopenharmony_ci    1 /* 8    */, 1 /* 9    */, 1 /* :    */, 1 /* ;    */,
12381cb0ef41Sopenharmony_ci    1 /* <    */, 1 /* =    */, 1 /* >    */, 1 /* ?    */,
12391cb0ef41Sopenharmony_ci    1 /* @    */, 1 /* A    */, 1 /* B    */, 1 /* C    */,
12401cb0ef41Sopenharmony_ci    1 /* D    */, 1 /* E    */, 1 /* F    */, 1 /* G    */,
12411cb0ef41Sopenharmony_ci    1 /* H    */, 1 /* I    */, 1 /* J    */, 1 /* K    */,
12421cb0ef41Sopenharmony_ci    1 /* L    */, 1 /* M    */, 1 /* N    */, 1 /* O    */,
12431cb0ef41Sopenharmony_ci    1 /* P    */, 1 /* Q    */, 1 /* R    */, 1 /* S    */,
12441cb0ef41Sopenharmony_ci    1 /* T    */, 1 /* U    */, 1 /* V    */, 1 /* W    */,
12451cb0ef41Sopenharmony_ci    1 /* X    */, 1 /* Y    */, 1 /* Z    */, 1 /* [    */,
12461cb0ef41Sopenharmony_ci    1 /* \    */, 1 /* ]    */, 1 /* ^    */, 1 /* _    */,
12471cb0ef41Sopenharmony_ci    1 /* `    */, 1 /* a    */, 1 /* b    */, 1 /* c    */,
12481cb0ef41Sopenharmony_ci    1 /* d    */, 1 /* e    */, 1 /* f    */, 1 /* g    */,
12491cb0ef41Sopenharmony_ci    1 /* h    */, 1 /* i    */, 1 /* j    */, 1 /* k    */,
12501cb0ef41Sopenharmony_ci    1 /* l    */, 1 /* m    */, 1 /* n    */, 1 /* o    */,
12511cb0ef41Sopenharmony_ci    1 /* p    */, 1 /* q    */, 1 /* r    */, 1 /* s    */,
12521cb0ef41Sopenharmony_ci    1 /* t    */, 1 /* u    */, 1 /* v    */, 1 /* w    */,
12531cb0ef41Sopenharmony_ci    1 /* x    */, 1 /* y    */, 1 /* z    */, 1 /* {    */,
12541cb0ef41Sopenharmony_ci    1 /* |    */, 1 /* }    */, 1 /* ~    */, 0 /* DEL  */,
12551cb0ef41Sopenharmony_ci    1 /* 0x80 */, 1 /* 0x81 */, 1 /* 0x82 */, 1 /* 0x83 */,
12561cb0ef41Sopenharmony_ci    1 /* 0x84 */, 1 /* 0x85 */, 1 /* 0x86 */, 1 /* 0x87 */,
12571cb0ef41Sopenharmony_ci    1 /* 0x88 */, 1 /* 0x89 */, 1 /* 0x8a */, 1 /* 0x8b */,
12581cb0ef41Sopenharmony_ci    1 /* 0x8c */, 1 /* 0x8d */, 1 /* 0x8e */, 1 /* 0x8f */,
12591cb0ef41Sopenharmony_ci    1 /* 0x90 */, 1 /* 0x91 */, 1 /* 0x92 */, 1 /* 0x93 */,
12601cb0ef41Sopenharmony_ci    1 /* 0x94 */, 1 /* 0x95 */, 1 /* 0x96 */, 1 /* 0x97 */,
12611cb0ef41Sopenharmony_ci    1 /* 0x98 */, 1 /* 0x99 */, 1 /* 0x9a */, 1 /* 0x9b */,
12621cb0ef41Sopenharmony_ci    1 /* 0x9c */, 1 /* 0x9d */, 1 /* 0x9e */, 1 /* 0x9f */,
12631cb0ef41Sopenharmony_ci    1 /* 0xa0 */, 1 /* 0xa1 */, 1 /* 0xa2 */, 1 /* 0xa3 */,
12641cb0ef41Sopenharmony_ci    1 /* 0xa4 */, 1 /* 0xa5 */, 1 /* 0xa6 */, 1 /* 0xa7 */,
12651cb0ef41Sopenharmony_ci    1 /* 0xa8 */, 1 /* 0xa9 */, 1 /* 0xaa */, 1 /* 0xab */,
12661cb0ef41Sopenharmony_ci    1 /* 0xac */, 1 /* 0xad */, 1 /* 0xae */, 1 /* 0xaf */,
12671cb0ef41Sopenharmony_ci    1 /* 0xb0 */, 1 /* 0xb1 */, 1 /* 0xb2 */, 1 /* 0xb3 */,
12681cb0ef41Sopenharmony_ci    1 /* 0xb4 */, 1 /* 0xb5 */, 1 /* 0xb6 */, 1 /* 0xb7 */,
12691cb0ef41Sopenharmony_ci    1 /* 0xb8 */, 1 /* 0xb9 */, 1 /* 0xba */, 1 /* 0xbb */,
12701cb0ef41Sopenharmony_ci    1 /* 0xbc */, 1 /* 0xbd */, 1 /* 0xbe */, 1 /* 0xbf */,
12711cb0ef41Sopenharmony_ci    1 /* 0xc0 */, 1 /* 0xc1 */, 1 /* 0xc2 */, 1 /* 0xc3 */,
12721cb0ef41Sopenharmony_ci    1 /* 0xc4 */, 1 /* 0xc5 */, 1 /* 0xc6 */, 1 /* 0xc7 */,
12731cb0ef41Sopenharmony_ci    1 /* 0xc8 */, 1 /* 0xc9 */, 1 /* 0xca */, 1 /* 0xcb */,
12741cb0ef41Sopenharmony_ci    1 /* 0xcc */, 1 /* 0xcd */, 1 /* 0xce */, 1 /* 0xcf */,
12751cb0ef41Sopenharmony_ci    1 /* 0xd0 */, 1 /* 0xd1 */, 1 /* 0xd2 */, 1 /* 0xd3 */,
12761cb0ef41Sopenharmony_ci    1 /* 0xd4 */, 1 /* 0xd5 */, 1 /* 0xd6 */, 1 /* 0xd7 */,
12771cb0ef41Sopenharmony_ci    1 /* 0xd8 */, 1 /* 0xd9 */, 1 /* 0xda */, 1 /* 0xdb */,
12781cb0ef41Sopenharmony_ci    1 /* 0xdc */, 1 /* 0xdd */, 1 /* 0xde */, 1 /* 0xdf */,
12791cb0ef41Sopenharmony_ci    1 /* 0xe0 */, 1 /* 0xe1 */, 1 /* 0xe2 */, 1 /* 0xe3 */,
12801cb0ef41Sopenharmony_ci    1 /* 0xe4 */, 1 /* 0xe5 */, 1 /* 0xe6 */, 1 /* 0xe7 */,
12811cb0ef41Sopenharmony_ci    1 /* 0xe8 */, 1 /* 0xe9 */, 1 /* 0xea */, 1 /* 0xeb */,
12821cb0ef41Sopenharmony_ci    1 /* 0xec */, 1 /* 0xed */, 1 /* 0xee */, 1 /* 0xef */,
12831cb0ef41Sopenharmony_ci    1 /* 0xf0 */, 1 /* 0xf1 */, 1 /* 0xf2 */, 1 /* 0xf3 */,
12841cb0ef41Sopenharmony_ci    1 /* 0xf4 */, 1 /* 0xf5 */, 1 /* 0xf6 */, 1 /* 0xf7 */,
12851cb0ef41Sopenharmony_ci    1 /* 0xf8 */, 1 /* 0xf9 */, 1 /* 0xfa */, 1 /* 0xfb */,
12861cb0ef41Sopenharmony_ci    1 /* 0xfc */, 1 /* 0xfd */, 1 /* 0xfe */, 1 /* 0xff */
12871cb0ef41Sopenharmony_ci};
12881cb0ef41Sopenharmony_ci
12891cb0ef41Sopenharmony_cistatic int check_path(const uint8_t *value, size_t len) {
12901cb0ef41Sopenharmony_ci  const uint8_t *last;
12911cb0ef41Sopenharmony_ci  for (last = value + len; value != last; ++value) {
12921cb0ef41Sopenharmony_ci    if (!VALID_PATH_CHARS[*value]) {
12931cb0ef41Sopenharmony_ci      return 0;
12941cb0ef41Sopenharmony_ci    }
12951cb0ef41Sopenharmony_ci  }
12961cb0ef41Sopenharmony_ci  return 1;
12971cb0ef41Sopenharmony_ci}
12981cb0ef41Sopenharmony_ci
12991cb0ef41Sopenharmony_ciint nghttp3_http_on_header(nghttp3_http_state *http, nghttp3_qpack_nv *nv,
13001cb0ef41Sopenharmony_ci                           int request, int trailers, int connect_protocol) {
13011cb0ef41Sopenharmony_ci  int rv;
13021cb0ef41Sopenharmony_ci  size_t i;
13031cb0ef41Sopenharmony_ci  uint8_t c;
13041cb0ef41Sopenharmony_ci
13051cb0ef41Sopenharmony_ci  if (!nghttp3_check_header_name(nv->name->base, nv->name->len)) {
13061cb0ef41Sopenharmony_ci    if (nv->name->len > 0 && nv->name->base[0] == ':') {
13071cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
13081cb0ef41Sopenharmony_ci    }
13091cb0ef41Sopenharmony_ci    /* header field name must be lower-cased without exception */
13101cb0ef41Sopenharmony_ci    for (i = 0; i < nv->name->len; ++i) {
13111cb0ef41Sopenharmony_ci      c = nv->name->base[i];
13121cb0ef41Sopenharmony_ci      if ('A' <= c && c <= 'Z') {
13131cb0ef41Sopenharmony_ci        return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
13141cb0ef41Sopenharmony_ci      }
13151cb0ef41Sopenharmony_ci    }
13161cb0ef41Sopenharmony_ci    /* When ignoring regular header fields, we set this flag so that
13171cb0ef41Sopenharmony_ci       we still enforce header field ordering rule for pseudo header
13181cb0ef41Sopenharmony_ci       fields. */
13191cb0ef41Sopenharmony_ci    http->flags |= NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED;
13201cb0ef41Sopenharmony_ci    return NGHTTP3_ERR_REMOVE_HTTP_HEADER;
13211cb0ef41Sopenharmony_ci  }
13221cb0ef41Sopenharmony_ci
13231cb0ef41Sopenharmony_ci  assert(nv->name->len > 0);
13241cb0ef41Sopenharmony_ci
13251cb0ef41Sopenharmony_ci  switch (nv->token) {
13261cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN__METHOD:
13271cb0ef41Sopenharmony_ci    rv = check_method(nv->value->base, nv->value->len);
13281cb0ef41Sopenharmony_ci    break;
13291cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN__SCHEME:
13301cb0ef41Sopenharmony_ci    rv = check_scheme(nv->value->base, nv->value->len);
13311cb0ef41Sopenharmony_ci    break;
13321cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN__AUTHORITY:
13331cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN_HOST:
13341cb0ef41Sopenharmony_ci    if (request) {
13351cb0ef41Sopenharmony_ci      rv = check_authority(nv->value->base, nv->value->len);
13361cb0ef41Sopenharmony_ci    } else {
13371cb0ef41Sopenharmony_ci      /* The use of host field in response field section is
13381cb0ef41Sopenharmony_ci         undefined. */
13391cb0ef41Sopenharmony_ci      rv = nghttp3_check_header_value(nv->value->base, nv->value->len);
13401cb0ef41Sopenharmony_ci    }
13411cb0ef41Sopenharmony_ci    break;
13421cb0ef41Sopenharmony_ci  case NGHTTP3_QPACK_TOKEN__PATH:
13431cb0ef41Sopenharmony_ci    rv = check_path(nv->value->base, nv->value->len);
13441cb0ef41Sopenharmony_ci    break;
13451cb0ef41Sopenharmony_ci  default:
13461cb0ef41Sopenharmony_ci    rv = nghttp3_check_header_value(nv->value->base, nv->value->len);
13471cb0ef41Sopenharmony_ci  }
13481cb0ef41Sopenharmony_ci
13491cb0ef41Sopenharmony_ci  if (rv == 0) {
13501cb0ef41Sopenharmony_ci    if (nv->name->base[0] == ':') {
13511cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
13521cb0ef41Sopenharmony_ci    }
13531cb0ef41Sopenharmony_ci    /* When ignoring regular header fields, we set this flag so that
13541cb0ef41Sopenharmony_ci       we still enforce header field ordering rule for pseudo header
13551cb0ef41Sopenharmony_ci       fields. */
13561cb0ef41Sopenharmony_ci    http->flags |= NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED;
13571cb0ef41Sopenharmony_ci    return NGHTTP3_ERR_REMOVE_HTTP_HEADER;
13581cb0ef41Sopenharmony_ci  }
13591cb0ef41Sopenharmony_ci
13601cb0ef41Sopenharmony_ci  if (request) {
13611cb0ef41Sopenharmony_ci    rv = http_request_on_header(http, nv, trailers, connect_protocol);
13621cb0ef41Sopenharmony_ci  } else {
13631cb0ef41Sopenharmony_ci    rv = http_response_on_header(http, nv, trailers);
13641cb0ef41Sopenharmony_ci  }
13651cb0ef41Sopenharmony_ci
13661cb0ef41Sopenharmony_ci  if (nv->name->base[0] != ':') {
13671cb0ef41Sopenharmony_ci    switch (rv) {
13681cb0ef41Sopenharmony_ci    case 0:
13691cb0ef41Sopenharmony_ci    case NGHTTP3_ERR_REMOVE_HTTP_HEADER:
13701cb0ef41Sopenharmony_ci      http->flags |= NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED;
13711cb0ef41Sopenharmony_ci      break;
13721cb0ef41Sopenharmony_ci    }
13731cb0ef41Sopenharmony_ci  }
13741cb0ef41Sopenharmony_ci
13751cb0ef41Sopenharmony_ci  return rv;
13761cb0ef41Sopenharmony_ci}
13771cb0ef41Sopenharmony_ci
13781cb0ef41Sopenharmony_ciint nghttp3_http_on_request_headers(nghttp3_http_state *http) {
13791cb0ef41Sopenharmony_ci  if (!(http->flags & NGHTTP3_HTTP_FLAG__PROTOCOL) &&
13801cb0ef41Sopenharmony_ci      (http->flags & NGHTTP3_HTTP_FLAG_METH_CONNECT)) {
13811cb0ef41Sopenharmony_ci    if ((http->flags & (NGHTTP3_HTTP_FLAG__SCHEME | NGHTTP3_HTTP_FLAG__PATH)) ||
13821cb0ef41Sopenharmony_ci        (http->flags & NGHTTP3_HTTP_FLAG__AUTHORITY) == 0) {
13831cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
13841cb0ef41Sopenharmony_ci    }
13851cb0ef41Sopenharmony_ci    http->content_length = -1;
13861cb0ef41Sopenharmony_ci  } else {
13871cb0ef41Sopenharmony_ci    if ((http->flags & NGHTTP3_HTTP_FLAG_REQ_HEADERS) !=
13881cb0ef41Sopenharmony_ci            NGHTTP3_HTTP_FLAG_REQ_HEADERS ||
13891cb0ef41Sopenharmony_ci        (http->flags &
13901cb0ef41Sopenharmony_ci         (NGHTTP3_HTTP_FLAG__AUTHORITY | NGHTTP3_HTTP_FLAG_HOST)) == 0) {
13911cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
13921cb0ef41Sopenharmony_ci    }
13931cb0ef41Sopenharmony_ci    if ((http->flags & NGHTTP3_HTTP_FLAG__PROTOCOL) &&
13941cb0ef41Sopenharmony_ci        ((http->flags & NGHTTP3_HTTP_FLAG_METH_CONNECT) == 0 ||
13951cb0ef41Sopenharmony_ci         (http->flags & NGHTTP3_HTTP_FLAG__AUTHORITY) == 0)) {
13961cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
13971cb0ef41Sopenharmony_ci    }
13981cb0ef41Sopenharmony_ci    if (!check_path_flags(http)) {
13991cb0ef41Sopenharmony_ci      return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
14001cb0ef41Sopenharmony_ci    }
14011cb0ef41Sopenharmony_ci  }
14021cb0ef41Sopenharmony_ci
14031cb0ef41Sopenharmony_ci  return 0;
14041cb0ef41Sopenharmony_ci}
14051cb0ef41Sopenharmony_ci
14061cb0ef41Sopenharmony_ciint nghttp3_http_on_response_headers(nghttp3_http_state *http) {
14071cb0ef41Sopenharmony_ci  if ((http->flags & NGHTTP3_HTTP_FLAG__STATUS) == 0) {
14081cb0ef41Sopenharmony_ci    return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
14091cb0ef41Sopenharmony_ci  }
14101cb0ef41Sopenharmony_ci
14111cb0ef41Sopenharmony_ci  if (http->status_code / 100 == 1) {
14121cb0ef41Sopenharmony_ci    /* non-final response */
14131cb0ef41Sopenharmony_ci    http->flags = (http->flags & NGHTTP3_HTTP_FLAG_METH_ALL) |
14141cb0ef41Sopenharmony_ci                  NGHTTP3_HTTP_FLAG_EXPECT_FINAL_RESPONSE;
14151cb0ef41Sopenharmony_ci    http->content_length = -1;
14161cb0ef41Sopenharmony_ci    http->status_code = -1;
14171cb0ef41Sopenharmony_ci    return 0;
14181cb0ef41Sopenharmony_ci  }
14191cb0ef41Sopenharmony_ci
14201cb0ef41Sopenharmony_ci  http->flags &= ~NGHTTP3_HTTP_FLAG_EXPECT_FINAL_RESPONSE;
14211cb0ef41Sopenharmony_ci
14221cb0ef41Sopenharmony_ci  if (!expect_response_body(http)) {
14231cb0ef41Sopenharmony_ci    http->content_length = 0;
14241cb0ef41Sopenharmony_ci  } else if (http->flags & NGHTTP3_HTTP_FLAG_METH_CONNECT) {
14251cb0ef41Sopenharmony_ci    http->content_length = -1;
14261cb0ef41Sopenharmony_ci  }
14271cb0ef41Sopenharmony_ci
14281cb0ef41Sopenharmony_ci  return 0;
14291cb0ef41Sopenharmony_ci}
14301cb0ef41Sopenharmony_ci
14311cb0ef41Sopenharmony_ciint nghttp3_http_on_remote_end_stream(nghttp3_stream *stream) {
14321cb0ef41Sopenharmony_ci  if ((stream->rx.http.flags & NGHTTP3_HTTP_FLAG_EXPECT_FINAL_RESPONSE) ||
14331cb0ef41Sopenharmony_ci      (stream->rx.http.content_length != -1 &&
14341cb0ef41Sopenharmony_ci       stream->rx.http.content_length != stream->rx.http.recv_content_length)) {
14351cb0ef41Sopenharmony_ci    return NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING;
14361cb0ef41Sopenharmony_ci  }
14371cb0ef41Sopenharmony_ci
14381cb0ef41Sopenharmony_ci  return 0;
14391cb0ef41Sopenharmony_ci}
14401cb0ef41Sopenharmony_ci
14411cb0ef41Sopenharmony_ciint nghttp3_http_on_data_chunk(nghttp3_stream *stream, size_t n) {
14421cb0ef41Sopenharmony_ci  stream->rx.http.recv_content_length += (int64_t)n;
14431cb0ef41Sopenharmony_ci
14441cb0ef41Sopenharmony_ci  if ((stream->rx.http.flags & NGHTTP3_HTTP_FLAG_EXPECT_FINAL_RESPONSE) ||
14451cb0ef41Sopenharmony_ci      (stream->rx.http.content_length != -1 &&
14461cb0ef41Sopenharmony_ci       stream->rx.http.recv_content_length > stream->rx.http.content_length)) {
14471cb0ef41Sopenharmony_ci    return NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING;
14481cb0ef41Sopenharmony_ci  }
14491cb0ef41Sopenharmony_ci
14501cb0ef41Sopenharmony_ci  return 0;
14511cb0ef41Sopenharmony_ci}
14521cb0ef41Sopenharmony_ci
14531cb0ef41Sopenharmony_civoid nghttp3_http_record_request_method(nghttp3_stream *stream,
14541cb0ef41Sopenharmony_ci                                        const nghttp3_nv *nva, size_t nvlen) {
14551cb0ef41Sopenharmony_ci  size_t i;
14561cb0ef41Sopenharmony_ci  const nghttp3_nv *nv;
14571cb0ef41Sopenharmony_ci
14581cb0ef41Sopenharmony_ci  /* TODO we should do this strictly. */
14591cb0ef41Sopenharmony_ci  for (i = 0; i < nvlen; ++i) {
14601cb0ef41Sopenharmony_ci    nv = &nva[i];
14611cb0ef41Sopenharmony_ci    if (!(nv->namelen == 7 && nv->name[6] == 'd' &&
14621cb0ef41Sopenharmony_ci          memcmp(":metho", nv->name, nv->namelen - 1) == 0)) {
14631cb0ef41Sopenharmony_ci      continue;
14641cb0ef41Sopenharmony_ci    }
14651cb0ef41Sopenharmony_ci    if (lstreq("CONNECT", nv->value, nv->valuelen)) {
14661cb0ef41Sopenharmony_ci      stream->rx.http.flags |= NGHTTP3_HTTP_FLAG_METH_CONNECT;
14671cb0ef41Sopenharmony_ci      return;
14681cb0ef41Sopenharmony_ci    }
14691cb0ef41Sopenharmony_ci    if (lstreq("HEAD", nv->value, nv->valuelen)) {
14701cb0ef41Sopenharmony_ci      stream->rx.http.flags |= NGHTTP3_HTTP_FLAG_METH_HEAD;
14711cb0ef41Sopenharmony_ci      return;
14721cb0ef41Sopenharmony_ci    }
14731cb0ef41Sopenharmony_ci    return;
14741cb0ef41Sopenharmony_ci  }
14751cb0ef41Sopenharmony_ci}
14761cb0ef41Sopenharmony_ci
14771cb0ef41Sopenharmony_ci/* Generated by gennmchartbl.py */
14781cb0ef41Sopenharmony_cistatic const int VALID_HD_NAME_CHARS[] = {
14791cb0ef41Sopenharmony_ci    0 /* NUL  */, 0 /* SOH  */, 0 /* STX  */, 0 /* ETX  */,
14801cb0ef41Sopenharmony_ci    0 /* EOT  */, 0 /* ENQ  */, 0 /* ACK  */, 0 /* BEL  */,
14811cb0ef41Sopenharmony_ci    0 /* BS   */, 0 /* HT   */, 0 /* LF   */, 0 /* VT   */,
14821cb0ef41Sopenharmony_ci    0 /* FF   */, 0 /* CR   */, 0 /* SO   */, 0 /* SI   */,
14831cb0ef41Sopenharmony_ci    0 /* DLE  */, 0 /* DC1  */, 0 /* DC2  */, 0 /* DC3  */,
14841cb0ef41Sopenharmony_ci    0 /* DC4  */, 0 /* NAK  */, 0 /* SYN  */, 0 /* ETB  */,
14851cb0ef41Sopenharmony_ci    0 /* CAN  */, 0 /* EM   */, 0 /* SUB  */, 0 /* ESC  */,
14861cb0ef41Sopenharmony_ci    0 /* FS   */, 0 /* GS   */, 0 /* RS   */, 0 /* US   */,
14871cb0ef41Sopenharmony_ci    0 /* SPC  */, 1 /* !    */, 0 /* "    */, 1 /* #    */,
14881cb0ef41Sopenharmony_ci    1 /* $    */, 1 /* %    */, 1 /* &    */, 1 /* '    */,
14891cb0ef41Sopenharmony_ci    0 /* (    */, 0 /* )    */, 1 /* *    */, 1 /* +    */,
14901cb0ef41Sopenharmony_ci    0 /* ,    */, 1 /* -    */, 1 /* .    */, 0 /* /    */,
14911cb0ef41Sopenharmony_ci    1 /* 0    */, 1 /* 1    */, 1 /* 2    */, 1 /* 3    */,
14921cb0ef41Sopenharmony_ci    1 /* 4    */, 1 /* 5    */, 1 /* 6    */, 1 /* 7    */,
14931cb0ef41Sopenharmony_ci    1 /* 8    */, 1 /* 9    */, 0 /* :    */, 0 /* ;    */,
14941cb0ef41Sopenharmony_ci    0 /* <    */, 0 /* =    */, 0 /* >    */, 0 /* ?    */,
14951cb0ef41Sopenharmony_ci    0 /* @    */, 0 /* A    */, 0 /* B    */, 0 /* C    */,
14961cb0ef41Sopenharmony_ci    0 /* D    */, 0 /* E    */, 0 /* F    */, 0 /* G    */,
14971cb0ef41Sopenharmony_ci    0 /* H    */, 0 /* I    */, 0 /* J    */, 0 /* K    */,
14981cb0ef41Sopenharmony_ci    0 /* L    */, 0 /* M    */, 0 /* N    */, 0 /* O    */,
14991cb0ef41Sopenharmony_ci    0 /* P    */, 0 /* Q    */, 0 /* R    */, 0 /* S    */,
15001cb0ef41Sopenharmony_ci    0 /* T    */, 0 /* U    */, 0 /* V    */, 0 /* W    */,
15011cb0ef41Sopenharmony_ci    0 /* X    */, 0 /* Y    */, 0 /* Z    */, 0 /* [    */,
15021cb0ef41Sopenharmony_ci    0 /* \    */, 0 /* ]    */, 1 /* ^    */, 1 /* _    */,
15031cb0ef41Sopenharmony_ci    1 /* `    */, 1 /* a    */, 1 /* b    */, 1 /* c    */,
15041cb0ef41Sopenharmony_ci    1 /* d    */, 1 /* e    */, 1 /* f    */, 1 /* g    */,
15051cb0ef41Sopenharmony_ci    1 /* h    */, 1 /* i    */, 1 /* j    */, 1 /* k    */,
15061cb0ef41Sopenharmony_ci    1 /* l    */, 1 /* m    */, 1 /* n    */, 1 /* o    */,
15071cb0ef41Sopenharmony_ci    1 /* p    */, 1 /* q    */, 1 /* r    */, 1 /* s    */,
15081cb0ef41Sopenharmony_ci    1 /* t    */, 1 /* u    */, 1 /* v    */, 1 /* w    */,
15091cb0ef41Sopenharmony_ci    1 /* x    */, 1 /* y    */, 1 /* z    */, 0 /* {    */,
15101cb0ef41Sopenharmony_ci    1 /* |    */, 0 /* }    */, 1 /* ~    */, 0 /* DEL  */,
15111cb0ef41Sopenharmony_ci    0 /* 0x80 */, 0 /* 0x81 */, 0 /* 0x82 */, 0 /* 0x83 */,
15121cb0ef41Sopenharmony_ci    0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */, 0 /* 0x87 */,
15131cb0ef41Sopenharmony_ci    0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */,
15141cb0ef41Sopenharmony_ci    0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */,
15151cb0ef41Sopenharmony_ci    0 /* 0x90 */, 0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */,
15161cb0ef41Sopenharmony_ci    0 /* 0x94 */, 0 /* 0x95 */, 0 /* 0x96 */, 0 /* 0x97 */,
15171cb0ef41Sopenharmony_ci    0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */, 0 /* 0x9b */,
15181cb0ef41Sopenharmony_ci    0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */,
15191cb0ef41Sopenharmony_ci    0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */,
15201cb0ef41Sopenharmony_ci    0 /* 0xa4 */, 0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */,
15211cb0ef41Sopenharmony_ci    0 /* 0xa8 */, 0 /* 0xa9 */, 0 /* 0xaa */, 0 /* 0xab */,
15221cb0ef41Sopenharmony_ci    0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */, 0 /* 0xaf */,
15231cb0ef41Sopenharmony_ci    0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */,
15241cb0ef41Sopenharmony_ci    0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */,
15251cb0ef41Sopenharmony_ci    0 /* 0xb8 */, 0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */,
15261cb0ef41Sopenharmony_ci    0 /* 0xbc */, 0 /* 0xbd */, 0 /* 0xbe */, 0 /* 0xbf */,
15271cb0ef41Sopenharmony_ci    0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */, 0 /* 0xc3 */,
15281cb0ef41Sopenharmony_ci    0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */,
15291cb0ef41Sopenharmony_ci    0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */,
15301cb0ef41Sopenharmony_ci    0 /* 0xcc */, 0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */,
15311cb0ef41Sopenharmony_ci    0 /* 0xd0 */, 0 /* 0xd1 */, 0 /* 0xd2 */, 0 /* 0xd3 */,
15321cb0ef41Sopenharmony_ci    0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */, 0 /* 0xd7 */,
15331cb0ef41Sopenharmony_ci    0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */,
15341cb0ef41Sopenharmony_ci    0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */,
15351cb0ef41Sopenharmony_ci    0 /* 0xe0 */, 0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */,
15361cb0ef41Sopenharmony_ci    0 /* 0xe4 */, 0 /* 0xe5 */, 0 /* 0xe6 */, 0 /* 0xe7 */,
15371cb0ef41Sopenharmony_ci    0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */, 0 /* 0xeb */,
15381cb0ef41Sopenharmony_ci    0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */,
15391cb0ef41Sopenharmony_ci    0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */,
15401cb0ef41Sopenharmony_ci    0 /* 0xf4 */, 0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */,
15411cb0ef41Sopenharmony_ci    0 /* 0xf8 */, 0 /* 0xf9 */, 0 /* 0xfa */, 0 /* 0xfb */,
15421cb0ef41Sopenharmony_ci    0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */, 0 /* 0xff */
15431cb0ef41Sopenharmony_ci};
15441cb0ef41Sopenharmony_ci
15451cb0ef41Sopenharmony_ciint nghttp3_check_header_name(const uint8_t *name, size_t len) {
15461cb0ef41Sopenharmony_ci  const uint8_t *last;
15471cb0ef41Sopenharmony_ci  if (len == 0) {
15481cb0ef41Sopenharmony_ci    return 0;
15491cb0ef41Sopenharmony_ci  }
15501cb0ef41Sopenharmony_ci  if (*name == ':') {
15511cb0ef41Sopenharmony_ci    if (len == 1) {
15521cb0ef41Sopenharmony_ci      return 0;
15531cb0ef41Sopenharmony_ci    }
15541cb0ef41Sopenharmony_ci    ++name;
15551cb0ef41Sopenharmony_ci    --len;
15561cb0ef41Sopenharmony_ci  }
15571cb0ef41Sopenharmony_ci  for (last = name + len; name != last; ++name) {
15581cb0ef41Sopenharmony_ci    if (!VALID_HD_NAME_CHARS[*name]) {
15591cb0ef41Sopenharmony_ci      return 0;
15601cb0ef41Sopenharmony_ci    }
15611cb0ef41Sopenharmony_ci  }
15621cb0ef41Sopenharmony_ci  return 1;
15631cb0ef41Sopenharmony_ci}
15641cb0ef41Sopenharmony_ci
15651cb0ef41Sopenharmony_ci/* Generated by genvchartbl.py */
15661cb0ef41Sopenharmony_cistatic const int VALID_HD_VALUE_CHARS[] = {
15671cb0ef41Sopenharmony_ci    0 /* NUL  */, 0 /* SOH  */, 0 /* STX  */, 0 /* ETX  */,
15681cb0ef41Sopenharmony_ci    0 /* EOT  */, 0 /* ENQ  */, 0 /* ACK  */, 0 /* BEL  */,
15691cb0ef41Sopenharmony_ci    0 /* BS   */, 1 /* HT   */, 0 /* LF   */, 0 /* VT   */,
15701cb0ef41Sopenharmony_ci    0 /* FF   */, 0 /* CR   */, 0 /* SO   */, 0 /* SI   */,
15711cb0ef41Sopenharmony_ci    0 /* DLE  */, 0 /* DC1  */, 0 /* DC2  */, 0 /* DC3  */,
15721cb0ef41Sopenharmony_ci    0 /* DC4  */, 0 /* NAK  */, 0 /* SYN  */, 0 /* ETB  */,
15731cb0ef41Sopenharmony_ci    0 /* CAN  */, 0 /* EM   */, 0 /* SUB  */, 0 /* ESC  */,
15741cb0ef41Sopenharmony_ci    0 /* FS   */, 0 /* GS   */, 0 /* RS   */, 0 /* US   */,
15751cb0ef41Sopenharmony_ci    1 /* SPC  */, 1 /* !    */, 1 /* "    */, 1 /* #    */,
15761cb0ef41Sopenharmony_ci    1 /* $    */, 1 /* %    */, 1 /* &    */, 1 /* '    */,
15771cb0ef41Sopenharmony_ci    1 /* (    */, 1 /* )    */, 1 /* *    */, 1 /* +    */,
15781cb0ef41Sopenharmony_ci    1 /* ,    */, 1 /* -    */, 1 /* .    */, 1 /* /    */,
15791cb0ef41Sopenharmony_ci    1 /* 0    */, 1 /* 1    */, 1 /* 2    */, 1 /* 3    */,
15801cb0ef41Sopenharmony_ci    1 /* 4    */, 1 /* 5    */, 1 /* 6    */, 1 /* 7    */,
15811cb0ef41Sopenharmony_ci    1 /* 8    */, 1 /* 9    */, 1 /* :    */, 1 /* ;    */,
15821cb0ef41Sopenharmony_ci    1 /* <    */, 1 /* =    */, 1 /* >    */, 1 /* ?    */,
15831cb0ef41Sopenharmony_ci    1 /* @    */, 1 /* A    */, 1 /* B    */, 1 /* C    */,
15841cb0ef41Sopenharmony_ci    1 /* D    */, 1 /* E    */, 1 /* F    */, 1 /* G    */,
15851cb0ef41Sopenharmony_ci    1 /* H    */, 1 /* I    */, 1 /* J    */, 1 /* K    */,
15861cb0ef41Sopenharmony_ci    1 /* L    */, 1 /* M    */, 1 /* N    */, 1 /* O    */,
15871cb0ef41Sopenharmony_ci    1 /* P    */, 1 /* Q    */, 1 /* R    */, 1 /* S    */,
15881cb0ef41Sopenharmony_ci    1 /* T    */, 1 /* U    */, 1 /* V    */, 1 /* W    */,
15891cb0ef41Sopenharmony_ci    1 /* X    */, 1 /* Y    */, 1 /* Z    */, 1 /* [    */,
15901cb0ef41Sopenharmony_ci    1 /* \    */, 1 /* ]    */, 1 /* ^    */, 1 /* _    */,
15911cb0ef41Sopenharmony_ci    1 /* `    */, 1 /* a    */, 1 /* b    */, 1 /* c    */,
15921cb0ef41Sopenharmony_ci    1 /* d    */, 1 /* e    */, 1 /* f    */, 1 /* g    */,
15931cb0ef41Sopenharmony_ci    1 /* h    */, 1 /* i    */, 1 /* j    */, 1 /* k    */,
15941cb0ef41Sopenharmony_ci    1 /* l    */, 1 /* m    */, 1 /* n    */, 1 /* o    */,
15951cb0ef41Sopenharmony_ci    1 /* p    */, 1 /* q    */, 1 /* r    */, 1 /* s    */,
15961cb0ef41Sopenharmony_ci    1 /* t    */, 1 /* u    */, 1 /* v    */, 1 /* w    */,
15971cb0ef41Sopenharmony_ci    1 /* x    */, 1 /* y    */, 1 /* z    */, 1 /* {    */,
15981cb0ef41Sopenharmony_ci    1 /* |    */, 1 /* }    */, 1 /* ~    */, 0 /* DEL  */,
15991cb0ef41Sopenharmony_ci    1 /* 0x80 */, 1 /* 0x81 */, 1 /* 0x82 */, 1 /* 0x83 */,
16001cb0ef41Sopenharmony_ci    1 /* 0x84 */, 1 /* 0x85 */, 1 /* 0x86 */, 1 /* 0x87 */,
16011cb0ef41Sopenharmony_ci    1 /* 0x88 */, 1 /* 0x89 */, 1 /* 0x8a */, 1 /* 0x8b */,
16021cb0ef41Sopenharmony_ci    1 /* 0x8c */, 1 /* 0x8d */, 1 /* 0x8e */, 1 /* 0x8f */,
16031cb0ef41Sopenharmony_ci    1 /* 0x90 */, 1 /* 0x91 */, 1 /* 0x92 */, 1 /* 0x93 */,
16041cb0ef41Sopenharmony_ci    1 /* 0x94 */, 1 /* 0x95 */, 1 /* 0x96 */, 1 /* 0x97 */,
16051cb0ef41Sopenharmony_ci    1 /* 0x98 */, 1 /* 0x99 */, 1 /* 0x9a */, 1 /* 0x9b */,
16061cb0ef41Sopenharmony_ci    1 /* 0x9c */, 1 /* 0x9d */, 1 /* 0x9e */, 1 /* 0x9f */,
16071cb0ef41Sopenharmony_ci    1 /* 0xa0 */, 1 /* 0xa1 */, 1 /* 0xa2 */, 1 /* 0xa3 */,
16081cb0ef41Sopenharmony_ci    1 /* 0xa4 */, 1 /* 0xa5 */, 1 /* 0xa6 */, 1 /* 0xa7 */,
16091cb0ef41Sopenharmony_ci    1 /* 0xa8 */, 1 /* 0xa9 */, 1 /* 0xaa */, 1 /* 0xab */,
16101cb0ef41Sopenharmony_ci    1 /* 0xac */, 1 /* 0xad */, 1 /* 0xae */, 1 /* 0xaf */,
16111cb0ef41Sopenharmony_ci    1 /* 0xb0 */, 1 /* 0xb1 */, 1 /* 0xb2 */, 1 /* 0xb3 */,
16121cb0ef41Sopenharmony_ci    1 /* 0xb4 */, 1 /* 0xb5 */, 1 /* 0xb6 */, 1 /* 0xb7 */,
16131cb0ef41Sopenharmony_ci    1 /* 0xb8 */, 1 /* 0xb9 */, 1 /* 0xba */, 1 /* 0xbb */,
16141cb0ef41Sopenharmony_ci    1 /* 0xbc */, 1 /* 0xbd */, 1 /* 0xbe */, 1 /* 0xbf */,
16151cb0ef41Sopenharmony_ci    1 /* 0xc0 */, 1 /* 0xc1 */, 1 /* 0xc2 */, 1 /* 0xc3 */,
16161cb0ef41Sopenharmony_ci    1 /* 0xc4 */, 1 /* 0xc5 */, 1 /* 0xc6 */, 1 /* 0xc7 */,
16171cb0ef41Sopenharmony_ci    1 /* 0xc8 */, 1 /* 0xc9 */, 1 /* 0xca */, 1 /* 0xcb */,
16181cb0ef41Sopenharmony_ci    1 /* 0xcc */, 1 /* 0xcd */, 1 /* 0xce */, 1 /* 0xcf */,
16191cb0ef41Sopenharmony_ci    1 /* 0xd0 */, 1 /* 0xd1 */, 1 /* 0xd2 */, 1 /* 0xd3 */,
16201cb0ef41Sopenharmony_ci    1 /* 0xd4 */, 1 /* 0xd5 */, 1 /* 0xd6 */, 1 /* 0xd7 */,
16211cb0ef41Sopenharmony_ci    1 /* 0xd8 */, 1 /* 0xd9 */, 1 /* 0xda */, 1 /* 0xdb */,
16221cb0ef41Sopenharmony_ci    1 /* 0xdc */, 1 /* 0xdd */, 1 /* 0xde */, 1 /* 0xdf */,
16231cb0ef41Sopenharmony_ci    1 /* 0xe0 */, 1 /* 0xe1 */, 1 /* 0xe2 */, 1 /* 0xe3 */,
16241cb0ef41Sopenharmony_ci    1 /* 0xe4 */, 1 /* 0xe5 */, 1 /* 0xe6 */, 1 /* 0xe7 */,
16251cb0ef41Sopenharmony_ci    1 /* 0xe8 */, 1 /* 0xe9 */, 1 /* 0xea */, 1 /* 0xeb */,
16261cb0ef41Sopenharmony_ci    1 /* 0xec */, 1 /* 0xed */, 1 /* 0xee */, 1 /* 0xef */,
16271cb0ef41Sopenharmony_ci    1 /* 0xf0 */, 1 /* 0xf1 */, 1 /* 0xf2 */, 1 /* 0xf3 */,
16281cb0ef41Sopenharmony_ci    1 /* 0xf4 */, 1 /* 0xf5 */, 1 /* 0xf6 */, 1 /* 0xf7 */,
16291cb0ef41Sopenharmony_ci    1 /* 0xf8 */, 1 /* 0xf9 */, 1 /* 0xfa */, 1 /* 0xfb */,
16301cb0ef41Sopenharmony_ci    1 /* 0xfc */, 1 /* 0xfd */, 1 /* 0xfe */, 1 /* 0xff */
16311cb0ef41Sopenharmony_ci};
16321cb0ef41Sopenharmony_ci
16331cb0ef41Sopenharmony_ciint nghttp3_check_header_value(const uint8_t *value, size_t len) {
16341cb0ef41Sopenharmony_ci  const uint8_t *last;
16351cb0ef41Sopenharmony_ci
16361cb0ef41Sopenharmony_ci  switch (len) {
16371cb0ef41Sopenharmony_ci  case 0:
16381cb0ef41Sopenharmony_ci    return 1;
16391cb0ef41Sopenharmony_ci  case 1:
16401cb0ef41Sopenharmony_ci    return !(*value == ' ' || *value == '\t');
16411cb0ef41Sopenharmony_ci  default:
16421cb0ef41Sopenharmony_ci    if (*value == ' ' || *value == '\t' || *(value + len - 1) == ' ' ||
16431cb0ef41Sopenharmony_ci        *(value + len - 1) == '\t') {
16441cb0ef41Sopenharmony_ci      return 0;
16451cb0ef41Sopenharmony_ci    }
16461cb0ef41Sopenharmony_ci  }
16471cb0ef41Sopenharmony_ci
16481cb0ef41Sopenharmony_ci  for (last = value + len; value != last; ++value) {
16491cb0ef41Sopenharmony_ci    if (!VALID_HD_VALUE_CHARS[*value]) {
16501cb0ef41Sopenharmony_ci      return 0;
16511cb0ef41Sopenharmony_ci    }
16521cb0ef41Sopenharmony_ci  }
16531cb0ef41Sopenharmony_ci  return 1;
16541cb0ef41Sopenharmony_ci}
1655