11cb0ef41Sopenharmony_ci/* 21cb0ef41Sopenharmony_ci * nghttp2 - HTTP/2 C Library 31cb0ef41Sopenharmony_ci * 41cb0ef41Sopenharmony_ci * Copyright (c) 2013 Tatsuhiro Tsujikawa 51cb0ef41Sopenharmony_ci * 61cb0ef41Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining 71cb0ef41Sopenharmony_ci * a copy of this software and associated documentation files (the 81cb0ef41Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 91cb0ef41Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 101cb0ef41Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to 111cb0ef41Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 121cb0ef41Sopenharmony_ci * the following conditions: 131cb0ef41Sopenharmony_ci * 141cb0ef41Sopenharmony_ci * The above copyright notice and this permission notice shall be 151cb0ef41Sopenharmony_ci * included in all copies or substantial portions of the Software. 161cb0ef41Sopenharmony_ci * 171cb0ef41Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 181cb0ef41Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 191cb0ef41Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 201cb0ef41Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 211cb0ef41Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 221cb0ef41Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 231cb0ef41Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 241cb0ef41Sopenharmony_ci */ 251cb0ef41Sopenharmony_ci#ifndef NGHTTP2_HD_H 261cb0ef41Sopenharmony_ci#define NGHTTP2_HD_H 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci#ifdef HAVE_CONFIG_H 291cb0ef41Sopenharmony_ci# include <config.h> 301cb0ef41Sopenharmony_ci#endif /* HAVE_CONFIG_H */ 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci#include <nghttp2/nghttp2.h> 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci#include "nghttp2_hd_huffman.h" 351cb0ef41Sopenharmony_ci#include "nghttp2_buf.h" 361cb0ef41Sopenharmony_ci#include "nghttp2_mem.h" 371cb0ef41Sopenharmony_ci#include "nghttp2_rcbuf.h" 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci#define NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE NGHTTP2_DEFAULT_HEADER_TABLE_SIZE 401cb0ef41Sopenharmony_ci#define NGHTTP2_HD_ENTRY_OVERHEAD 32 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci/* The maximum length of one name/value pair. This is the sum of the 431cb0ef41Sopenharmony_ci length of name and value. This is not specified by the spec. We 441cb0ef41Sopenharmony_ci just chose the arbitrary size */ 451cb0ef41Sopenharmony_ci#define NGHTTP2_HD_MAX_NV 65536 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci/* Default size of maximum table buffer size for encoder. Even if 481cb0ef41Sopenharmony_ci remote decoder notifies larger buffer size for its decoding, 491cb0ef41Sopenharmony_ci encoder only uses the memory up to this value. */ 501cb0ef41Sopenharmony_ci#define NGHTTP2_HD_DEFAULT_MAX_DEFLATE_BUFFER_SIZE (1 << 12) 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci/* Exported for unit test */ 531cb0ef41Sopenharmony_ci#define NGHTTP2_STATIC_TABLE_LENGTH 61 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ci/* Generated by genlibtokenlookup.py */ 561cb0ef41Sopenharmony_citypedef enum { 571cb0ef41Sopenharmony_ci NGHTTP2_TOKEN__AUTHORITY = 0, 581cb0ef41Sopenharmony_ci NGHTTP2_TOKEN__METHOD = 1, 591cb0ef41Sopenharmony_ci NGHTTP2_TOKEN__PATH = 3, 601cb0ef41Sopenharmony_ci NGHTTP2_TOKEN__SCHEME = 5, 611cb0ef41Sopenharmony_ci NGHTTP2_TOKEN__STATUS = 7, 621cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_ACCEPT_CHARSET = 14, 631cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_ACCEPT_ENCODING = 15, 641cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_ACCEPT_LANGUAGE = 16, 651cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_ACCEPT_RANGES = 17, 661cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_ACCEPT = 18, 671cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_ACCESS_CONTROL_ALLOW_ORIGIN = 19, 681cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_AGE = 20, 691cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_ALLOW = 21, 701cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_AUTHORIZATION = 22, 711cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_CACHE_CONTROL = 23, 721cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_CONTENT_DISPOSITION = 24, 731cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_CONTENT_ENCODING = 25, 741cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_CONTENT_LANGUAGE = 26, 751cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_CONTENT_LENGTH = 27, 761cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_CONTENT_LOCATION = 28, 771cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_CONTENT_RANGE = 29, 781cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_CONTENT_TYPE = 30, 791cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_COOKIE = 31, 801cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_DATE = 32, 811cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_ETAG = 33, 821cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_EXPECT = 34, 831cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_EXPIRES = 35, 841cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_FROM = 36, 851cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_HOST = 37, 861cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_IF_MATCH = 38, 871cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_IF_MODIFIED_SINCE = 39, 881cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_IF_NONE_MATCH = 40, 891cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_IF_RANGE = 41, 901cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_IF_UNMODIFIED_SINCE = 42, 911cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_LAST_MODIFIED = 43, 921cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_LINK = 44, 931cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_LOCATION = 45, 941cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_MAX_FORWARDS = 46, 951cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_PROXY_AUTHENTICATE = 47, 961cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_PROXY_AUTHORIZATION = 48, 971cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_RANGE = 49, 981cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_REFERER = 50, 991cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_REFRESH = 51, 1001cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_RETRY_AFTER = 52, 1011cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_SERVER = 53, 1021cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_SET_COOKIE = 54, 1031cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_STRICT_TRANSPORT_SECURITY = 55, 1041cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_TRANSFER_ENCODING = 56, 1051cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_USER_AGENT = 57, 1061cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_VARY = 58, 1071cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_VIA = 59, 1081cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_WWW_AUTHENTICATE = 60, 1091cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_TE, 1101cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_CONNECTION, 1111cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_KEEP_ALIVE, 1121cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_PROXY_CONNECTION, 1131cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_UPGRADE, 1141cb0ef41Sopenharmony_ci NGHTTP2_TOKEN__PROTOCOL, 1151cb0ef41Sopenharmony_ci NGHTTP2_TOKEN_PRIORITY, 1161cb0ef41Sopenharmony_ci} nghttp2_token; 1171cb0ef41Sopenharmony_ci 1181cb0ef41Sopenharmony_cistruct nghttp2_hd_entry; 1191cb0ef41Sopenharmony_citypedef struct nghttp2_hd_entry nghttp2_hd_entry; 1201cb0ef41Sopenharmony_ci 1211cb0ef41Sopenharmony_citypedef struct { 1221cb0ef41Sopenharmony_ci /* The buffer containing header field name. NULL-termination is 1231cb0ef41Sopenharmony_ci guaranteed. */ 1241cb0ef41Sopenharmony_ci nghttp2_rcbuf *name; 1251cb0ef41Sopenharmony_ci /* The buffer containing header field value. NULL-termination is 1261cb0ef41Sopenharmony_ci guaranteed. */ 1271cb0ef41Sopenharmony_ci nghttp2_rcbuf *value; 1281cb0ef41Sopenharmony_ci /* nghttp2_token value for name. It could be -1 if we have no token 1291cb0ef41Sopenharmony_ci for that header field name. */ 1301cb0ef41Sopenharmony_ci int32_t token; 1311cb0ef41Sopenharmony_ci /* Bitwise OR of one or more of nghttp2_nv_flag. */ 1321cb0ef41Sopenharmony_ci uint8_t flags; 1331cb0ef41Sopenharmony_ci} nghttp2_hd_nv; 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_cistruct nghttp2_hd_entry { 1361cb0ef41Sopenharmony_ci /* The header field name/value pair */ 1371cb0ef41Sopenharmony_ci nghttp2_hd_nv nv; 1381cb0ef41Sopenharmony_ci /* This is solely for nghttp2_hd_{deflate,inflate}_get_table_entry 1391cb0ef41Sopenharmony_ci APIs to keep backward compatibility. */ 1401cb0ef41Sopenharmony_ci nghttp2_nv cnv; 1411cb0ef41Sopenharmony_ci /* The next entry which shares same bucket in hash table. */ 1421cb0ef41Sopenharmony_ci nghttp2_hd_entry *next; 1431cb0ef41Sopenharmony_ci /* The sequence number. We will increment it by one whenever we 1441cb0ef41Sopenharmony_ci store nghttp2_hd_entry to dynamic header table. */ 1451cb0ef41Sopenharmony_ci uint32_t seq; 1461cb0ef41Sopenharmony_ci /* The hash value for header name (nv.name). */ 1471cb0ef41Sopenharmony_ci uint32_t hash; 1481cb0ef41Sopenharmony_ci}; 1491cb0ef41Sopenharmony_ci 1501cb0ef41Sopenharmony_ci/* The entry used for static header table. */ 1511cb0ef41Sopenharmony_citypedef struct { 1521cb0ef41Sopenharmony_ci nghttp2_rcbuf name; 1531cb0ef41Sopenharmony_ci nghttp2_rcbuf value; 1541cb0ef41Sopenharmony_ci nghttp2_nv cnv; 1551cb0ef41Sopenharmony_ci int32_t token; 1561cb0ef41Sopenharmony_ci uint32_t hash; 1571cb0ef41Sopenharmony_ci} nghttp2_hd_static_entry; 1581cb0ef41Sopenharmony_ci 1591cb0ef41Sopenharmony_citypedef struct { 1601cb0ef41Sopenharmony_ci nghttp2_hd_entry **buffer; 1611cb0ef41Sopenharmony_ci size_t mask; 1621cb0ef41Sopenharmony_ci size_t first; 1631cb0ef41Sopenharmony_ci size_t len; 1641cb0ef41Sopenharmony_ci} nghttp2_hd_ringbuf; 1651cb0ef41Sopenharmony_ci 1661cb0ef41Sopenharmony_citypedef enum { 1671cb0ef41Sopenharmony_ci NGHTTP2_HD_OPCODE_NONE, 1681cb0ef41Sopenharmony_ci NGHTTP2_HD_OPCODE_INDEXED, 1691cb0ef41Sopenharmony_ci NGHTTP2_HD_OPCODE_NEWNAME, 1701cb0ef41Sopenharmony_ci NGHTTP2_HD_OPCODE_INDNAME 1711cb0ef41Sopenharmony_ci} nghttp2_hd_opcode; 1721cb0ef41Sopenharmony_ci 1731cb0ef41Sopenharmony_citypedef enum { 1741cb0ef41Sopenharmony_ci NGHTTP2_HD_STATE_EXPECT_TABLE_SIZE, 1751cb0ef41Sopenharmony_ci NGHTTP2_HD_STATE_INFLATE_START, 1761cb0ef41Sopenharmony_ci NGHTTP2_HD_STATE_OPCODE, 1771cb0ef41Sopenharmony_ci NGHTTP2_HD_STATE_READ_TABLE_SIZE, 1781cb0ef41Sopenharmony_ci NGHTTP2_HD_STATE_READ_INDEX, 1791cb0ef41Sopenharmony_ci NGHTTP2_HD_STATE_NEWNAME_CHECK_NAMELEN, 1801cb0ef41Sopenharmony_ci NGHTTP2_HD_STATE_NEWNAME_READ_NAMELEN, 1811cb0ef41Sopenharmony_ci NGHTTP2_HD_STATE_NEWNAME_READ_NAMEHUFF, 1821cb0ef41Sopenharmony_ci NGHTTP2_HD_STATE_NEWNAME_READ_NAME, 1831cb0ef41Sopenharmony_ci NGHTTP2_HD_STATE_CHECK_VALUELEN, 1841cb0ef41Sopenharmony_ci NGHTTP2_HD_STATE_READ_VALUELEN, 1851cb0ef41Sopenharmony_ci NGHTTP2_HD_STATE_READ_VALUEHUFF, 1861cb0ef41Sopenharmony_ci NGHTTP2_HD_STATE_READ_VALUE 1871cb0ef41Sopenharmony_ci} nghttp2_hd_inflate_state; 1881cb0ef41Sopenharmony_ci 1891cb0ef41Sopenharmony_citypedef enum { 1901cb0ef41Sopenharmony_ci NGHTTP2_HD_WITH_INDEXING, 1911cb0ef41Sopenharmony_ci NGHTTP2_HD_WITHOUT_INDEXING, 1921cb0ef41Sopenharmony_ci NGHTTP2_HD_NEVER_INDEXING 1931cb0ef41Sopenharmony_ci} nghttp2_hd_indexing_mode; 1941cb0ef41Sopenharmony_ci 1951cb0ef41Sopenharmony_citypedef struct { 1961cb0ef41Sopenharmony_ci /* dynamic header table */ 1971cb0ef41Sopenharmony_ci nghttp2_hd_ringbuf hd_table; 1981cb0ef41Sopenharmony_ci /* Memory allocator */ 1991cb0ef41Sopenharmony_ci nghttp2_mem *mem; 2001cb0ef41Sopenharmony_ci /* Abstract buffer size of hd_table as described in the spec. This 2011cb0ef41Sopenharmony_ci is the sum of length of name/value in hd_table + 2021cb0ef41Sopenharmony_ci NGHTTP2_HD_ENTRY_OVERHEAD bytes overhead per each entry. */ 2031cb0ef41Sopenharmony_ci size_t hd_table_bufsize; 2041cb0ef41Sopenharmony_ci /* The effective header table size. */ 2051cb0ef41Sopenharmony_ci size_t hd_table_bufsize_max; 2061cb0ef41Sopenharmony_ci /* Next sequence number for nghttp2_hd_entry */ 2071cb0ef41Sopenharmony_ci uint32_t next_seq; 2081cb0ef41Sopenharmony_ci /* If inflate/deflate error occurred, this value is set to 1 and 2091cb0ef41Sopenharmony_ci further invocation of inflate/deflate will fail with 2101cb0ef41Sopenharmony_ci NGHTTP2_ERR_HEADER_COMP. */ 2111cb0ef41Sopenharmony_ci uint8_t bad; 2121cb0ef41Sopenharmony_ci} nghttp2_hd_context; 2131cb0ef41Sopenharmony_ci 2141cb0ef41Sopenharmony_ci#define HD_MAP_SIZE 128 2151cb0ef41Sopenharmony_ci 2161cb0ef41Sopenharmony_citypedef struct { 2171cb0ef41Sopenharmony_ci nghttp2_hd_entry *table[HD_MAP_SIZE]; 2181cb0ef41Sopenharmony_ci} nghttp2_hd_map; 2191cb0ef41Sopenharmony_ci 2201cb0ef41Sopenharmony_cistruct nghttp2_hd_deflater { 2211cb0ef41Sopenharmony_ci nghttp2_hd_context ctx; 2221cb0ef41Sopenharmony_ci nghttp2_hd_map map; 2231cb0ef41Sopenharmony_ci /* The upper limit of the header table size the deflater accepts. */ 2241cb0ef41Sopenharmony_ci size_t deflate_hd_table_bufsize_max; 2251cb0ef41Sopenharmony_ci /* Minimum header table size notified in the next context update */ 2261cb0ef41Sopenharmony_ci size_t min_hd_table_bufsize_max; 2271cb0ef41Sopenharmony_ci /* If nonzero, send header table size using encoding context update 2281cb0ef41Sopenharmony_ci in the next deflate process */ 2291cb0ef41Sopenharmony_ci uint8_t notify_table_size_change; 2301cb0ef41Sopenharmony_ci}; 2311cb0ef41Sopenharmony_ci 2321cb0ef41Sopenharmony_cistruct nghttp2_hd_inflater { 2331cb0ef41Sopenharmony_ci nghttp2_hd_context ctx; 2341cb0ef41Sopenharmony_ci /* Stores current state of huffman decoding */ 2351cb0ef41Sopenharmony_ci nghttp2_hd_huff_decode_context huff_decode_ctx; 2361cb0ef41Sopenharmony_ci /* header buffer */ 2371cb0ef41Sopenharmony_ci nghttp2_buf namebuf, valuebuf; 2381cb0ef41Sopenharmony_ci nghttp2_rcbuf *namercbuf, *valuercbuf; 2391cb0ef41Sopenharmony_ci /* Pointer to the name/value pair which are used in the current 2401cb0ef41Sopenharmony_ci header emission. */ 2411cb0ef41Sopenharmony_ci nghttp2_rcbuf *nv_name_keep, *nv_value_keep; 2421cb0ef41Sopenharmony_ci /* The number of bytes to read */ 2431cb0ef41Sopenharmony_ci size_t left; 2441cb0ef41Sopenharmony_ci /* The index in indexed repr or indexed name */ 2451cb0ef41Sopenharmony_ci size_t index; 2461cb0ef41Sopenharmony_ci /* The maximum header table size the inflater supports. This is the 2471cb0ef41Sopenharmony_ci same value transmitted in SETTINGS_HEADER_TABLE_SIZE */ 2481cb0ef41Sopenharmony_ci size_t settings_hd_table_bufsize_max; 2491cb0ef41Sopenharmony_ci /* Minimum header table size set by nghttp2_hd_inflate_change_table_size */ 2501cb0ef41Sopenharmony_ci size_t min_hd_table_bufsize_max; 2511cb0ef41Sopenharmony_ci /* The number of next shift to decode integer */ 2521cb0ef41Sopenharmony_ci size_t shift; 2531cb0ef41Sopenharmony_ci nghttp2_hd_opcode opcode; 2541cb0ef41Sopenharmony_ci nghttp2_hd_inflate_state state; 2551cb0ef41Sopenharmony_ci /* nonzero if string is huffman encoded */ 2561cb0ef41Sopenharmony_ci uint8_t huffman_encoded; 2571cb0ef41Sopenharmony_ci /* nonzero if deflater requires that current entry is indexed */ 2581cb0ef41Sopenharmony_ci uint8_t index_required; 2591cb0ef41Sopenharmony_ci /* nonzero if deflater requires that current entry must not be 2601cb0ef41Sopenharmony_ci indexed */ 2611cb0ef41Sopenharmony_ci uint8_t no_index; 2621cb0ef41Sopenharmony_ci}; 2631cb0ef41Sopenharmony_ci 2641cb0ef41Sopenharmony_ci/* 2651cb0ef41Sopenharmony_ci * Initializes the |ent| members. The reference counts of nv->name 2661cb0ef41Sopenharmony_ci * and nv->value are increased by one for each. 2671cb0ef41Sopenharmony_ci */ 2681cb0ef41Sopenharmony_civoid nghttp2_hd_entry_init(nghttp2_hd_entry *ent, nghttp2_hd_nv *nv); 2691cb0ef41Sopenharmony_ci 2701cb0ef41Sopenharmony_ci/* 2711cb0ef41Sopenharmony_ci * This function decreases the reference counts of nv->name and 2721cb0ef41Sopenharmony_ci * nv->value. 2731cb0ef41Sopenharmony_ci */ 2741cb0ef41Sopenharmony_civoid nghttp2_hd_entry_free(nghttp2_hd_entry *ent); 2751cb0ef41Sopenharmony_ci 2761cb0ef41Sopenharmony_ci/* 2771cb0ef41Sopenharmony_ci * Initializes |deflater| for deflating name/values pairs. 2781cb0ef41Sopenharmony_ci * 2791cb0ef41Sopenharmony_ci * The encoder only uses up to 2801cb0ef41Sopenharmony_ci * NGHTTP2_HD_DEFAULT_MAX_DEFLATE_BUFFER_SIZE bytes for header table 2811cb0ef41Sopenharmony_ci * even if the larger value is specified later in 2821cb0ef41Sopenharmony_ci * nghttp2_hd_change_table_size(). 2831cb0ef41Sopenharmony_ci * 2841cb0ef41Sopenharmony_ci * This function returns 0 if it succeeds, or one of the following 2851cb0ef41Sopenharmony_ci * negative error codes: 2861cb0ef41Sopenharmony_ci * 2871cb0ef41Sopenharmony_ci * NGHTTP2_ERR_NOMEM 2881cb0ef41Sopenharmony_ci * Out of memory. 2891cb0ef41Sopenharmony_ci */ 2901cb0ef41Sopenharmony_ciint nghttp2_hd_deflate_init(nghttp2_hd_deflater *deflater, nghttp2_mem *mem); 2911cb0ef41Sopenharmony_ci 2921cb0ef41Sopenharmony_ci/* 2931cb0ef41Sopenharmony_ci * Initializes |deflater| for deflating name/values pairs. 2941cb0ef41Sopenharmony_ci * 2951cb0ef41Sopenharmony_ci * The encoder only uses up to |max_deflate_dynamic_table_size| bytes 2961cb0ef41Sopenharmony_ci * for header table even if the larger value is specified later in 2971cb0ef41Sopenharmony_ci * nghttp2_hd_change_table_size(). 2981cb0ef41Sopenharmony_ci * 2991cb0ef41Sopenharmony_ci * This function returns 0 if it succeeds, or one of the following 3001cb0ef41Sopenharmony_ci * negative error codes: 3011cb0ef41Sopenharmony_ci * 3021cb0ef41Sopenharmony_ci * NGHTTP2_ERR_NOMEM 3031cb0ef41Sopenharmony_ci * Out of memory. 3041cb0ef41Sopenharmony_ci */ 3051cb0ef41Sopenharmony_ciint nghttp2_hd_deflate_init2(nghttp2_hd_deflater *deflater, 3061cb0ef41Sopenharmony_ci size_t max_deflate_dynamic_table_size, 3071cb0ef41Sopenharmony_ci nghttp2_mem *mem); 3081cb0ef41Sopenharmony_ci 3091cb0ef41Sopenharmony_ci/* 3101cb0ef41Sopenharmony_ci * Deallocates any resources allocated for |deflater|. 3111cb0ef41Sopenharmony_ci */ 3121cb0ef41Sopenharmony_civoid nghttp2_hd_deflate_free(nghttp2_hd_deflater *deflater); 3131cb0ef41Sopenharmony_ci 3141cb0ef41Sopenharmony_ci/* 3151cb0ef41Sopenharmony_ci * Deflates the |nva|, which has the |nvlen| name/value pairs, into 3161cb0ef41Sopenharmony_ci * the |bufs|. 3171cb0ef41Sopenharmony_ci * 3181cb0ef41Sopenharmony_ci * This function expands |bufs| as necessary to store the result. If 3191cb0ef41Sopenharmony_ci * buffers is full and the process still requires more space, this 3201cb0ef41Sopenharmony_ci * function fails and returns NGHTTP2_ERR_HEADER_COMP. 3211cb0ef41Sopenharmony_ci * 3221cb0ef41Sopenharmony_ci * After this function returns, it is safe to delete the |nva|. 3231cb0ef41Sopenharmony_ci * 3241cb0ef41Sopenharmony_ci * This function returns 0 if it succeeds, or one of the following 3251cb0ef41Sopenharmony_ci * negative error codes: 3261cb0ef41Sopenharmony_ci * 3271cb0ef41Sopenharmony_ci * NGHTTP2_ERR_NOMEM 3281cb0ef41Sopenharmony_ci * Out of memory. 3291cb0ef41Sopenharmony_ci * NGHTTP2_ERR_HEADER_COMP 3301cb0ef41Sopenharmony_ci * Deflation process has failed. 3311cb0ef41Sopenharmony_ci * NGHTTP2_ERR_BUFFER_ERROR 3321cb0ef41Sopenharmony_ci * Out of buffer space. 3331cb0ef41Sopenharmony_ci */ 3341cb0ef41Sopenharmony_ciint nghttp2_hd_deflate_hd_bufs(nghttp2_hd_deflater *deflater, 3351cb0ef41Sopenharmony_ci nghttp2_bufs *bufs, const nghttp2_nv *nva, 3361cb0ef41Sopenharmony_ci size_t nvlen); 3371cb0ef41Sopenharmony_ci 3381cb0ef41Sopenharmony_ci/* 3391cb0ef41Sopenharmony_ci * Initializes |inflater| for inflating name/values pairs. 3401cb0ef41Sopenharmony_ci * 3411cb0ef41Sopenharmony_ci * This function returns 0 if it succeeds, or one of the following 3421cb0ef41Sopenharmony_ci * negative error codes: 3431cb0ef41Sopenharmony_ci * 3441cb0ef41Sopenharmony_ci * :enum:`NGHTTP2_ERR_NOMEM` 3451cb0ef41Sopenharmony_ci * Out of memory. 3461cb0ef41Sopenharmony_ci */ 3471cb0ef41Sopenharmony_ciint nghttp2_hd_inflate_init(nghttp2_hd_inflater *inflater, nghttp2_mem *mem); 3481cb0ef41Sopenharmony_ci 3491cb0ef41Sopenharmony_ci/* 3501cb0ef41Sopenharmony_ci * Deallocates any resources allocated for |inflater|. 3511cb0ef41Sopenharmony_ci */ 3521cb0ef41Sopenharmony_civoid nghttp2_hd_inflate_free(nghttp2_hd_inflater *inflater); 3531cb0ef41Sopenharmony_ci 3541cb0ef41Sopenharmony_ci/* 3551cb0ef41Sopenharmony_ci * Similar to nghttp2_hd_inflate_hd(), but this takes nghttp2_hd_nv 3561cb0ef41Sopenharmony_ci * instead of nghttp2_nv as output parameter |nv_out|. Other than 3571cb0ef41Sopenharmony_ci * that return values and semantics are the same as 3581cb0ef41Sopenharmony_ci * nghttp2_hd_inflate_hd(). 3591cb0ef41Sopenharmony_ci */ 3601cb0ef41Sopenharmony_cissize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, 3611cb0ef41Sopenharmony_ci nghttp2_hd_nv *nv_out, int *inflate_flags, 3621cb0ef41Sopenharmony_ci const uint8_t *in, size_t inlen, int in_final); 3631cb0ef41Sopenharmony_ci 3641cb0ef41Sopenharmony_ci/* For unittesting purpose */ 3651cb0ef41Sopenharmony_ciint nghttp2_hd_emit_indname_block(nghttp2_bufs *bufs, size_t index, 3661cb0ef41Sopenharmony_ci nghttp2_nv *nv, int indexing_mode); 3671cb0ef41Sopenharmony_ci 3681cb0ef41Sopenharmony_ci/* For unittesting purpose */ 3691cb0ef41Sopenharmony_ciint nghttp2_hd_emit_newname_block(nghttp2_bufs *bufs, nghttp2_nv *nv, 3701cb0ef41Sopenharmony_ci int indexing_mode); 3711cb0ef41Sopenharmony_ci 3721cb0ef41Sopenharmony_ci/* For unittesting purpose */ 3731cb0ef41Sopenharmony_ciint nghttp2_hd_emit_table_size(nghttp2_bufs *bufs, size_t table_size); 3741cb0ef41Sopenharmony_ci 3751cb0ef41Sopenharmony_ci/* For unittesting purpose */ 3761cb0ef41Sopenharmony_cinghttp2_hd_nv nghttp2_hd_table_get(nghttp2_hd_context *context, size_t index); 3771cb0ef41Sopenharmony_ci 3781cb0ef41Sopenharmony_ci/* For unittesting purpose */ 3791cb0ef41Sopenharmony_cissize_t nghttp2_hd_decode_length(uint32_t *res, size_t *shift_ptr, int *fin, 3801cb0ef41Sopenharmony_ci uint32_t initial, size_t shift, uint8_t *in, 3811cb0ef41Sopenharmony_ci uint8_t *last, size_t prefix); 3821cb0ef41Sopenharmony_ci 3831cb0ef41Sopenharmony_ci/* Huffman encoding/decoding functions */ 3841cb0ef41Sopenharmony_ci 3851cb0ef41Sopenharmony_ci/* 3861cb0ef41Sopenharmony_ci * Counts the required bytes to encode |src| with length |len|. 3871cb0ef41Sopenharmony_ci * 3881cb0ef41Sopenharmony_ci * This function returns the number of required bytes to encode given 3891cb0ef41Sopenharmony_ci * data, including padding of prefix of terminal symbol code. This 3901cb0ef41Sopenharmony_ci * function always succeeds. 3911cb0ef41Sopenharmony_ci */ 3921cb0ef41Sopenharmony_cisize_t nghttp2_hd_huff_encode_count(const uint8_t *src, size_t len); 3931cb0ef41Sopenharmony_ci 3941cb0ef41Sopenharmony_ci/* 3951cb0ef41Sopenharmony_ci * Encodes the given data |src| with length |srclen| to the |bufs|. 3961cb0ef41Sopenharmony_ci * This function expands extra buffers in |bufs| if necessary. 3971cb0ef41Sopenharmony_ci * 3981cb0ef41Sopenharmony_ci * This function returns 0 if it succeeds, or one of the following 3991cb0ef41Sopenharmony_ci * negative error codes: 4001cb0ef41Sopenharmony_ci * 4011cb0ef41Sopenharmony_ci * NGHTTP2_ERR_NOMEM 4021cb0ef41Sopenharmony_ci * Out of memory. 4031cb0ef41Sopenharmony_ci * NGHTTP2_ERR_BUFFER_ERROR 4041cb0ef41Sopenharmony_ci * Out of buffer space. 4051cb0ef41Sopenharmony_ci */ 4061cb0ef41Sopenharmony_ciint nghttp2_hd_huff_encode(nghttp2_bufs *bufs, const uint8_t *src, 4071cb0ef41Sopenharmony_ci size_t srclen); 4081cb0ef41Sopenharmony_ci 4091cb0ef41Sopenharmony_civoid nghttp2_hd_huff_decode_context_init(nghttp2_hd_huff_decode_context *ctx); 4101cb0ef41Sopenharmony_ci 4111cb0ef41Sopenharmony_ci/* 4121cb0ef41Sopenharmony_ci * Decodes the given data |src| with length |srclen|. The |ctx| must 4131cb0ef41Sopenharmony_ci * be initialized by nghttp2_hd_huff_decode_context_init(). The result 4141cb0ef41Sopenharmony_ci * will be written to |buf|. This function assumes that |buf| has the 4151cb0ef41Sopenharmony_ci * enough room to store the decoded byte string. 4161cb0ef41Sopenharmony_ci * 4171cb0ef41Sopenharmony_ci * The caller must set the |fin| to nonzero if the given input is the 4181cb0ef41Sopenharmony_ci * final block. 4191cb0ef41Sopenharmony_ci * 4201cb0ef41Sopenharmony_ci * This function returns the number of read bytes from the |in|. 4211cb0ef41Sopenharmony_ci * 4221cb0ef41Sopenharmony_ci * If this function fails, it returns one of the following negative 4231cb0ef41Sopenharmony_ci * return codes: 4241cb0ef41Sopenharmony_ci * 4251cb0ef41Sopenharmony_ci * NGHTTP2_ERR_NOMEM 4261cb0ef41Sopenharmony_ci * Out of memory. 4271cb0ef41Sopenharmony_ci * NGHTTP2_ERR_HEADER_COMP 4281cb0ef41Sopenharmony_ci * Decoding process has failed. 4291cb0ef41Sopenharmony_ci */ 4301cb0ef41Sopenharmony_cissize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx, 4311cb0ef41Sopenharmony_ci nghttp2_buf *buf, const uint8_t *src, 4321cb0ef41Sopenharmony_ci size_t srclen, int fin); 4331cb0ef41Sopenharmony_ci 4341cb0ef41Sopenharmony_ci/* 4351cb0ef41Sopenharmony_ci * nghttp2_hd_huff_decode_failure_state returns nonzero if |ctx| 4361cb0ef41Sopenharmony_ci * indicates that huffman decoding context is in failure state. 4371cb0ef41Sopenharmony_ci */ 4381cb0ef41Sopenharmony_ciint nghttp2_hd_huff_decode_failure_state(nghttp2_hd_huff_decode_context *ctx); 4391cb0ef41Sopenharmony_ci 4401cb0ef41Sopenharmony_ci#endif /* NGHTTP2_HD_H */ 441