deps: update nghttp3 to 1.16.0

PR-URL: https://github.com/nodejs/node/pull/63776
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
Node.js GitHub Bot authored and GitHub committed 2026-06-09 02:06:44 +00:00
1 parent e163a67e09
commit 28b5baae64
34 files changed
+2215 -1907

No files matched your search

+265 -67
View File
@@ -86,8 +86,9 @@ typedef ptrdiff_t nghttp3_ssize;
*
* :type:`nghttp3_tstamp` is a timestamp with nanosecond resolution.
* ``UINT64_MAX`` is an invalid value, and it is often used to
* indicate that no value is set. This type is available since
* v1.12.0.
* indicate that no value is set.
*
* .. version-added:: 1.12.0
*/
typedef uint64_t nghttp3_tstamp;
@@ -96,8 +97,9 @@ typedef uint64_t nghttp3_tstamp;
*
* :type:`nghttp3_duration` is a period of time in nanosecond
* resolution. ``UINT64_MAX`` is an invalid value, and it is often
* used to indicate that no value is set. This type is available
* since v1.12.0.
* used to indicate that no value is set.
*
* .. version-added:: 1.12.0.
*/
typedef uint64_t nghttp3_duration;
@@ -105,7 +107,9 @@ typedef uint64_t nghttp3_duration;
* @macro
*
* :macro:`NGHTTP3_NANOSECONDS` is a count of tick which corresponds
* to 1 nanosecond. This macro is available since v1.12.0.
* to 1 nanosecond.
*
* .. version-added:: 1.12.0
*/
#define NGHTTP3_NANOSECONDS ((nghttp3_duration)1ULL)
@@ -113,7 +117,9 @@ typedef uint64_t nghttp3_duration;
* @macro
*
* :macro:`NGHTTP3_MICROSECONDS` is a count of tick which corresponds
* to 1 microsecond. This macro is available since v1.12.0.
* to 1 microsecond.
*
* .. version-added:: 1.12.0
*/
#define NGHTTP3_MICROSECONDS ((nghttp3_duration)(1000ULL * NGHTTP3_NANOSECONDS))
@@ -121,7 +127,9 @@ typedef uint64_t nghttp3_duration;
* @macro
*
* :macro:`NGHTTP3_MILLISECONDS` is a count of tick which corresponds
* to 1 millisecond. This macro is available since v1.12.0.
* to 1 millisecond.
*
* .. version-added:: 1.12.0
*/
#define NGHTTP3_MILLISECONDS \
((nghttp3_duration)(1000ULL * NGHTTP3_MICROSECONDS))
@@ -130,7 +138,9 @@ typedef uint64_t nghttp3_duration;
* @macro
*
* :macro:`NGHTTP3_SECONDS` is a count of tick which corresponds to 1
* second. This macro is available since v1.12.0.
* second.
*
* .. version-added:: 1.12.0
*/
#define NGHTTP3_SECONDS ((nghttp3_duration)(1000ULL * NGHTTP3_MILLISECONDS))
@@ -429,42 +439,42 @@ typedef uint64_t nghttp3_duration;
* :macro:`NGHTTP3_H3_MISSING_SETTINGS` is HTTP/3 application error
* code ``H3_MISSING_SETTINGS``.
*/
#define NGHTTP3_H3_MISSING_SETTINGS 0x010a
#define NGHTTP3_H3_MISSING_SETTINGS 0x010A
/**
* @macro
*
* :macro:`NGHTTP3_H3_REQUEST_REJECTED` is HTTP/3 application error
* code ``H3_REQUEST_REJECTED``.
*/
#define NGHTTP3_H3_REQUEST_REJECTED 0x010b
#define NGHTTP3_H3_REQUEST_REJECTED 0x010B
/**
* @macro
*
* :macro:`NGHTTP3_H3_REQUEST_CANCELLED` is HTTP/3 application error
* code ``H3_REQUEST_CANCELLED``.
*/
#define NGHTTP3_H3_REQUEST_CANCELLED 0x010c
#define NGHTTP3_H3_REQUEST_CANCELLED 0x010C
/**
* @macro
*
* :macro:`NGHTTP3_H3_REQUEST_INCOMPLETE` is HTTP/3 application error
* code ``H3_REQUEST_INCOMPLETE``.
*/
#define NGHTTP3_H3_REQUEST_INCOMPLETE 0x010d
#define NGHTTP3_H3_REQUEST_INCOMPLETE 0x010D
/**
* @macro
*
* :macro:`NGHTTP3_H3_MESSAGE_ERROR` is HTTP/3 application error code
* ``H3_MESSAGE_ERROR``.
*/
#define NGHTTP3_H3_MESSAGE_ERROR 0x010e
#define NGHTTP3_H3_MESSAGE_ERROR 0x010E
/**
* @macro
*
* :macro:`NGHTTP3_H3_CONNECT_ERROR` is HTTP/3 application error code
* ``H3_CONNECT_ERROR``.
*/
#define NGHTTP3_H3_CONNECT_ERROR 0x010f
#define NGHTTP3_H3_CONNECT_ERROR 0x010F
/**
* @macro
*
@@ -753,7 +763,7 @@ NGHTTP3_EXTERN void nghttp3_buf_reset(nghttp3_buf *buf);
*
* :macro:`NGHTTP3_NV_FLAG_NONE` indicates no flag set.
*/
#define NGHTTP3_NV_FLAG_NONE 0x00u
#define NGHTTP3_NV_FLAG_NONE 0x00U
/**
* @macro
@@ -762,7 +772,7 @@ NGHTTP3_EXTERN void nghttp3_buf_reset(nghttp3_buf *buf);
* pair must not be indexed. Other implementation calls this bit as
* "sensitive".
*/
#define NGHTTP3_NV_FLAG_NEVER_INDEX 0x01u
#define NGHTTP3_NV_FLAG_NEVER_INDEX 0x01U
/**
* @macro
@@ -771,7 +781,7 @@ NGHTTP3_EXTERN void nghttp3_buf_reset(nghttp3_buf *buf);
* If this flag is set, the library does not make a copy of field
* name. This could improve performance.
*/
#define NGHTTP3_NV_FLAG_NO_COPY_NAME 0x02u
#define NGHTTP3_NV_FLAG_NO_COPY_NAME 0x02U
/**
* @macro
@@ -780,7 +790,7 @@ NGHTTP3_EXTERN void nghttp3_buf_reset(nghttp3_buf *buf);
* application. If this flag is set, the library does not make a copy
* of field value. This could improve performance.
*/
#define NGHTTP3_NV_FLAG_NO_COPY_VALUE 0x04u
#define NGHTTP3_NV_FLAG_NO_COPY_VALUE 0x04U
/**
* @macro
@@ -790,7 +800,7 @@ NGHTTP3_EXTERN void nghttp3_buf_reset(nghttp3_buf *buf);
* a hint, and QPACK encoder might not encode the field in various
* reasons.
*/
#define NGHTTP3_NV_FLAG_TRY_INDEX 0x08u
#define NGHTTP3_NV_FLAG_TRY_INDEX 0x08U
/**
* @struct
@@ -1156,8 +1166,9 @@ typedef struct nghttp3_qpack_nv {
*
* :type:`nghttp3_qpack_indexing_strat` defines the QPACK dynamic
* table indexing strategies for fields not defined in
* :type:`nghttp3_qpack_token`. This type is available since v1.13.0.
* :type:`nghttp3_qpack_token`.
*
* .. version-added:: 1.13.0
*/
typedef enum nghttp3_qpack_indexing_strat {
/**
@@ -1165,14 +1176,16 @@ typedef enum nghttp3_qpack_indexing_strat {
* fields not defined in :type:`nghttp3_qpack_token`. This is the
* default strategy. You can still use
* :macro:`NGHTTP3_NV_FLAG_TRY_INDEX` to index a particular field.
* This enum is available since v1.13.0.
*
* .. version-added:: 1.13.0
*/
NGHTTP3_QPACK_INDEXING_STRAT_NONE,
/**
* :enum:`NGHTTP3_QPACK_INDEXING_STRAT_EAGER` indexes all fields not
* defined in :type:`nghttp3_qpack_token`. Please note that QPACK
* encoder might not index the field in various reasons. This enum
* is available since v1.13.0.
* encoder might not index the field in various reasons.
*
* .. version-added:: 1.13.0
*/
NGHTTP3_QPACK_INDEXING_STRAT_EAGER
} nghttp3_qpack_indexing_strat;
@@ -1233,7 +1246,7 @@ NGHTTP3_EXTERN int nghttp3_qpack_encoder_new(nghttp3_qpack_encoder **pencoder,
* :macro:`NGHTTP3_ERR_NOMEM`
* Out of memory.
*
* This function is available since v1.11.0.
* .. version-added:: 1.11.0
*/
NGHTTP3_EXTERN int nghttp3_qpack_encoder_new2(nghttp3_qpack_encoder **pencoder,
size_t hard_max_dtable_capacity,
@@ -1329,9 +1342,9 @@ nghttp3_qpack_encoder_set_max_blocked_streams(nghttp3_qpack_encoder *encoder,
* @function
*
* `nghttp3_qpack_encoder_set_indexing_strat` sets the dynamic table
* indexing strategy |strat| to |encoder|. This function is available
* since v1.13.0.
* indexing strategy |strat| to |encoder|.
*
* .. version-added:: 1.13.0
*/
NGHTTP3_EXTERN void
nghttp3_qpack_encoder_set_indexing_strat(nghttp3_qpack_encoder *encoder,
@@ -1352,12 +1365,28 @@ nghttp3_qpack_encoder_ack_everything(nghttp3_qpack_encoder *encoder);
/**
* @function
*
* .. warning::
*
* .. version-deprecated:: 1.16.0
* Use `nghttp3_qpack_encoder_get_num_blocked_streams2` instead.
*
* `nghttp3_qpack_encoder_get_num_blocked_streams` returns the number
* of streams which are potentially blocked at decoder side.
*/
NGHTTP3_EXTERN size_t
nghttp3_qpack_encoder_get_num_blocked_streams(nghttp3_qpack_encoder *encoder);
/**
* @function
*
* `nghttp3_qpack_encoder_get_num_blocked_streams2` returns the number
* of streams which are potentially blocked at decoder side.
*
* .. version-added:: 1.16.0
*/
NGHTTP3_EXTERN size_t nghttp3_qpack_encoder_get_num_blocked_streams2(
const nghttp3_qpack_encoder *encoder);
/**
* @struct
*
@@ -1401,12 +1430,26 @@ nghttp3_qpack_stream_context_del(nghttp3_qpack_stream_context *sctx);
/**
* @function
*
* .. warning::
*
* .. version-deprecated:: 1.16.0
* Use `nghttp3_qpack_stream_context_get_ricnt2` instead.
*
* `nghttp3_qpack_stream_context_get_ricnt` returns required insert
* count.
*/
NGHTTP3_EXTERN uint64_t
nghttp3_qpack_stream_context_get_ricnt(nghttp3_qpack_stream_context *sctx);
/**
* @function
*
* `nghttp3_qpack_stream_context_get_ricnt2` returns required insert
* count.
*/
NGHTTP3_EXTERN uint64_t nghttp3_qpack_stream_context_get_ricnt2(
const nghttp3_qpack_stream_context *sctx);
/**
* @function
*
@@ -1495,7 +1538,7 @@ nghttp3_qpack_decoder_get_icnt(const nghttp3_qpack_decoder *decoder);
*
* :macro:`NGHTTP3_QPACK_DECODE_FLAG_NONE` indicates that no flag set.
*/
#define NGHTTP3_QPACK_DECODE_FLAG_NONE 0x00u
#define NGHTTP3_QPACK_DECODE_FLAG_NONE 0x00U
/**
* @macro
@@ -1503,7 +1546,7 @@ nghttp3_qpack_decoder_get_icnt(const nghttp3_qpack_decoder *decoder);
* :macro:`NGHTTP3_QPACK_DECODE_FLAG_EMIT` indicates that an HTTP
* field is successfully decoded.
*/
#define NGHTTP3_QPACK_DECODE_FLAG_EMIT 0x01u
#define NGHTTP3_QPACK_DECODE_FLAG_EMIT 0x01U
/**
* @macro
@@ -1511,7 +1554,7 @@ nghttp3_qpack_decoder_get_icnt(const nghttp3_qpack_decoder *decoder);
* :macro:`NGHTTP3_QPACK_DECODE_FLAG_FINAL` indicates that an entire
* HTTP field section has been decoded.
*/
#define NGHTTP3_QPACK_DECODE_FLAG_FINAL 0x02u
#define NGHTTP3_QPACK_DECODE_FLAG_FINAL 0x02U
/**
* @macro
@@ -1519,7 +1562,7 @@ nghttp3_qpack_decoder_get_icnt(const nghttp3_qpack_decoder *decoder);
* :macro:`NGHTTP3_QPACK_DECODE_FLAG_BLOCKED` indicates that decoding
* has been blocked.
*/
#define NGHTTP3_QPACK_DECODE_FLAG_BLOCKED 0x04u
#define NGHTTP3_QPACK_DECODE_FLAG_BLOCKED 0x04U
/**
* @function
@@ -1579,8 +1622,8 @@ NGHTTP3_EXTERN nghttp3_ssize nghttp3_qpack_decoder_read_request(
*
* The caller must ensure that `nghttp3_buf_left(dbuf)
* <nghttp3_buf_left>` >=
* `nghttp3_qpack_decoder_get_decoder_streamlen(decoder)
* <nghttp3_qpack_decoder_get_decoder_streamlen>`.
* `nghttp3_qpack_decoder_get_decoder_streamlen2(decoder)
* <nghttp3_qpack_decoder_get_decoder_streamlen2>`.
*/
NGHTTP3_EXTERN void
nghttp3_qpack_decoder_write_decoder(nghttp3_qpack_decoder *decoder,
@@ -1589,12 +1632,28 @@ nghttp3_qpack_decoder_write_decoder(nghttp3_qpack_decoder *decoder,
/**
* @function
*
* .. warning::
*
* .. version-deprecated:: 1.16.0
* Use `nghttp3_qpack_decoder_get_decoder_streamlen2` instead.
*
* `nghttp3_qpack_decoder_get_decoder_streamlen` returns the length of
* decoder stream that is currently pending.
*/
NGHTTP3_EXTERN size_t
nghttp3_qpack_decoder_get_decoder_streamlen(nghttp3_qpack_decoder *decoder);
/**
* @function
*
* `nghttp3_qpack_decoder_get_decoder_streamlen2` returns the length
* of decoder stream that is currently pending.
*
* .. version-added:: 1.16.0
*/
NGHTTP3_EXTERN size_t nghttp3_qpack_decoder_get_decoder_streamlen2(
const nghttp3_qpack_decoder *decoder);
/**
* @function
*
@@ -1714,7 +1773,7 @@ NGHTTP3_EXTERN void nghttp3_set_debug_vprintf_callback(
* by a server when it initiates graceful shutdown of the connection
* via `nghttp3_conn_submit_shutdown_notice`.
*/
#define NGHTTP3_SHUTDOWN_NOTICE_STREAM_ID ((1ull << 62) - 4)
#define NGHTTP3_SHUTDOWN_NOTICE_STREAM_ID ((1ULL << 62) - 4)
/**
* @macro
@@ -1724,7 +1783,7 @@ NGHTTP3_EXTERN void nghttp3_set_debug_vprintf_callback(
* `nghttp3_conn_submit_shutdown_notice`. Note that libnghttp3 does
* not implement HTTP/3 Server Push.
*/
#define NGHTTP3_SHUTDOWN_NOTICE_PUSH_ID ((1ull << 62) - 1)
#define NGHTTP3_SHUTDOWN_NOTICE_PUSH_ID ((1ULL << 62) - 1)
/**
* @struct
@@ -1790,7 +1849,8 @@ typedef struct nghttp3_settings {
* Datagrams (see :rfc:`9297`).
*/
uint8_t h3_datagram;
/* The following fields have been added since NGHTTP3_SETTINGS_V2. */
/* The following fields have been added since
NGHTTP3_SETTINGS_V2. */
/**
* :member:`origin_list`, if set, must contain a serialized HTTP/3
* ORIGIN frame (see :rfc:`9412`) payload. The ORIGIN frame payload
@@ -1802,10 +1862,13 @@ typedef struct nghttp3_settings {
* until the :type:`nghttp3_conn` to which this field was passed is
* freed by `nghttp3_conn_del`. The object pointed to by this field
* is copied internally, and does not need to be kept alive. Only
* server uses this field. This field is available since v1.11.0.
* server uses this field.
*
* .. version-added:: 1.11.0
*/
const nghttp3_vec *origin_list;
/* The following fields have been added since NGHTTP3_SETTINGS_V3. */
/* The following fields have been added since
NGHTTP3_SETTINGS_V3. */
/**
* :member:`glitch_ratelim_burst` is the maximum number of tokens
* available to "glitch" rate limiter. "glitch" is a suspicious
@@ -1813,21 +1876,27 @@ typedef struct nghttp3_settings {
* tokens are consumed. If no tokens are available to consume, the
* connection is closed. The rate of token generation is specified
* by :member:`glitch_ratelim_rate`. This feature is enabled only
* when `nghttp3_conn_read_stream2` is used. This field has been
* available since v1.12.0.
* when `nghttp3_conn_read_stream2` is used.
*
* .. version-added:: 1.12.0
*/
uint64_t glitch_ratelim_burst;
/**
* :member:`glitch_ratelim_rate` is the number of tokens generated
* per second. See :member:`glitch_ratelim_burst` for "glitch" rate
* limiter. This field has been available since v1.12.0.
* limiter.
*
* .. version-added:: 1.12.0
*/
uint64_t glitch_ratelim_rate;
/* The following fields have been added since
NGHTTP3_SETTINGS_V4. */
/**
* :member:`qpack_indexing_strat` defines the QPACK dynamic table
* indexing strategy for those fields that are not defined in
* :type:`nghttp3_qpack_token`. This field has been available since
* v1.13.0.
* :type:`nghttp3_qpack_token`.
*
* .. version-added:: 1.13.0
*/
nghttp3_qpack_indexing_strat qpack_indexing_strat;
} nghttp3_settings;
@@ -1839,7 +1908,9 @@ typedef struct nghttp3_settings {
* @struct
*
* :type:`nghttp3_proto_settings` contains HTTP/3 settings that this
* library can recognize. This field is available since v1.14.0.
* library can recognize.
*
* .. version-added:: 1.14.0
*/
typedef struct nghttp3_proto_settings {
/**
@@ -2096,8 +2167,9 @@ typedef int (*nghttp3_shutdown)(nghttp3_conn *conn, int64_t id,
*
* .. warning::
*
* Deprecated since v1.14.0. Use :type:`nghttp3_recv_settings2`
* instead. New settings will not be notified with this callback.
* .. version-deprecated:: 1.14.0
* Use :type:`nghttp3_recv_settings2` instead. New settings will
* not be notified with this callback.
*
* :type:`nghttp3_recv_settings` is a callback function which is
* invoked when SETTINGS frame is received. |settings| is a received
@@ -2160,8 +2232,9 @@ typedef void (*nghttp3_rand)(uint8_t *dest, size_t destlen);
* The implementation of this callback must return 0 if it succeeds.
* Returning :macro:`NGHTTP3_ERR_CALLBACK_FAILURE` will return to the
* caller immediately. Any values other than 0 is treated as
* :macro:`NGHTTP3_ERR_CALLBACK_FAILURE`. This callback is available
* since v1.14.0.
* :macro:`NGHTTP3_ERR_CALLBACK_FAILURE`.
*
* .. version-added:: 1.14.0
*/
typedef int (*nghttp3_recv_settings2)(nghttp3_conn *conn,
const nghttp3_proto_settings *settings,
@@ -2262,24 +2335,27 @@ typedef struct nghttp3_callbacks {
/**
* .. warning::
*
* Deprecated since v1.14.0. Use :member:`recv_settings2`
* instead.
* .. version-deprecated:: 1.14.0
* Use :member:`recv_settings2` instead.
*
* :member:`recv_settings` is a callback function which is invoked
* when SETTINGS frame is received.
*/
nghttp3_recv_settings recv_settings;
/* The following fields have been added since NGHTTP3_CALLBACKS_V2. */
/* The following fields have been added since
NGHTTP3_CALLBACKS_V2. */
/**
* :member:`recv_origin` is a callback function which is invoked
* when a single origin in an ORIGIN frame is received. This field
* is available since v1.11.0.
* when a single origin in an ORIGIN frame is received.
*
* .. version-added:: 1.11.0
*/
nghttp3_recv_origin recv_origin;
/**
* :member:`end_origin` is a callback function which is invoked when
* an ORIGIN frame has been completely processed. This field is
* available since v1.11.0.
* an ORIGIN frame has been completely processed.
*
* .. version-added:: 1.11.0
*/
nghttp3_end_origin end_origin;
/**
@@ -2287,14 +2363,16 @@ typedef struct nghttp3_callbacks {
* unpredictable data are needed. Although this field is optional
* due to the backward compatibility, it is recommended to specify
* this field to harden the runtime behavior against suspicious
* activities of a remote endpoint. This field is available since
* v1.11.0.
* activities of a remote endpoint.
*
* .. version-added:: 1.11.0
*/
nghttp3_rand rand;
/**
* :member:`recv_settings2` is a callback function which is invoked
* when SETTINGS frame is received. This field is available since
* v1.14.0.
* when SETTINGS frame is received.
*
* .. version-added:: 1.14.0
*/
nghttp3_recv_settings2 recv_settings2;
} nghttp3_callbacks;
@@ -2306,7 +2384,7 @@ typedef struct nghttp3_callbacks {
* values.
*
* - :member:`max_field_section_size
* <nghttp3_settings.max_field_section_size>` = :expr:`((1ull << 62) - 1)`
* <nghttp3_settings.max_field_section_size>` = :expr:`((1ULL << 62) - 1)`
* - :member:`qpack_max_dtable_capacity
* <nghttp3_settings.qpack_max_dtable_capacity>` = 0
* - :member:`qpack_encoder_max_dtable_capacity
@@ -2417,8 +2495,8 @@ NGHTTP3_EXTERN int nghttp3_conn_bind_qpack_streams(nghttp3_conn *conn,
*
* .. warning::
*
* Deprecated since v1.12.0. Use `nghttp3_conn_read_stream2`
* instead.
* .. version-deprecated:: 1.12.0
* Use `nghttp3_conn_read_stream2` instead.
*
* `nghttp3_conn_read_stream` reads data |src| of length |srclen| on
* stream identified by |stream_id|. It returns the number of bytes
@@ -2476,7 +2554,7 @@ NGHTTP3_EXTERN nghttp3_ssize nghttp3_conn_read_stream(nghttp3_conn *conn,
* be closed. Calling nghttp3 API other than `nghttp3_conn_del`
* causes undefined behavior.
*
* This function is available since v1.12.0.
* .. version-added:: 1.12.0
*/
NGHTTP3_EXTERN nghttp3_ssize nghttp3_conn_read_stream2(nghttp3_conn *conn,
int64_t stream_id,
@@ -2624,6 +2702,11 @@ NGHTTP3_EXTERN int nghttp3_conn_unblock_stream(nghttp3_conn *conn,
/**
* @function
*
* .. warning::
*
* .. version-deprecated:: 1.16.0
* Use `nghttp3_conn_is_stream_writable2` instead.
*
* `nghttp3_conn_is_stream_writable` returns nonzero if a stream
* identified by |stream_id| is writable. It is not writable if:
*
@@ -2641,6 +2724,28 @@ NGHTTP3_EXTERN int nghttp3_conn_unblock_stream(nghttp3_conn *conn,
NGHTTP3_EXTERN int nghttp3_conn_is_stream_writable(nghttp3_conn *conn,
int64_t stream_id);
/**
* @function
*
* `nghttp3_conn_is_stream_writable2` returns nonzero if a stream
* identified by |stream_id| is writable. It is not writable if:
*
* - the stream does not exist; or,
* - the stream is closed (e.g., `nghttp3_conn_close_stream` is
* called); or,
* - the stream is QUIC flow control blocked (e.g.,
* `nghttp3_conn_block_stream` is called); or,
* - the stream is input data blocked (e.g.,
* :macro:`NGHTTP3_ERR_WOULDBLOCK` is returned from
* :type:`nghttp3_read_data_callback`); or,
* - the stream is half-closed local (e.g.,
* `nghttp3_conn_shutdown_stream_write` is called).
*
* .. version-added:: 1.16.0
*/
NGHTTP3_EXTERN int nghttp3_conn_is_stream_writable2(const nghttp3_conn *conn,
int64_t stream_id);
/**
* @function
*
@@ -2729,7 +2834,7 @@ NGHTTP3_EXTERN int nghttp3_conn_close_stream(nghttp3_conn *conn,
*
* :macro:`NGHTTP3_DATA_FLAG_NONE` indicates no flag set.
*/
#define NGHTTP3_DATA_FLAG_NONE 0x00u
#define NGHTTP3_DATA_FLAG_NONE 0x00U
/**
* @macro
@@ -2739,7 +2844,7 @@ NGHTTP3_EXTERN int nghttp3_conn_close_stream(nghttp3_conn *conn,
* that sending side of stream is closed unless
* :macro:`NGHTTP3_DATA_FLAG_NO_END_STREAM` is given at the same time.
*/
#define NGHTTP3_DATA_FLAG_EOF 0x01u
#define NGHTTP3_DATA_FLAG_EOF 0x01U
/**
* @macro
@@ -2751,7 +2856,7 @@ NGHTTP3_EXTERN int nghttp3_conn_close_stream(nghttp3_conn *conn,
* has been called, regardless of this flag, the submitted trailer
* fields are sent.
*/
#define NGHTTP3_DATA_FLAG_NO_END_STREAM 0x02u
#define NGHTTP3_DATA_FLAG_NO_END_STREAM 0x02U
/**
* @function
@@ -2964,6 +3069,29 @@ NGHTTP3_EXTERN int nghttp3_conn_set_stream_user_data(nghttp3_conn *conn,
/**
* @function
*
* `nghttp3_conn_get_stream_user_data` returns the user data
* associated to the stream identified by |stream_id|. If no data is
* associated or the stream is not found, this function returns NULL.
*
* The user data can be associated to the stream by the following
* functions:
*
* - `nghttp3_conn_set_stream_user_data`
* - `nghttp3_conn_submit_request`
*
* .. version-added:: 1.16.0
*/
NGHTTP3_EXTERN void *nghttp3_conn_get_stream_user_data(const nghttp3_conn *conn,
int64_t stream_id);
/**
* @function
*
* .. warning::
*
* .. version-deprecated:: 1.16.0
* Use `nghttp3_conn_get_frame_payload_left2` instead.
*
* `nghttp3_conn_get_frame_payload_left` returns the number of bytes
* left to read current frame payload for a stream denoted by
* |stream_id|. If no such stream is found, or |stream_id| identifies
@@ -2973,6 +3101,20 @@ NGHTTP3_EXTERN int nghttp3_conn_set_stream_user_data(nghttp3_conn *conn,
NGHTTP3_EXTERN uint64_t nghttp3_conn_get_frame_payload_left(nghttp3_conn *conn,
int64_t stream_id);
/**
* @function
*
* `nghttp3_conn_get_frame_payload_left2` returns the number of bytes
* left to read current frame payload for a stream denoted by
* |stream_id|. If no such stream is found, or |stream_id| identifies
* neither client bidirectional stream nor remote control stream, it
* returns 0.
*
* .. version-added:: 1.16.0
*/
NGHTTP3_EXTERN uint64_t nghttp3_conn_get_frame_payload_left2(
const nghttp3_conn *conn, int64_t stream_id);
/**
* @macrosection
*
@@ -3034,6 +3176,11 @@ typedef struct NGHTTP3_ALIGN(8) nghttp3_pri {
/**
* @function
*
* .. warning::
*
* .. version-deprecated:: 1.16.0
* Use `nghttp3_conn_get_stream_priority2` instead.
*
* `nghttp3_conn_get_stream_priority` stores stream priority of a
* stream denoted by |stream_id| into |*dest|. |stream_id| must
* identify client initiated bidirectional stream. Only server can
@@ -3053,6 +3200,32 @@ typedef struct NGHTTP3_ALIGN(8) nghttp3_pri {
NGHTTP3_EXTERN int nghttp3_conn_get_stream_priority_versioned(
nghttp3_conn *conn, int pri_version, nghttp3_pri *dest, int64_t stream_id);
/**
* @function
*
* `nghttp3_conn_get_stream_priority2` stores stream priority of a
* stream denoted by |stream_id| into |*dest|. |stream_id| must
* identify client initiated bidirectional stream. Only server can
* use this function.
*
* This function must not be called if |conn| is initialized as
* client.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* :macro:`NGHTTP3_ERR_INVALID_ARGUMENT`
* |stream_id| is not a client initiated bidirectional stream ID.
* :macro:`NGHTTP3_ERR_STREAM_NOT_FOUND`
* Stream not found.
*
* .. version-added:: 1.16.0
*/
NGHTTP3_EXTERN int
nghttp3_conn_get_stream_priority2_versioned(const nghttp3_conn *conn,
int pri_version, nghttp3_pri *dest,
int64_t stream_id);
/**
* @function
*
@@ -3139,12 +3312,28 @@ NGHTTP3_EXTERN int nghttp3_check_header_value(const uint8_t *value, size_t len);
/**
* @function
*
* .. warning::
*
* .. version-deprecated:: 1.16.0
* Use `nghttp3_conn_is_drained2` instead.
*
* `nghttp3_conn_is_drained` returns nonzero if
* `nghttp3_conn_shutdown` has been called, and there is no active
* remote streams. This function is for server use only.
*/
NGHTTP3_EXTERN int nghttp3_conn_is_drained(nghttp3_conn *conn);
/**
* @function
*
* `nghttp3_conn_is_drained2` returns nonzero if
* `nghttp3_conn_shutdown` has been called, and there is no active
* remote streams. This function is for server use only.
*
* .. version-added:: 1.16.0
*/
NGHTTP3_EXTERN int nghttp3_conn_is_drained2(const nghttp3_conn *conn);
/**
* @function
*
@@ -3279,6 +3468,15 @@ NGHTTP3_EXTERN int nghttp3_err_is_fatal(int liberr);
nghttp3_conn_get_stream_priority_versioned((CONN), NGHTTP3_PRI_VERSION, \
(DEST), (STREAM_ID))
/*
* `nghttp3_conn_get_stream_priority2` is a wrapper around
* `nghttp3_conn_get_stream_priority2_versioned` to set the correct
* struct version.
*/
#define nghttp3_conn_get_stream_priority2(CONN, DEST, STREAM_ID) \
nghttp3_conn_get_stream_priority2_versioned((CONN), NGHTTP3_PRI_VERSION, \
(DEST), (STREAM_ID))
/*
* `nghttp3_pri_parse_priority` is a wrapper around
* `nghttp3_pri_parse_priority_versioned` to set the correct struct
+2 -2
View File
@@ -31,7 +31,7 @@
*
* Version number of the nghttp3 library release.
*/
#define NGHTTP3_VERSION "1.15.0"
#define NGHTTP3_VERSION "1.16.0"
/**
* @macro
@@ -41,6 +41,6 @@
* number, 8 bits for minor and 8 bits for patch. Version 1.2.3
* becomes 0x010203.
*/
#define NGHTTP3_VERSION_NUM 0x010f00
#define NGHTTP3_VERSION_NUM 0x011000
#endif /* !defined(NGHTTP3_VERSION_H) */
+6 -6
View File
@@ -31,7 +31,7 @@
void nghttp3_balloc_init(nghttp3_balloc *balloc, size_t blklen,
const nghttp3_mem *mem) {
assert((blklen & 0xfu) == 0);
assert((blklen & 0xFU) == 0);
balloc->mem = mem;
balloc->blklen = blklen;
@@ -67,7 +67,7 @@ int nghttp3_balloc_get(nghttp3_balloc *balloc, void **pbuf, size_t n) {
if (nghttp3_buf_left(&balloc->buf) < n) {
p = nghttp3_mem_malloc(balloc->mem,
sizeof(nghttp3_memblock_hd) + 0x8u + balloc->blklen);
sizeof(nghttp3_memblock_hd) + 0x8U + balloc->blklen);
if (p == NULL) {
return NGHTTP3_ERR_NOMEM;
}
@@ -77,15 +77,15 @@ int nghttp3_balloc_get(nghttp3_balloc *balloc, void **pbuf, size_t n) {
balloc->head = hd;
nghttp3_buf_wrap_init(
&balloc->buf,
(uint8_t *)(((uintptr_t)p + sizeof(nghttp3_memblock_hd) + 0xfu) &
~(uintptr_t)0xfu),
(uint8_t *)(((uintptr_t)p + sizeof(nghttp3_memblock_hd) + 0xFU) &
~(uintptr_t)0xFU),
balloc->blklen);
}
assert(((uintptr_t)balloc->buf.last & 0xfu) == 0);
assert(((uintptr_t)balloc->buf.last & 0xFU) == 0);
*pbuf = balloc->buf.last;
balloc->buf.last += (n + 0xfu) & ~(uintptr_t)0xfu;
balloc->buf.last += (n + 0xFU) & ~(size_t)0xFU;
return 0;
}
+1 -1
View File
@@ -45,7 +45,7 @@ nghttp3_callbacks_convert_to_latest(nghttp3_callbacks *dest,
return src;
}
memset(dest, 0, sizeof(*dest));
*dest = (nghttp3_callbacks){0};
callbacks_copy(dest, src, callbacks_version);
+169 -132
View File
@@ -43,7 +43,7 @@ nghttp3_objalloc_def(chunk, nghttp3_chunk, oplent)
* conn_remote_stream_uni returns nonzero if |stream_id| is remote
* unidirectional stream ID.
*/
static int conn_remote_stream_uni(nghttp3_conn *conn, int64_t stream_id) {
static int conn_remote_stream_uni(const nghttp3_conn *conn, int64_t stream_id) {
if (conn->server) {
return (stream_id & 0x03) == 0x02;
}
@@ -495,7 +495,7 @@ nghttp3_ssize nghttp3_conn_read_stream2(nghttp3_conn *conn, int64_t stream_id,
}
conn->rx.max_stream_id_bidi =
nghttp3_max_int64(conn->rx.max_stream_id_bidi, stream_id);
nghttp3_max(conn->rx.max_stream_id_bidi, stream_id);
rv = nghttp3_conn_create_stream(conn, &stream, stream_id);
if (rv != 0) {
return rv;
@@ -572,7 +572,7 @@ static nghttp3_ssize conn_read_type(nghttp3_conn *conn, nghttp3_stream *stream,
nghttp3_stream_read_state *rstate = &stream->rstate;
nghttp3_varint_read_state *rvint = &rstate->rvint;
nghttp3_ssize nread;
int64_t stream_type;
uint64_t stream_type;
assert(srclen);
@@ -649,10 +649,7 @@ nghttp3_ssize nghttp3_conn_read_uni(nghttp3_conn *conn, nghttp3_stream *stream,
return NGHTTP3_ERR_H3_EXCESSIVE_LOAD;
}
rv = conn_delete_stream(conn, stream);
assert(0 == rv);
return 0;
return conn_delete_stream(conn, stream);
}
nread = conn_read_type(conn, stream, src, srclen, fin);
if (nread < 0) {
@@ -724,8 +721,8 @@ static void conn_reset_rx_originlen(nghttp3_conn *conn) {
conn->rx.originlen = 0;
}
static int frame_fin(nghttp3_stream_read_state *rstate, size_t len) {
return (int64_t)len >= rstate->left;
static int frame_fin(const nghttp3_stream_read_state *rstate, size_t len) {
return len >= rstate->left;
}
nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
@@ -909,7 +906,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
}
/* Read Identifier */
len = (size_t)nghttp3_min_int64(rstate->left, (int64_t)(end - p));
len = (size_t)nghttp3_min(rstate->left, (uint64_t)(end - p));
assert(len > 0);
nread = nghttp3_read_varint(rvint, p, p + len, frame_fin(rstate, len));
if (nread < 0) {
@@ -918,12 +915,12 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
p += nread;
nconsumed += (size_t)nread;
rstate->left -= nread;
rstate->left -= (uint64_t)nread;
if (rvint->left) {
rstate->state = NGHTTP3_CTRL_STREAM_STATE_SETTINGS_ID;
return (nghttp3_ssize)nconsumed;
}
rstate->fr.settings.iv[0].id = (uint64_t)rvint->acc;
rstate->fr.settings.iv[0].id = rvint->acc;
nghttp3_varint_read_state_reset(rvint);
/* Read Value */
@@ -944,12 +941,12 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
p += nread;
nconsumed += (size_t)nread;
rstate->left -= nread;
rstate->left -= (uint64_t)nread;
if (rvint->left) {
rstate->state = NGHTTP3_CTRL_STREAM_STATE_SETTINGS_VALUE;
return (nghttp3_ssize)nconsumed;
}
rstate->fr.settings.iv[0].value = (uint64_t)rvint->acc;
rstate->fr.settings.iv[0].value = rvint->acc;
nghttp3_varint_read_state_reset(rvint);
rv =
@@ -960,7 +957,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
}
break;
case NGHTTP3_CTRL_STREAM_STATE_SETTINGS_ID:
len = (size_t)nghttp3_min_int64(rstate->left, (int64_t)(end - p));
len = (size_t)nghttp3_min(rstate->left, (uint64_t)(end - p));
assert(len > 0);
nread = nghttp3_read_varint(rvint, p, p + len, frame_fin(rstate, len));
if (nread < 0) {
@@ -969,11 +966,11 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
p += nread;
nconsumed += (size_t)nread;
rstate->left -= nread;
rstate->left -= (uint64_t)nread;
if (rvint->left) {
return (nghttp3_ssize)nconsumed;
}
rstate->fr.settings.iv[0].id = (uint64_t)rvint->acc;
rstate->fr.settings.iv[0].id = rvint->acc;
nghttp3_varint_read_state_reset(rvint);
if (rstate->left == 0) {
@@ -987,7 +984,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
}
/* Fall through */
case NGHTTP3_CTRL_STREAM_STATE_SETTINGS_VALUE:
len = (size_t)nghttp3_min_int64(rstate->left, (int64_t)(end - p));
len = (size_t)nghttp3_min(rstate->left, (uint64_t)(end - p));
assert(len > 0);
nread = nghttp3_read_varint(rvint, p, p + len, frame_fin(rstate, len));
if (nread < 0) {
@@ -996,11 +993,11 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
p += nread;
nconsumed += (size_t)nread;
rstate->left -= nread;
rstate->left -= (uint64_t)nread;
if (rvint->left) {
return (nghttp3_ssize)nconsumed;
}
rstate->fr.settings.iv[0].value = (uint64_t)rvint->acc;
rstate->fr.settings.iv[0].value = rvint->acc;
nghttp3_varint_read_state_reset(rvint);
rv = nghttp3_conn_on_settings_entry_received(conn, &rstate->fr.settings);
@@ -1021,7 +1018,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
nghttp3_stream_read_state_reset(rstate);
break;
case NGHTTP3_CTRL_STREAM_STATE_GOAWAY:
len = (size_t)nghttp3_min_int64(rstate->left, (int64_t)(end - p));
len = (size_t)nghttp3_min(rstate->left, (uint64_t)(end - p));
assert(len > 0);
nread = nghttp3_read_varint(rvint, p, p + len, frame_fin(rstate, len));
if (nread < 0) {
@@ -1030,26 +1027,26 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
p += nread;
nconsumed += (size_t)nread;
rstate->left -= nread;
rstate->left -= (uint64_t)nread;
if (rvint->left) {
return (nghttp3_ssize)nconsumed;
}
if (!conn->server && !nghttp3_client_stream_bidi(rvint->acc)) {
if (!conn->server && !nghttp3_client_stream_bidi((int64_t)rvint->acc)) {
return NGHTTP3_ERR_H3_ID_ERROR;
}
if (conn->rx.goaway_id < rvint->acc) {
if (conn->rx.goaway_id < (int64_t)rvint->acc) {
return NGHTTP3_ERR_H3_ID_ERROR;
}
/* Receiving same GOAWAY ID is suspicious. */
if (conn->rx.goaway_id == rvint->acc &&
if (conn->rx.goaway_id == (int64_t)rvint->acc &&
conn_glitch_ratelim_drain(conn, 1, ts) != 0) {
return NGHTTP3_ERR_H3_EXCESSIVE_LOAD;
}
conn->flags |= NGHTTP3_CONN_FLAG_GOAWAY_RECVED;
conn->rx.goaway_id = rvint->acc;
conn->rx.goaway_id = (int64_t)rvint->acc;
nghttp3_varint_read_state_reset(rvint);
if (conn->callbacks.shutdown) {
@@ -1064,7 +1061,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
break;
case NGHTTP3_CTRL_STREAM_STATE_MAX_PUSH_ID:
/* server side only */
len = (size_t)nghttp3_min_int64(rstate->left, (int64_t)(end - p));
len = (size_t)nghttp3_min(rstate->left, (uint64_t)(end - p));
assert(len > 0);
nread = nghttp3_read_varint(rvint, p, p + len, frame_fin(rstate, len));
if (nread < 0) {
@@ -1073,29 +1070,29 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
p += nread;
nconsumed += (size_t)nread;
rstate->left -= nread;
rstate->left -= (uint64_t)nread;
if (rvint->left) {
return (nghttp3_ssize)nconsumed;
}
if (conn->local.uni.max_pushes > (uint64_t)rvint->acc + 1) {
if (conn->local.uni.max_pushes > rvint->acc + 1) {
return NGHTTP3_ERR_H3_FRAME_ERROR;
}
/* Receiving same MAX_PUSH_ID is suspicious. */
if (conn->local.uni.max_pushes == (uint64_t)rvint->acc + 1 &&
if (conn->local.uni.max_pushes == rvint->acc + 1 &&
conn_glitch_ratelim_drain(conn, 1, ts) != 0) {
return NGHTTP3_ERR_H3_EXCESSIVE_LOAD;
}
conn->local.uni.max_pushes = (uint64_t)rvint->acc + 1;
conn->local.uni.max_pushes = rvint->acc + 1;
nghttp3_varint_read_state_reset(rvint);
nghttp3_stream_read_state_reset(rstate);
break;
case NGHTTP3_CTRL_STREAM_STATE_PRIORITY_UPDATE_PRI_ELEM_ID:
/* server side only */
len = (size_t)nghttp3_min_int64(rstate->left, (int64_t)(end - p));
len = (size_t)nghttp3_min(rstate->left, (uint64_t)(end - p));
assert(len > 0);
nread = nghttp3_read_varint(rvint, p, p + len, frame_fin(rstate, len));
if (nread < 0) {
@@ -1104,12 +1101,12 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
p += nread;
nconsumed += (size_t)nread;
rstate->left -= nread;
rstate->left -= (uint64_t)nread;
if (rvint->left) {
return (nghttp3_ssize)nconsumed;
}
rstate->fr.priority_update.pri_elem_id = rvint->acc;
rstate->fr.priority_update.pri_elem_id = (int64_t)rvint->acc;
nghttp3_varint_read_state_reset(rvint);
if (rstate->left == 0) {
@@ -1138,9 +1135,9 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
case NGHTTP3_CTRL_STREAM_STATE_PRIORITY_UPDATE:
/* We need to buffer Priority Field Value because it might be
fragmented. */
len = (size_t)nghttp3_min_int64(rstate->left, (int64_t)(end - p));
len = (size_t)nghttp3_min(rstate->left, (uint64_t)(end - p));
assert(len > 0);
if (conn->rx.pri_fieldbuflen == 0 && rstate->left == (int64_t)len) {
if (conn->rx.pri_fieldbuflen == 0 && rstate->left == len) {
/* Everything is in the input buffer. Apply same length
limit we impose when buffering the field. */
if (len > sizeof(conn->rx.pri_fieldbuf)) {
@@ -1160,7 +1157,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
memcpy(conn->rx.pri_fieldbuf + conn->rx.pri_fieldbuflen, p, len);
conn->rx.pri_fieldbuflen += len;
if (rstate->left == (int64_t)len) {
if (rstate->left == len) {
pri_field_value = conn->rx.pri_fieldbuf;
pri_field_valuelen = conn->rx.pri_fieldbuflen;
}
@@ -1168,7 +1165,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
p += len;
nconsumed += len;
rstate->left -= (int64_t)len;
rstate->left -= len;
if (rstate->left) {
return (nghttp3_ssize)nconsumed;
@@ -1193,7 +1190,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
break;
case NGHTTP3_CTRL_STREAM_STATE_ORIGIN_ORIGIN_LEN:
/* client side only */
len = (size_t)nghttp3_min_int64(rstate->left, (int64_t)(end - p));
len = (size_t)nghttp3_min(rstate->left, (uint64_t)(end - p));
assert(len > 0);
@@ -1208,7 +1205,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
}
nconsumed += (size_t)nread;
rstate->left -= nread;
rstate->left -= (uint64_t)nread;
len -= (size_t)nread;
if (conn->rx.originlen_offset < sizeof(conn->rx.originlen)) {
@@ -1240,7 +1237,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
/* No need to update p because we will return very soon. */
nconsumed += len;
rstate->left -= (int64_t)len;
rstate->left -= len;
conn->rx.originbuflen = len;
@@ -1281,8 +1278,8 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
break;
case NGHTTP3_CTRL_STREAM_STATE_ORIGIN_ASCII_ORIGIN:
/* client side only */
len = nghttp3_min_size(conn->rx.originlen - conn->rx.originbuflen,
(size_t)(end - p));
len = nghttp3_min(conn->rx.originlen - conn->rx.originbuflen,
(size_t)(end - p));
assert(len > 0);
@@ -1291,7 +1288,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
conn->rx.originbuflen += len;
p += len;
nconsumed += len;
rstate->left -= (int64_t)len;
rstate->left -= len;
if (conn->rx.originbuflen < conn->rx.originlen) {
return (nghttp3_ssize)nconsumed;
@@ -1319,10 +1316,10 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
break;
case NGHTTP3_CTRL_STREAM_STATE_IGN_FRAME:
len = (size_t)nghttp3_min_int64(rstate->left, (int64_t)(end - p));
len = (size_t)nghttp3_min(rstate->left, (uint64_t)(end - p));
p += len;
nconsumed += len;
rstate->left -= (int64_t)len;
rstate->left -= len;
if (rstate->left) {
return (nghttp3_ssize)nconsumed;
@@ -1339,7 +1336,6 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
}
static int conn_delete_stream(nghttp3_conn *conn, nghttp3_stream *stream) {
int bidi = nghttp3_client_stream_bidi(stream->node.id);
int rv;
rv = conn_call_deferred_consume(conn, stream,
@@ -1348,23 +1344,20 @@ static int conn_delete_stream(nghttp3_conn *conn, nghttp3_stream *stream) {
return rv;
}
if (bidi) {
if (stream->qpack_blocked_pe.index != NGHTTP3_PQ_BAD_INDEX) {
nghttp3_conn_qpack_blocked_streams_remove(conn, stream);
if (stream->qpack_blocked_pe.index != NGHTTP3_PQ_BAD_INDEX) {
nghttp3_conn_qpack_blocked_streams_remove(conn, stream);
rv = nghttp3_qpack_decoder_cancel_stream(&conn->qdec, stream->node.id);
if (rv != 0) {
return rv;
}
rv = nghttp3_qpack_decoder_cancel_stream(&conn->qdec, stream->node.id);
if (rv != 0) {
return rv;
}
}
if (conn->callbacks.stream_close) {
rv =
conn->callbacks.stream_close(conn, stream->node.id, stream->error_code,
conn->user_data, stream->user_data);
if (rv != 0) {
return NGHTTP3_ERR_CALLBACK_FAILURE;
}
if (conn->callbacks.stream_close) {
rv = conn->callbacks.stream_close(conn, stream->node.id, stream->error_code,
conn->user_data, stream->user_data);
if (rv != 0) {
return NGHTTP3_ERR_CALLBACK_FAILURE;
}
}
@@ -1445,7 +1438,7 @@ nghttp3_ssize nghttp3_conn_read_qpack_encoder(nghttp3_conn *conn,
for (; !nghttp3_pq_empty(&conn->qpack_blocked_streams);) {
stream = nghttp3_struct_of(nghttp3_pq_top(&conn->qpack_blocked_streams),
nghttp3_stream, qpack_blocked_pe);
if (nghttp3_qpack_stream_context_get_ricnt(&stream->qpack_sctx) >
if (nghttp3_qpack_stream_context_get_ricnt2(&stream->qpack_sctx) >
nghttp3_qpack_decoder_get_icnt(&conn->qdec)) {
break;
}
@@ -1647,13 +1640,13 @@ nghttp3_ssize nghttp3_conn_read_bidi(nghttp3_conn *conn, size_t *pnproc,
}
break;
case NGHTTP3_REQ_STREAM_STATE_DATA:
len = (size_t)nghttp3_min_int64(rstate->left, (int64_t)(end - p));
len = (size_t)nghttp3_min(rstate->left, (uint64_t)(end - p));
rv = nghttp3_conn_on_data(conn, stream, p, len);
if (rv != 0) {
return rv;
}
p += len;
rstate->left -= (int64_t)len;
rstate->left -= len;
if (rstate->left) {
goto almost_done;
@@ -1666,16 +1659,16 @@ nghttp3_ssize nghttp3_conn_read_bidi(nghttp3_conn *conn, size_t *pnproc,
nghttp3_stream_read_state_reset(rstate);
break;
case NGHTTP3_REQ_STREAM_STATE_HEADERS:
len = (size_t)nghttp3_min_int64(rstate->left, (int64_t)(end - p));
nread = nghttp3_conn_on_headers(conn, stream, p, len,
(int64_t)len == rstate->left);
len = (size_t)nghttp3_min(rstate->left, (uint64_t)(end - p));
nread =
nghttp3_conn_on_headers(conn, stream, p, len, len == rstate->left);
if (nread < 0) {
return nread;
}
p += nread;
nconsumed += (size_t)nread;
rstate->left -= nread;
rstate->left -= (uint64_t)nread;
if (stream->flags & NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED) {
if (p != end && nghttp3_stream_get_buffered_datalen(stream) == 0) {
@@ -1748,10 +1741,10 @@ nghttp3_ssize nghttp3_conn_read_bidi(nghttp3_conn *conn, size_t *pnproc,
break;
case NGHTTP3_REQ_STREAM_STATE_IGN_FRAME:
len = (size_t)nghttp3_min_int64(rstate->left, (int64_t)(end - p));
len = (size_t)nghttp3_min(rstate->left, (uint64_t)(end - p));
p += len;
nconsumed += len;
rstate->left -= (int64_t)len;
rstate->left -= len;
if (rstate->left) {
goto almost_done;
@@ -1975,7 +1968,7 @@ int nghttp3_conn_on_settings_entry_received(nghttp3_conn *conn,
dest->qpack_blocked_streams = (size_t)ent->value;
nghttp3_qpack_encoder_set_max_blocked_streams(
&conn->qenc, (size_t)nghttp3_min_uint64(100, ent->value));
&conn->qenc, (size_t)nghttp3_min(100, ent->value));
break;
case NGHTTP3_SETTINGS_ID_ENABLE_CONNECT_PROTOCOL:
if (conn->server) {
@@ -2054,7 +2047,7 @@ conn_on_priority_update_stream(nghttp3_conn *conn,
}
conn->rx.max_stream_id_bidi =
nghttp3_max_int64(conn->rx.max_stream_id_bidi, stream_id);
nghttp3_max(conn->rx.max_stream_id_bidi, stream_id);
rv = nghttp3_conn_create_stream(conn, &stream, stream_id);
if (rv != 0) {
return rv;
@@ -2106,11 +2099,11 @@ int nghttp3_conn_create_stream(nghttp3_conn *conn, nghttp3_stream **pstream,
int64_t stream_id) {
nghttp3_stream *stream;
int rv;
static const nghttp3_stream_callbacks callbacks = {
.acked_data = conn_stream_acked_data,
};
rv = nghttp3_stream_new(&stream, stream_id,
&(nghttp3_stream_callbacks){
.acked_data = conn_stream_acked_data,
},
rv = nghttp3_stream_new(&stream, stream_id, &callbacks,
&conn->out_chunk_objalloc, &conn->stream_objalloc,
conn->mem);
if (rv != 0) {
@@ -2135,14 +2128,14 @@ int nghttp3_conn_create_stream(nghttp3_conn *conn, nghttp3_stream **pstream,
return 0;
}
nghttp3_stream *nghttp3_conn_find_stream(nghttp3_conn *conn,
nghttp3_stream *nghttp3_conn_find_stream(const nghttp3_conn *conn,
int64_t stream_id) {
return nghttp3_map_find(&conn->streams, (nghttp3_map_key_type)stream_id);
}
int nghttp3_conn_bind_control_stream(nghttp3_conn *conn, int64_t stream_id) {
nghttp3_stream *stream;
nghttp3_frame fr;
nghttp3_frame *fr;
int rv;
assert(stream_id >= 0);
@@ -2168,28 +2161,28 @@ int nghttp3_conn_bind_control_stream(nghttp3_conn *conn, int64_t stream_id) {
return rv;
}
fr.settings = (nghttp3_frame_settings){
.type = NGHTTP3_FRAME_SETTINGS,
.local_settings = &conn->local.settings,
};
rv = nghttp3_stream_frq_add(stream, &fr);
rv = nghttp3_stream_frq_emplace(stream, &fr);
if (rv != 0) {
return rv;
}
fr->settings = (nghttp3_frame_settings){
.type = NGHTTP3_FRAME_SETTINGS,
.local_settings = &conn->local.settings,
};
if (conn->local.settings.origin_list) {
assert(conn->server);
fr.origin = (nghttp3_frame_origin){
.type = NGHTTP3_FRAME_ORIGIN,
.origin_list = *conn->local.settings.origin_list,
};
rv = nghttp3_stream_frq_add(stream, &fr);
rv = nghttp3_stream_frq_emplace(stream, &fr);
if (rv != 0) {
return rv;
}
fr->origin = (nghttp3_frame_origin){
.type = NGHTTP3_FRAME_ORIGIN,
.origin_list = *conn->local.settings.origin_list,
};
}
return 0;
@@ -2416,35 +2409,35 @@ static int conn_submit_headers_data(nghttp3_conn *conn, nghttp3_stream *stream,
const nghttp3_data_reader *dr) {
int rv;
nghttp3_nv *nnva;
nghttp3_frame fr;
nghttp3_frame *fr;
rv = nghttp3_nva_copy(&nnva, nva, nvlen, conn->mem);
if (rv != 0) {
return rv;
}
fr.headers = (nghttp3_frame_headers){
.type = NGHTTP3_FRAME_HEADERS,
.nva = nnva,
.nvlen = nvlen,
};
rv = nghttp3_stream_frq_add(stream, &fr);
rv = nghttp3_stream_frq_emplace(stream, &fr);
if (rv != 0) {
nghttp3_nva_del(nnva, conn->mem);
return rv;
}
if (dr) {
fr.data = (nghttp3_frame_data){
.type = NGHTTP3_FRAME_DATA,
.dr = *dr,
};
fr->headers = (nghttp3_frame_headers){
.type = NGHTTP3_FRAME_HEADERS,
.nva = nnva,
.nvlen = nvlen,
};
rv = nghttp3_stream_frq_add(stream, &fr);
if (dr) {
rv = nghttp3_stream_frq_emplace(stream, &fr);
if (rv != 0) {
return rv;
}
fr->data = (nghttp3_frame_data){
.type = NGHTTP3_FRAME_DATA,
.dr = *dr,
};
}
if (nghttp3_stream_require_schedule(stream)) {
@@ -2587,51 +2580,51 @@ int nghttp3_conn_submit_trailers(nghttp3_conn *conn, int64_t stream_id,
}
int nghttp3_conn_submit_shutdown_notice(nghttp3_conn *conn) {
nghttp3_frame fr;
nghttp3_frame *fr;
int rv;
assert(conn->tx.ctrl);
fr.goaway = (nghttp3_frame_goaway){
rv = nghttp3_stream_frq_emplace(conn->tx.ctrl, &fr);
if (rv != 0) {
return rv;
}
fr->goaway = (nghttp3_frame_goaway){
.type = NGHTTP3_FRAME_GOAWAY,
.id = conn->server ? NGHTTP3_SHUTDOWN_NOTICE_STREAM_ID
: NGHTTP3_SHUTDOWN_NOTICE_PUSH_ID,
};
assert(fr.goaway.id <= conn->tx.goaway_id);
assert(fr->goaway.id <= conn->tx.goaway_id);
rv = nghttp3_stream_frq_add(conn->tx.ctrl, &fr);
if (rv != 0) {
return rv;
}
conn->tx.goaway_id = fr.goaway.id;
conn->tx.goaway_id = fr->goaway.id;
conn->flags |= NGHTTP3_CONN_FLAG_GOAWAY_QUEUED;
return 0;
}
int nghttp3_conn_shutdown(nghttp3_conn *conn) {
nghttp3_frame fr;
nghttp3_frame *fr;
int rv;
assert(conn->tx.ctrl);
fr.goaway = (nghttp3_frame_goaway){
.type = NGHTTP3_FRAME_GOAWAY,
.id = conn->server ? nghttp3_min_int64((1ll << 62) - 4,
conn->rx.max_stream_id_bidi + 4)
: 0,
};
assert(fr.goaway.id <= conn->tx.goaway_id);
rv = nghttp3_stream_frq_add(conn->tx.ctrl, &fr);
rv = nghttp3_stream_frq_emplace(conn->tx.ctrl, &fr);
if (rv != 0) {
return rv;
}
conn->tx.goaway_id = fr.goaway.id;
fr->goaway = (nghttp3_frame_goaway){
.type = NGHTTP3_FRAME_GOAWAY,
.id = conn->server
? nghttp3_min((1LL << 62) - 4, conn->rx.max_stream_id_bidi + 4)
: 0,
};
assert(fr->goaway.id <= conn->tx.goaway_id);
conn->tx.goaway_id = fr->goaway.id;
conn->flags |=
NGHTTP3_CONN_FLAG_GOAWAY_QUEUED | NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED;
@@ -2697,7 +2690,12 @@ int nghttp3_conn_unblock_stream(nghttp3_conn *conn, int64_t stream_id) {
}
int nghttp3_conn_is_stream_writable(nghttp3_conn *conn, int64_t stream_id) {
nghttp3_stream *stream = nghttp3_conn_find_stream(conn, stream_id);
return nghttp3_conn_is_stream_writable2(conn, stream_id);
}
int nghttp3_conn_is_stream_writable2(const nghttp3_conn *conn,
int64_t stream_id) {
const nghttp3_stream *stream = nghttp3_conn_find_stream(conn, stream_id);
if (stream == NULL) {
return 0;
@@ -2815,9 +2813,29 @@ int nghttp3_conn_set_stream_user_data(nghttp3_conn *conn, int64_t stream_id,
return 0;
}
void *nghttp3_conn_get_stream_user_data(const nghttp3_conn *conn,
int64_t stream_id) {
nghttp3_stream *stream;
assert(stream_id >= 0);
assert(stream_id <= (int64_t)NGHTTP3_MAX_VARINT);
stream = nghttp3_conn_find_stream(conn, stream_id);
if (stream == NULL) {
return NULL;
}
return stream->user_data;
}
uint64_t nghttp3_conn_get_frame_payload_left(nghttp3_conn *conn,
int64_t stream_id) {
nghttp3_stream *stream;
return nghttp3_conn_get_frame_payload_left2(conn, stream_id);
}
uint64_t nghttp3_conn_get_frame_payload_left2(const nghttp3_conn *conn,
int64_t stream_id) {
const nghttp3_stream *stream;
int uni = 0;
assert(stream_id >= 0);
@@ -2839,14 +2857,22 @@ uint64_t nghttp3_conn_get_frame_payload_left(nghttp3_conn *conn,
return 0;
}
return (uint64_t)stream->rstate.left;
return stream->rstate.left;
}
int nghttp3_conn_get_stream_priority_versioned(nghttp3_conn *conn,
int pri_version,
nghttp3_pri *dest,
int64_t stream_id) {
nghttp3_stream *stream;
return nghttp3_conn_get_stream_priority2_versioned(conn, pri_version, dest,
stream_id);
}
int nghttp3_conn_get_stream_priority2_versioned(const nghttp3_conn *conn,
int pri_version,
nghttp3_pri *dest,
int64_t stream_id) {
const nghttp3_stream *stream;
(void)pri_version;
assert(conn->server);
@@ -2872,7 +2898,8 @@ int nghttp3_conn_set_client_stream_priority(nghttp3_conn *conn,
const uint8_t *data,
size_t datalen) {
nghttp3_stream *stream;
nghttp3_frame fr;
nghttp3_frame *fr;
int rv;
uint8_t *buf = NULL;
assert(!conn->server);
@@ -2897,14 +2924,20 @@ int nghttp3_conn_set_client_stream_priority(nghttp3_conn *conn,
memcpy(buf, data, datalen);
}
fr.priority_update = (nghttp3_frame_priority_update){
rv = nghttp3_stream_frq_emplace(conn->tx.ctrl, &fr);
if (rv != 0) {
nghttp3_mem_free(conn->mem, buf);
return rv;
}
fr->priority_update = (nghttp3_frame_priority_update){
.type = NGHTTP3_FRAME_PRIORITY_UPDATE,
.pri_elem_id = stream_id,
.data = buf,
.datalen = datalen,
};
return nghttp3_stream_frq_add(conn->tx.ctrl, &fr);
return 0;
}
int nghttp3_conn_set_server_stream_priority_versioned(nghttp3_conn *conn,
@@ -2935,6 +2968,10 @@ int nghttp3_conn_set_server_stream_priority_versioned(nghttp3_conn *conn,
}
int nghttp3_conn_is_drained(nghttp3_conn *conn) {
return nghttp3_conn_is_drained2(conn);
}
int nghttp3_conn_is_drained2(const nghttp3_conn *conn) {
assert(conn->server);
return (conn->flags & NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED) &&
+10 -9
View File
@@ -48,28 +48,28 @@
#define NGHTTP3_QPACK_ENCODER_MAX_BLOCK_STREAMS 100
/* NGHTTP3_CONN_FLAG_NONE indicates that no flag is set. */
#define NGHTTP3_CONN_FLAG_NONE 0x0000u
#define NGHTTP3_CONN_FLAG_NONE 0x0000U
/* NGHTTP3_CONN_FLAG_SETTINGS_RECVED is set when SETTINGS frame has
been received. */
#define NGHTTP3_CONN_FLAG_SETTINGS_RECVED 0x0001u
#define NGHTTP3_CONN_FLAG_SETTINGS_RECVED 0x0001U
/* NGHTTP3_CONN_FLAG_CONTROL_OPENED is set when a control stream has
opened. */
#define NGHTTP3_CONN_FLAG_CONTROL_OPENED 0x0002u
#define NGHTTP3_CONN_FLAG_CONTROL_OPENED 0x0002U
/* NGHTTP3_CONN_FLAG_QPACK_ENCODER_OPENED is set when a QPACK encoder
stream has opened. */
#define NGHTTP3_CONN_FLAG_QPACK_ENCODER_OPENED 0x0004u
#define NGHTTP3_CONN_FLAG_QPACK_ENCODER_OPENED 0x0004U
/* NGHTTP3_CONN_FLAG_QPACK_DECODER_OPENED is set when a QPACK decoder
stream has opened. */
#define NGHTTP3_CONN_FLAG_QPACK_DECODER_OPENED 0x0008u
#define NGHTTP3_CONN_FLAG_QPACK_DECODER_OPENED 0x0008U
/* NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED is set when graceful shutdown
has started. */
#define NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED 0x0010u
#define NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED 0x0010U
/* NGHTTP3_CONN_FLAG_GOAWAY_RECVED indicates that GOAWAY frame has
received. */
#define NGHTTP3_CONN_FLAG_GOAWAY_RECVED 0x0020u
#define NGHTTP3_CONN_FLAG_GOAWAY_RECVED 0x0020U
/* NGHTTP3_CONN_FLAG_GOAWAY_QUEUED indicates that GOAWAY frame has
been submitted for transmission. */
#define NGHTTP3_CONN_FLAG_GOAWAY_QUEUED 0x0040u
#define NGHTTP3_CONN_FLAG_GOAWAY_QUEUED 0x0040U
typedef struct nghttp3_chunk {
nghttp3_opl_entry oplent;
@@ -175,7 +175,8 @@ struct nghttp3_conn {
} tx;
};
nghttp3_stream *nghttp3_conn_find_stream(nghttp3_conn *conn, int64_t stream_id);
nghttp3_stream *nghttp3_conn_find_stream(const nghttp3_conn *conn,
int64_t stream_id);
int nghttp3_conn_create_stream(nghttp3_conn *conn, nghttp3_stream **pstream,
int64_t stream_id);
+15 -15
View File
@@ -31,7 +31,7 @@
#include "nghttp3_str.h"
#include "nghttp3_unreachable.h"
const uint8_t *nghttp3_get_varint(int64_t *dest, const uint8_t *p) {
const uint8_t *nghttp3_get_uvarint(uint64_t *dest, const uint8_t *p) {
uint16_t n16;
uint32_t n32;
uint64_t n64;
@@ -43,22 +43,22 @@ const uint8_t *nghttp3_get_varint(int64_t *dest, const uint8_t *p) {
case 1:
memcpy(&n16, p, 2);
n16 = ntohs(n16);
n16 &= 0x3fff;
n16 &= 0x3FFFU;
*dest = n16;
return p + 2;
case 2:
memcpy(&n32, p, 4);
n32 = ntohl(n32);
n32 &= 0x3fffffff;
n32 &= 0x3FFFFFFFU;
*dest = n32;
return p + 4;
case 3:
memcpy(&n64, p, 8);
n64 = nghttp3_ntohl64(n64);
n64 &= 0x3fffffffffffffff;
*dest = (int64_t)n64;
n64 &= 0x3FFFFFFFFFFFFFFFU;
*dest = n64;
return p + 8;
default:
@@ -66,8 +66,8 @@ const uint8_t *nghttp3_get_varint(int64_t *dest, const uint8_t *p) {
}
}
size_t nghttp3_get_varintlen(const uint8_t *p) {
return (size_t)(1u << (*p >> 6));
size_t nghttp3_get_uvarintlen(const uint8_t *p) {
return (size_t)(1U << (*p >> 6));
}
uint8_t *nghttp3_put_uint64be(uint8_t *p, uint64_t n) {
@@ -85,7 +85,7 @@ uint8_t *nghttp3_put_uint16be(uint8_t *p, uint16_t n) {
return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n));
}
uint8_t *nghttp3_put_varint(uint8_t *p, int64_t n) {
uint8_t *nghttp3_put_uvarint(uint8_t *p, uint64_t n) {
uint8_t *rv;
if (n < 64) {
*p++ = (uint8_t)n;
@@ -93,21 +93,21 @@ uint8_t *nghttp3_put_varint(uint8_t *p, int64_t n) {
}
if (n < 16384) {
rv = nghttp3_put_uint16be(p, (uint16_t)n);
*p |= 0x40;
*p |= 0x40U;
return rv;
}
if (n < 1073741824) {
rv = nghttp3_put_uint32be(p, (uint32_t)n);
*p |= 0x80;
*p |= 0x80U;
return rv;
}
assert(n < 4611686018427387904LL);
rv = nghttp3_put_uint64be(p, (uint64_t)n);
*p |= 0xc0;
assert(n < 4611686018427387904ULL);
rv = nghttp3_put_uint64be(p, n);
*p |= 0xC0U;
return rv;
}
size_t nghttp3_put_varintlen(int64_t n) {
size_t nghttp3_put_uvarintlen(uint64_t n) {
if (n < 64) {
return 1;
}
@@ -117,7 +117,7 @@ size_t nghttp3_put_varintlen(int64_t n) {
if (n < 1073741824) {
return 4;
}
assert(n < 4611686018427387904LL);
assert(n < 4611686018427387904ULL);
return 8;
}
+37 -66
View File
@@ -56,7 +56,7 @@
#include <nghttp3/nghttp3.h>
#define NGHTTP3_VARINT_MAX ((1ull << 62) - 1)
#define NGHTTP3_VARINT_MAX ((1ULL << 62) - 1)
#if HAVE_DECL_BE64TOH
# define nghttp3_ntohl64(N) be64toh(N)
@@ -67,11 +67,11 @@
# define nghttp3_htonl64(N) (N)
# else /* !defined(WORDS_BIGENDIAN) */
# if HAVE_DECL_BSWAP_64
# define nghttp3_bswap64 bswap_64
# define nghttp3_bswap64(N) bswap_64(N)
# elif defined(WIN32)
# define nghttp3_bswap64 _byteswap_uint64
# define nghttp3_bswap64(N) _byteswap_uint64(N)
# elif defined(__APPLE__)
# define nghttp3_bswap64 OSSwapInt64
# define nghttp3_bswap64(N) OSSwapInt64(N)
# else /* !(HAVE_DECL_BSWAP_64 || defined(WIN32) || defined(__APPLE__)) */
# define nghttp3_bswap64(N) \
((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
@@ -82,66 +82,43 @@
#endif /* !HAVE_DECL_BE64TOH */
#ifdef WIN32
/* Windows requires ws2_32 library for ntonl family of functions. We
define inline functions for those functions so that we don't have
dependency on that lib. */
# ifdef _MSC_VER
# define STIN static __inline
# else /* !defined(_MSC_VER) */
# define STIN static inline
# endif /* !defined(_MSC_VER) */
STIN uint32_t htonl(uint32_t hostlong) {
uint32_t res;
unsigned char *p = (unsigned char *)&res;
*p++ = (unsigned char)(hostlong >> 24);
*p++ = (hostlong >> 16) & 0xffu;
*p++ = (hostlong >> 8) & 0xffu;
*p = hostlong & 0xffu;
return res;
}
STIN uint16_t htons(uint16_t hostshort) {
uint16_t res;
unsigned char *p = (unsigned char *)&res;
*p++ = (unsigned char)(hostshort >> 8);
*p = hostshort & 0xffu;
return res;
}
STIN uint32_t ntohl(uint32_t netlong) {
uint32_t res;
unsigned char *p = (unsigned char *)&netlong;
res = (uint32_t)(*p++ << 24);
res += (uint32_t)(*p++ << 16);
res += (uint32_t)(*p++ << 8);
res += *p;
return res;
}
STIN uint16_t ntohs(uint16_t netshort) {
uint16_t res;
unsigned char *p = (unsigned char *)&netshort;
res = (uint16_t)(*p++ << 8);
res += *p;
return res;
}
/* Windows requires ws2_32 library for ntonl family of functions.
Instead of using them, use _byteswap_* functions. This is fine
because all platforms that can run Windows these days are little
endian. */
# define htonl(N) _byteswap_ulong(N)
# define htons(N) _byteswap_ushort(N)
# define ntohl(N) _byteswap_ulong(N)
# define ntohs(N) _byteswap_ushort(N)
#endif /* defined(WIN32) */
/*
* nghttp3_get_uvarint reads variable-length unsigned integer from
* |p|, and stores it in the buffer pointed by |dest| in host byte
* order. It returns |p| plus the number of bytes read from |p|.
*/
const uint8_t *nghttp3_get_uvarint(uint64_t *dest, const uint8_t *p);
/*
* nghttp3_get_uvarintlen returns the required number of bytes to read
* variable-length integer starting at |p|.
*/
size_t nghttp3_get_uvarintlen(const uint8_t *p);
/*
* nghttp3_get_varint reads variable-length unsigned integer from |p|,
* and stores it in the buffer pointed by |dest| in host byte order.
* It returns |p| plus the number of bytes read from |p|.
*/
const uint8_t *nghttp3_get_varint(int64_t *dest, const uint8_t *p);
static inline const uint8_t *nghttp3_get_varint(int64_t *dest,
const uint8_t *p) {
uint64_t n;
/*
* nghttp3_get_varintlen returns the required number of bytes to read
* variable-length integer starting at |p|.
*/
size_t nghttp3_get_varintlen(const uint8_t *p);
p = nghttp3_get_uvarint(&n, p);
*dest = (int64_t)n;
return p;
}
/*
* nghttp3_put_uint64be writes |n| in host byte order in |p| in
@@ -165,26 +142,20 @@ uint8_t *nghttp3_put_uint32be(uint8_t *p, uint32_t n);
uint8_t *nghttp3_put_uint16be(uint8_t *p, uint16_t n);
/*
* nghttp3_put_varint writes |n| in |p| using variable-length integer
* nghttp3_put_uvarint writes |n| in |p| using variable-length integer
* encoding. It returns the one beyond of the last written position.
*/
uint8_t *nghttp3_put_varint(uint8_t *p, int64_t n);
uint8_t *nghttp3_put_uvarint(uint8_t *p, uint64_t n);
/*
* nghttp3_put_varintlen returns the required number of bytes to
* nghttp3_put_uvarintlen returns the required number of bytes to
* encode |n|.
*/
size_t nghttp3_put_varintlen(int64_t n);
size_t nghttp3_put_uvarintlen(uint64_t n);
/*
* nghttp3_ord_stream_id returns the ordinal number of |stream_id|.
*/
uint64_t nghttp3_ord_stream_id(int64_t stream_id);
/*
* NGHTTP3_PRI_INC_MASK is a bit mask to retrieve incremental bit from
* a value produced by nghttp3_pri_to_uint8.
*/
#define NGHTTP3_PRI_INC_MASK (1 << 7)
#endif /* !defined(NGHTTP3_CONV_H) */
+35 -33
View File
@@ -31,69 +31,70 @@
#include "nghttp3_conv.h"
#include "nghttp3_str.h"
uint8_t *nghttp3_frame_write_hd(uint8_t *p, int64_t type, int64_t payloadlen) {
p = nghttp3_put_varint(p, type);
p = nghttp3_put_varint(p, payloadlen);
uint8_t *nghttp3_frame_write_hd(uint8_t *p, uint64_t type,
uint64_t payloadlen) {
p = nghttp3_put_uvarint(p, type);
p = nghttp3_put_uvarint(p, payloadlen);
return p;
}
size_t nghttp3_frame_write_hd_len(int64_t type, int64_t payloadlen) {
return nghttp3_put_varintlen(type) + nghttp3_put_varintlen(payloadlen);
size_t nghttp3_frame_write_hd_len(uint64_t type, uint64_t payloadlen) {
return nghttp3_put_uvarintlen(type) + nghttp3_put_uvarintlen(payloadlen);
}
uint8_t *nghttp3_frame_write_settings(uint8_t *p,
const nghttp3_frame_settings *fr,
int64_t payloadlen) {
uint64_t payloadlen) {
size_t i;
p = nghttp3_frame_write_hd(p, fr->type, payloadlen);
for (i = 0; i < fr->niv; ++i) {
p = nghttp3_put_varint(p, (int64_t)fr->iv[i].id);
p = nghttp3_put_varint(p, (int64_t)fr->iv[i].value);
p = nghttp3_put_uvarint(p, fr->iv[i].id);
p = nghttp3_put_uvarint(p, fr->iv[i].value);
}
return p;
}
size_t nghttp3_frame_write_settings_len(int64_t *ppayloadlen,
size_t nghttp3_frame_write_settings_len(uint64_t *ppayloadlen,
const nghttp3_frame_settings *fr) {
size_t payloadlen = 0;
size_t i;
for (i = 0; i < fr->niv; ++i) {
payloadlen += nghttp3_put_varintlen((int64_t)fr->iv[i].id) +
nghttp3_put_varintlen((int64_t)fr->iv[i].value);
payloadlen += nghttp3_put_uvarintlen(fr->iv[i].id) +
nghttp3_put_uvarintlen(fr->iv[i].value);
}
*ppayloadlen = (int64_t)payloadlen;
*ppayloadlen = payloadlen;
return nghttp3_put_varintlen(NGHTTP3_FRAME_SETTINGS) +
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
return nghttp3_put_uvarintlen(NGHTTP3_FRAME_SETTINGS) +
nghttp3_put_uvarintlen(payloadlen) + payloadlen;
}
uint8_t *nghttp3_frame_write_goaway(uint8_t *p, const nghttp3_frame_goaway *fr,
int64_t payloadlen) {
uint64_t payloadlen) {
p = nghttp3_frame_write_hd(p, fr->type, payloadlen);
p = nghttp3_put_varint(p, fr->id);
p = nghttp3_put_uvarint(p, (uint64_t)fr->id);
return p;
}
size_t nghttp3_frame_write_goaway_len(int64_t *ppayloadlen,
size_t nghttp3_frame_write_goaway_len(uint64_t *ppayloadlen,
const nghttp3_frame_goaway *fr) {
size_t payloadlen = nghttp3_put_varintlen(fr->id);
size_t payloadlen = nghttp3_put_uvarintlen((uint64_t)fr->id);
*ppayloadlen = (int64_t)payloadlen;
*ppayloadlen = payloadlen;
return nghttp3_put_varintlen(NGHTTP3_FRAME_GOAWAY) +
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
return nghttp3_put_uvarintlen(NGHTTP3_FRAME_GOAWAY) +
nghttp3_put_uvarintlen(payloadlen) + payloadlen;
}
uint8_t *nghttp3_frame_write_priority_update(
uint8_t *p, const nghttp3_frame_priority_update *fr, int64_t payloadlen) {
uint8_t *p, const nghttp3_frame_priority_update *fr, uint64_t payloadlen) {
p = nghttp3_frame_write_hd(p, fr->type, payloadlen);
p = nghttp3_put_varint(p, fr->pri_elem_id);
p = nghttp3_put_uvarint(p, (uint64_t)fr->pri_elem_id);
if (fr->datalen) {
p = nghttp3_cpymem(p, fr->data, fr->datalen);
}
@@ -102,17 +103,18 @@ uint8_t *nghttp3_frame_write_priority_update(
}
size_t nghttp3_frame_write_priority_update_len(
int64_t *ppayloadlen, const nghttp3_frame_priority_update *fr) {
size_t payloadlen = nghttp3_put_varintlen(fr->pri_elem_id) + fr->datalen;
uint64_t *ppayloadlen, const nghttp3_frame_priority_update *fr) {
size_t payloadlen =
nghttp3_put_uvarintlen((uint64_t)fr->pri_elem_id) + fr->datalen;
*ppayloadlen = (int64_t)payloadlen;
*ppayloadlen = payloadlen;
return nghttp3_put_varintlen(fr->type) +
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
return nghttp3_put_uvarintlen(fr->type) + nghttp3_put_uvarintlen(payloadlen) +
payloadlen;
}
uint8_t *nghttp3_frame_write_origin(uint8_t *p, const nghttp3_frame_origin *fr,
int64_t payloadlen) {
uint64_t payloadlen) {
p = nghttp3_frame_write_hd(p, fr->type, payloadlen);
if (fr->origin_list.len) {
p = nghttp3_cpymem(p, fr->origin_list.base, fr->origin_list.len);
@@ -121,14 +123,14 @@ uint8_t *nghttp3_frame_write_origin(uint8_t *p, const nghttp3_frame_origin *fr,
return p;
}
size_t nghttp3_frame_write_origin_len(int64_t *ppayloadlen,
size_t nghttp3_frame_write_origin_len(uint64_t *ppayloadlen,
const nghttp3_frame_origin *fr) {
size_t payloadlen = fr->origin_list.len;
*ppayloadlen = (int64_t)payloadlen;
*ppayloadlen = payloadlen;
return nghttp3_put_varintlen(fr->type) +
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
return nghttp3_put_uvarintlen(fr->type) + nghttp3_put_uvarintlen(payloadlen) +
payloadlen;
}
int nghttp3_nva_copy(nghttp3_nv **pnva, const nghttp3_nv *nva, size_t nvlen,
+41 -41
View File
@@ -34,53 +34,53 @@
#include "nghttp3_buf.h"
#define NGHTTP3_FRAME_DATA 0x00
#define NGHTTP3_FRAME_HEADERS 0x01
#define NGHTTP3_FRAME_CANCEL_PUSH 0x03
#define NGHTTP3_FRAME_SETTINGS 0x04
#define NGHTTP3_FRAME_PUSH_PROMISE 0x05
#define NGHTTP3_FRAME_GOAWAY 0x07
#define NGHTTP3_FRAME_MAX_PUSH_ID 0x0d
#define NGHTTP3_FRAME_DATA 0x00U
#define NGHTTP3_FRAME_HEADERS 0x01U
#define NGHTTP3_FRAME_CANCEL_PUSH 0x03U
#define NGHTTP3_FRAME_SETTINGS 0x04U
#define NGHTTP3_FRAME_PUSH_PROMISE 0x05U
#define NGHTTP3_FRAME_GOAWAY 0x07U
#define NGHTTP3_FRAME_MAX_PUSH_ID 0x0DU
/* PRIORITY_UPDATE: https://datatracker.ietf.org/doc/html/rfc9218 */
#define NGHTTP3_FRAME_PRIORITY_UPDATE 0x0f0700
#define NGHTTP3_FRAME_PRIORITY_UPDATE_PUSH_ID 0x0f0701
#define NGHTTP3_FRAME_PRIORITY_UPDATE 0x0F0700U
#define NGHTTP3_FRAME_PRIORITY_UPDATE_PUSH_ID 0x0F0701U
/* ORIGIN: https://datatracker.ietf.org/doc/html/rfc9412 */
#define NGHTTP3_FRAME_ORIGIN 0x0c
#define NGHTTP3_FRAME_ORIGIN 0x0CU
/* Frame types that are reserved for HTTP/2, and must not be used in
HTTP/3. */
#define NGHTTP3_H2_FRAME_PRIORITY 0x02
#define NGHTTP3_H2_FRAME_PING 0x06
#define NGHTTP3_H2_FRAME_WINDOW_UPDATE 0x08
#define NGHTTP3_H2_FRAME_CONTINUATION 0x9
#define NGHTTP3_H2_FRAME_PRIORITY 0x02U
#define NGHTTP3_H2_FRAME_PING 0x06U
#define NGHTTP3_H2_FRAME_WINDOW_UPDATE 0x08U
#define NGHTTP3_H2_FRAME_CONTINUATION 0x9U
typedef struct nghttp3_frame_hd {
int64_t type;
uint64_t type;
} nghttp3_frame_hd;
typedef struct nghttp3_frame_data {
int64_t type;
uint64_t type;
/* dr is set when sending DATA frame. It is not used on
reception. */
nghttp3_data_reader dr;
} nghttp3_frame_data;
typedef struct nghttp3_frame_headers {
int64_t type;
uint64_t type;
nghttp3_nv *nva;
size_t nvlen;
} nghttp3_frame_headers;
#define NGHTTP3_SETTINGS_ID_MAX_FIELD_SECTION_SIZE 0x06
#define NGHTTP3_SETTINGS_ID_QPACK_MAX_TABLE_CAPACITY 0x01
#define NGHTTP3_SETTINGS_ID_QPACK_BLOCKED_STREAMS 0x07
#define NGHTTP3_SETTINGS_ID_ENABLE_CONNECT_PROTOCOL 0x08
#define NGHTTP3_SETTINGS_ID_H3_DATAGRAM 0x33
#define NGHTTP3_SETTINGS_ID_MAX_FIELD_SECTION_SIZE 0x06U
#define NGHTTP3_SETTINGS_ID_QPACK_MAX_TABLE_CAPACITY 0x01U
#define NGHTTP3_SETTINGS_ID_QPACK_BLOCKED_STREAMS 0x07U
#define NGHTTP3_SETTINGS_ID_ENABLE_CONNECT_PROTOCOL 0x08U
#define NGHTTP3_SETTINGS_ID_H3_DATAGRAM 0x33U
#define NGHTTP3_H2_SETTINGS_ID_ENABLE_PUSH 0x2
#define NGHTTP3_H2_SETTINGS_ID_MAX_CONCURRENT_STREAMS 0x3
#define NGHTTP3_H2_SETTINGS_ID_INITIAL_WINDOW_SIZE 0x4
#define NGHTTP3_H2_SETTINGS_ID_MAX_FRAME_SIZE 0x5
#define NGHTTP3_H2_SETTINGS_ID_ENABLE_PUSH 0x2U
#define NGHTTP3_H2_SETTINGS_ID_MAX_CONCURRENT_STREAMS 0x3U
#define NGHTTP3_H2_SETTINGS_ID_INITIAL_WINDOW_SIZE 0x4U
#define NGHTTP3_H2_SETTINGS_ID_MAX_FRAME_SIZE 0x5U
typedef struct nghttp3_settings_entry {
uint64_t id;
@@ -88,7 +88,7 @@ typedef struct nghttp3_settings_entry {
} nghttp3_settings_entry;
typedef struct nghttp3_frame_settings {
int64_t type;
uint64_t type;
size_t niv;
nghttp3_settings_entry *iv;
/* local_settings is set when sending SETTINGS frame. It is not
@@ -97,12 +97,12 @@ typedef struct nghttp3_frame_settings {
} nghttp3_frame_settings;
typedef struct nghttp3_frame_goaway {
int64_t type;
uint64_t type;
int64_t id;
} nghttp3_frame_goaway;
typedef struct nghttp3_frame_priority_update {
int64_t type;
uint64_t type;
/* pri_elem_id is stream ID if type ==
NGHTTP3_FRAME_PRIORITY_UPDATE. It is push ID if type ==
NGHTTP3_FRAME_PRIORITY_UPDATE_PUSH_ID. It is undefined
@@ -126,7 +126,7 @@ typedef struct nghttp3_frame_priority_update {
} nghttp3_frame_priority_update;
typedef struct nghttp3_frame_origin {
int64_t type;
uint64_t type;
/* These fields are only used by server to send ORIGIN frame.
Client never use them. */
nghttp3_vec origin_list;
@@ -149,14 +149,14 @@ typedef union nghttp3_frame {
*
* This function returns |dest| plus the number of bytes written.
*/
uint8_t *nghttp3_frame_write_hd(uint8_t *dest, int64_t type,
int64_t payloadlen);
uint8_t *nghttp3_frame_write_hd(uint8_t *dest, uint64_t type,
uint64_t payloadlen);
/*
* nghttp3_frame_write_hd_len returns the number of bytes required to
* write a frame header consisting of |type| and |payloadlen|.
*/
size_t nghttp3_frame_write_hd_len(int64_t type, int64_t payloadlen);
size_t nghttp3_frame_write_hd_len(uint64_t type, uint64_t payloadlen);
/*
* nghttp3_frame_write_settings writes SETTINGS frame |fr| to |dest|.
@@ -167,14 +167,14 @@ size_t nghttp3_frame_write_hd_len(int64_t type, int64_t payloadlen);
*/
uint8_t *nghttp3_frame_write_settings(uint8_t *dest,
const nghttp3_frame_settings *fr,
int64_t payloadlen);
uint64_t payloadlen);
/*
* nghttp3_frame_write_settings_len returns the number of bytes
* required to write |fr|. This function stores the frame payload
* length in |*ppayloadlen|.
*/
size_t nghttp3_frame_write_settings_len(int64_t *pppayloadlen,
size_t nghttp3_frame_write_settings_len(uint64_t *pppayloadlen,
const nghttp3_frame_settings *fr);
/*
@@ -186,14 +186,14 @@ size_t nghttp3_frame_write_settings_len(int64_t *pppayloadlen,
*/
uint8_t *nghttp3_frame_write_goaway(uint8_t *dest,
const nghttp3_frame_goaway *fr,
int64_t payloadlen);
uint64_t payloadlen);
/*
* nghttp3_frame_write_goaway_len returns the number of bytes required
* to write |fr|. This function stores the frame payload length in
* |*ppayloadlen|.
*/
size_t nghttp3_frame_write_goaway_len(int64_t *ppayloadlen,
size_t nghttp3_frame_write_goaway_len(uint64_t *ppayloadlen,
const nghttp3_frame_goaway *fr);
/*
@@ -204,7 +204,7 @@ size_t nghttp3_frame_write_goaway_len(int64_t *ppayloadlen,
* This function returns |dest| plus the number of bytes written;
*/
uint8_t *nghttp3_frame_write_priority_update(
uint8_t *dest, const nghttp3_frame_priority_update *fr, int64_t payloadlen);
uint8_t *dest, const nghttp3_frame_priority_update *fr, uint64_t payloadlen);
/*
* nghttp3_frame_write_priority_update_len returns the number of bytes
@@ -212,7 +212,7 @@ uint8_t *nghttp3_frame_write_priority_update(
* length in |*ppayloadlen|.
*/
size_t nghttp3_frame_write_priority_update_len(
int64_t *ppayloadlen, const nghttp3_frame_priority_update *fr);
uint64_t *ppayloadlen, const nghttp3_frame_priority_update *fr);
/*
* nghttp3_frame_write_origin writes ORIGIN frame |fr| to |dest|.
@@ -223,14 +223,14 @@ size_t nghttp3_frame_write_priority_update_len(
*/
uint8_t *nghttp3_frame_write_origin(uint8_t *dest,
const nghttp3_frame_origin *fr,
int64_t payloadlen);
uint64_t payloadlen);
/*
* nghttp3_frame_write_origin_len returns the number of bytes required
* to write |fr|. This function stores the frame payload length in
* |*ppayloadlen|.
*/
size_t nghttp3_frame_write_origin_len(int64_t *ppayloadlen,
size_t nghttp3_frame_write_origin_len(uint64_t *ppayloadlen,
const nghttp3_frame_origin *fr);
/*
+5 -5
View File
@@ -36,11 +36,11 @@ void nghttp3_gaptr_init(nghttp3_gaptr *gaptr, const nghttp3_mem *mem) {
}
static int gaptr_gap_init(nghttp3_gaptr *gaptr) {
return nghttp3_ksl_insert(&gaptr->gap, NULL,
&(nghttp3_range){
.end = UINT64_MAX,
},
NULL);
static const nghttp3_range end = {
.end = UINT64_MAX,
};
return nghttp3_ksl_insert(&gaptr->gap, NULL, &end, NULL);
}
void nghttp3_gaptr_free(nghttp3_gaptr *gaptr) {
+83 -69
View File
@@ -62,27 +62,39 @@ static int memieq(const void *a, const void *b, size_t n) {
#define lstrieq(A, B, N) \
(nghttp3_strlen_lit((A)) == (N) && memieq((A), (B), (N)))
static int32_t parse_status_code(const uint8_t *s, size_t len) {
if (len != 3 || '1' > s[0] || s[0] > '9' || '0' > s[1] || s[1] > '9' ||
'0' > s[2] || s[2] > '9') {
return -1;
}
return (s[0] - '0') * 100 + (s[1] - '0') * 10 + (s[2] - '0');
}
static int64_t parse_uint(const uint8_t *s, size_t len) {
int64_t n = 0;
uint64_t n = 0;
uint32_t c;
size_t i;
if (len == 0) {
return -1;
}
for (i = 0; i < len; ++i) {
if ('0' <= s[i] && s[i] <= '9') {
if (n > (int64_t)NGHTTP3_MAX_VARINT / 10) {
return -1;
}
n *= 10;
if (n > (int64_t)NGHTTP3_MAX_VARINT - (s[i] - '0')) {
return -1;
}
n += s[i] - '0';
continue;
if ('0' > s[i] || s[i] > '9') {
return -1;
}
return -1;
c = s[i] - '0';
if (n > (NGHTTP3_MAX_VARINT - c) / 10) {
return -1;
}
n = n * 10 + c;
}
return n;
return (int64_t)n;
}
static int check_pseudo_header(nghttp3_http_state *http,
@@ -94,7 +106,7 @@ static int check_pseudo_header(nghttp3_http_state *http,
return 1;
}
static int expect_response_body(nghttp3_http_state *http) {
static int expect_response_body(const nghttp3_http_state *http) {
return (http->flags & NGHTTP3_HTTP_FLAG_METH_HEAD) == 0 &&
http->status_code / 100 != 1 && http->status_code != 304 &&
http->status_code != 204;
@@ -105,7 +117,7 @@ static int expect_response_body(nghttp3_http_state *http) {
:path header field value must start with "/". This function must
be called after ":method" header field was received. This function
returns nonzero if path is valid.*/
static int check_path_flags(nghttp3_http_state *http) {
static int check_path_flags(const nghttp3_http_state *http) {
return (http->flags & NGHTTP3_HTTP_FLAG_SCHEME_HTTP) == 0 ||
((http->flags & NGHTTP3_HTTP_FLAG_PATH_REGULAR) ||
((http->flags & NGHTTP3_HTTP_FLAG_METH_OPTIONS) &&
@@ -275,26 +287,26 @@ static const int8_t VALID_PATH_CHARS[256] = {
['u'] = 1, ['v'] = 1, ['w'] = 1, ['x'] = 1, ['y'] = 1, ['z'] = 1,
['{'] = 1, ['|'] = 1, ['}'] = 1, ['~'] = 1, [0x80] = 1, [0x81] = 1,
[0x82] = 1, [0x83] = 1, [0x84] = 1, [0x85] = 1, [0x86] = 1, [0x87] = 1,
[0x88] = 1, [0x89] = 1, [0x8a] = 1, [0x8b] = 1, [0x8c] = 1, [0x8d] = 1,
[0x8e] = 1, [0x8f] = 1, [0x90] = 1, [0x91] = 1, [0x92] = 1, [0x93] = 1,
[0x88] = 1, [0x89] = 1, [0x8A] = 1, [0x8B] = 1, [0x8C] = 1, [0x8D] = 1,
[0x8E] = 1, [0x8F] = 1, [0x90] = 1, [0x91] = 1, [0x92] = 1, [0x93] = 1,
[0x94] = 1, [0x95] = 1, [0x96] = 1, [0x97] = 1, [0x98] = 1, [0x99] = 1,
[0x9a] = 1, [0x9b] = 1, [0x9c] = 1, [0x9d] = 1, [0x9e] = 1, [0x9f] = 1,
[0xa0] = 1, [0xa1] = 1, [0xa2] = 1, [0xa3] = 1, [0xa4] = 1, [0xa5] = 1,
[0xa6] = 1, [0xa7] = 1, [0xa8] = 1, [0xa9] = 1, [0xaa] = 1, [0xab] = 1,
[0xac] = 1, [0xad] = 1, [0xae] = 1, [0xaf] = 1, [0xb0] = 1, [0xb1] = 1,
[0xb2] = 1, [0xb3] = 1, [0xb4] = 1, [0xb5] = 1, [0xb6] = 1, [0xb7] = 1,
[0xb8] = 1, [0xb9] = 1, [0xba] = 1, [0xbb] = 1, [0xbc] = 1, [0xbd] = 1,
[0xbe] = 1, [0xbf] = 1, [0xc0] = 1, [0xc1] = 1, [0xc2] = 1, [0xc3] = 1,
[0xc4] = 1, [0xc5] = 1, [0xc6] = 1, [0xc7] = 1, [0xc8] = 1, [0xc9] = 1,
[0xca] = 1, [0xcb] = 1, [0xcc] = 1, [0xcd] = 1, [0xce] = 1, [0xcf] = 1,
[0xd0] = 1, [0xd1] = 1, [0xd2] = 1, [0xd3] = 1, [0xd4] = 1, [0xd5] = 1,
[0xd6] = 1, [0xd7] = 1, [0xd8] = 1, [0xd9] = 1, [0xda] = 1, [0xdb] = 1,
[0xdc] = 1, [0xdd] = 1, [0xde] = 1, [0xdf] = 1, [0xe0] = 1, [0xe1] = 1,
[0xe2] = 1, [0xe3] = 1, [0xe4] = 1, [0xe5] = 1, [0xe6] = 1, [0xe7] = 1,
[0xe8] = 1, [0xe9] = 1, [0xea] = 1, [0xeb] = 1, [0xec] = 1, [0xed] = 1,
[0xee] = 1, [0xef] = 1, [0xf0] = 1, [0xf1] = 1, [0xf2] = 1, [0xf3] = 1,
[0xf4] = 1, [0xf5] = 1, [0xf6] = 1, [0xf7] = 1, [0xf8] = 1, [0xf9] = 1,
[0xfa] = 1, [0xfb] = 1, [0xfc] = 1, [0xfd] = 1, [0xfe] = 1, [0xff] = 1,
[0x9A] = 1, [0x9B] = 1, [0x9C] = 1, [0x9D] = 1, [0x9E] = 1, [0x9F] = 1,
[0xA0] = 1, [0xA1] = 1, [0xA2] = 1, [0xA3] = 1, [0xA4] = 1, [0xA5] = 1,
[0xA6] = 1, [0xA7] = 1, [0xA8] = 1, [0xA9] = 1, [0xAA] = 1, [0xAB] = 1,
[0xAC] = 1, [0xAD] = 1, [0xAE] = 1, [0xAF] = 1, [0xB0] = 1, [0xB1] = 1,
[0xB2] = 1, [0xB3] = 1, [0xB4] = 1, [0xB5] = 1, [0xB6] = 1, [0xB7] = 1,
[0xB8] = 1, [0xB9] = 1, [0xBA] = 1, [0xBB] = 1, [0xBC] = 1, [0xBD] = 1,
[0xBE] = 1, [0xBF] = 1, [0xC0] = 1, [0xC1] = 1, [0xC2] = 1, [0xC3] = 1,
[0xC4] = 1, [0xC5] = 1, [0xC6] = 1, [0xC7] = 1, [0xC8] = 1, [0xC9] = 1,
[0xCA] = 1, [0xCB] = 1, [0xCC] = 1, [0xCD] = 1, [0xCE] = 1, [0xCF] = 1,
[0xD0] = 1, [0xD1] = 1, [0xD2] = 1, [0xD3] = 1, [0xD4] = 1, [0xD5] = 1,
[0xD6] = 1, [0xD7] = 1, [0xD8] = 1, [0xD9] = 1, [0xDA] = 1, [0xDB] = 1,
[0xDC] = 1, [0xDD] = 1, [0xDE] = 1, [0xDF] = 1, [0xE0] = 1, [0xE1] = 1,
[0xE2] = 1, [0xE3] = 1, [0xE4] = 1, [0xE5] = 1, [0xE6] = 1, [0xE7] = 1,
[0xE8] = 1, [0xE9] = 1, [0xEA] = 1, [0xEB] = 1, [0xEC] = 1, [0xED] = 1,
[0xEE] = 1, [0xEF] = 1, [0xF0] = 1, [0xF1] = 1, [0xF2] = 1, [0xF3] = 1,
[0xF4] = 1, [0xF5] = 1, [0xF6] = 1, [0xF7] = 1, [0xF8] = 1, [0xF9] = 1,
[0xFA] = 1, [0xFB] = 1, [0xFC] = 1, [0xFD] = 1, [0xFE] = 1, [0xFF] = 1,
};
static int check_path(const uint8_t *value, size_t len) {
@@ -308,7 +320,7 @@ static int check_path(const uint8_t *value, size_t len) {
}
static int http_request_on_header(nghttp3_http_state *http,
nghttp3_qpack_nv *nv, int trailers,
const nghttp3_qpack_nv *nv, int trailers,
int connect_protocol) {
nghttp3_pri pri;
@@ -452,15 +464,14 @@ static int http_request_on_header(nghttp3_http_state *http,
}
static int http_response_on_header(nghttp3_http_state *http,
nghttp3_qpack_nv *nv, int trailers) {
const nghttp3_qpack_nv *nv, int trailers) {
switch (nv->token) {
case NGHTTP3_QPACK_TOKEN__STATUS: {
if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG__STATUS) ||
nv->value->len != 3) {
if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG__STATUS)) {
return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
}
http->status_code = (int16_t)parse_uint(nv->value->base, nv->value->len);
if (http->status_code < 100 || http->status_code == 101) {
http->status_code = parse_status_code(nv->value->base, nv->value->len);
if (http->status_code == -1 || http->status_code == 101) {
return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
}
break;
@@ -527,7 +538,7 @@ static int http_response_on_header(nghttp3_http_state *http,
static int http_check_nonempty_header_name(const uint8_t *name, size_t len);
int nghttp3_http_on_header(nghttp3_http_state *http, nghttp3_qpack_nv *nv,
int nghttp3_http_on_header(nghttp3_http_state *http, const nghttp3_qpack_nv *nv,
int request, int trailers, int connect_protocol) {
if (nv->name->len == 0) {
http->flags |= NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED;
@@ -577,10 +588,13 @@ int nghttp3_http_on_request_headers(nghttp3_http_state *http) {
(NGHTTP3_HTTP_FLAG__AUTHORITY | NGHTTP3_HTTP_FLAG_HOST)) == 0) {
return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
}
if ((http->flags & NGHTTP3_HTTP_FLAG__PROTOCOL) &&
((http->flags & NGHTTP3_HTTP_FLAG_METH_CONNECT) == 0 ||
(http->flags & NGHTTP3_HTTP_FLAG__AUTHORITY) == 0)) {
return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
if (http->flags & NGHTTP3_HTTP_FLAG__PROTOCOL) {
if ((http->flags & NGHTTP3_HTTP_FLAG_METH_CONNECT) == 0 ||
(http->flags & NGHTTP3_HTTP_FLAG__AUTHORITY) == 0) {
return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
}
http->content_length = -1;
}
if (!check_path_flags(http)) {
return NGHTTP3_ERR_MALFORMED_HTTP_HEADER;
@@ -615,7 +629,7 @@ int nghttp3_http_on_response_headers(nghttp3_http_state *http) {
return 0;
}
int nghttp3_http_on_remote_end_stream(nghttp3_stream *stream) {
int nghttp3_http_on_remote_end_stream(const nghttp3_stream *stream) {
if ((stream->rx.http.flags & NGHTTP3_HTTP_FLAG_EXPECT_FINAL_RESPONSE) ||
(stream->rx.http.content_length != -1 &&
stream->rx.http.content_length != stream->rx.http.recv_content_length)) {
@@ -733,36 +747,36 @@ static const int8_t VALID_HD_VALUE_CHARS[256] = {
['s'] = 1, ['t'] = 1, ['u'] = 1, ['v'] = 1, ['w'] = 1, ['x'] = 1,
['y'] = 1, ['z'] = 1, ['{'] = 1, ['|'] = 1, ['}'] = 1, ['~'] = 1,
[0x80] = 1, [0x81] = 1, [0x82] = 1, [0x83] = 1, [0x84] = 1, [0x85] = 1,
[0x86] = 1, [0x87] = 1, [0x88] = 1, [0x89] = 1, [0x8a] = 1, [0x8b] = 1,
[0x8c] = 1, [0x8d] = 1, [0x8e] = 1, [0x8f] = 1, [0x90] = 1, [0x91] = 1,
[0x86] = 1, [0x87] = 1, [0x88] = 1, [0x89] = 1, [0x8A] = 1, [0x8B] = 1,
[0x8C] = 1, [0x8D] = 1, [0x8E] = 1, [0x8F] = 1, [0x90] = 1, [0x91] = 1,
[0x92] = 1, [0x93] = 1, [0x94] = 1, [0x95] = 1, [0x96] = 1, [0x97] = 1,
[0x98] = 1, [0x99] = 1, [0x9a] = 1, [0x9b] = 1, [0x9c] = 1, [0x9d] = 1,
[0x9e] = 1, [0x9f] = 1, [0xa0] = 1, [0xa1] = 1, [0xa2] = 1, [0xa3] = 1,
[0xa4] = 1, [0xa5] = 1, [0xa6] = 1, [0xa7] = 1, [0xa8] = 1, [0xa9] = 1,
[0xaa] = 1, [0xab] = 1, [0xac] = 1, [0xad] = 1, [0xae] = 1, [0xaf] = 1,
[0xb0] = 1, [0xb1] = 1, [0xb2] = 1, [0xb3] = 1, [0xb4] = 1, [0xb5] = 1,
[0xb6] = 1, [0xb7] = 1, [0xb8] = 1, [0xb9] = 1, [0xba] = 1, [0xbb] = 1,
[0xbc] = 1, [0xbd] = 1, [0xbe] = 1, [0xbf] = 1, [0xc0] = 1, [0xc1] = 1,
[0xc2] = 1, [0xc3] = 1, [0xc4] = 1, [0xc5] = 1, [0xc6] = 1, [0xc7] = 1,
[0xc8] = 1, [0xc9] = 1, [0xca] = 1, [0xcb] = 1, [0xcc] = 1, [0xcd] = 1,
[0xce] = 1, [0xcf] = 1, [0xd0] = 1, [0xd1] = 1, [0xd2] = 1, [0xd3] = 1,
[0xd4] = 1, [0xd5] = 1, [0xd6] = 1, [0xd7] = 1, [0xd8] = 1, [0xd9] = 1,
[0xda] = 1, [0xdb] = 1, [0xdc] = 1, [0xdd] = 1, [0xde] = 1, [0xdf] = 1,
[0xe0] = 1, [0xe1] = 1, [0xe2] = 1, [0xe3] = 1, [0xe4] = 1, [0xe5] = 1,
[0xe6] = 1, [0xe7] = 1, [0xe8] = 1, [0xe9] = 1, [0xea] = 1, [0xeb] = 1,
[0xec] = 1, [0xed] = 1, [0xee] = 1, [0xef] = 1, [0xf0] = 1, [0xf1] = 1,
[0xf2] = 1, [0xf3] = 1, [0xf4] = 1, [0xf5] = 1, [0xf6] = 1, [0xf7] = 1,
[0xf8] = 1, [0xf9] = 1, [0xfa] = 1, [0xfb] = 1, [0xfc] = 1, [0xfd] = 1,
[0xfe] = 1, [0xff] = 1,
[0x98] = 1, [0x99] = 1, [0x9A] = 1, [0x9B] = 1, [0x9C] = 1, [0x9D] = 1,
[0x9E] = 1, [0x9F] = 1, [0xA0] = 1, [0xA1] = 1, [0xA2] = 1, [0xA3] = 1,
[0xA4] = 1, [0xA5] = 1, [0xA6] = 1, [0xA7] = 1, [0xA8] = 1, [0xA9] = 1,
[0xAA] = 1, [0xAB] = 1, [0xAC] = 1, [0xAD] = 1, [0xAE] = 1, [0xAF] = 1,
[0xB0] = 1, [0xB1] = 1, [0xB2] = 1, [0xB3] = 1, [0xB4] = 1, [0xB5] = 1,
[0xB6] = 1, [0xB7] = 1, [0xB8] = 1, [0xB9] = 1, [0xBA] = 1, [0xBB] = 1,
[0xBC] = 1, [0xBD] = 1, [0xBE] = 1, [0xBF] = 1, [0xC0] = 1, [0xC1] = 1,
[0xC2] = 1, [0xC3] = 1, [0xC4] = 1, [0xC5] = 1, [0xC6] = 1, [0xC7] = 1,
[0xC8] = 1, [0xC9] = 1, [0xCA] = 1, [0xCB] = 1, [0xCC] = 1, [0xCD] = 1,
[0xCE] = 1, [0xCF] = 1, [0xD0] = 1, [0xD1] = 1, [0xD2] = 1, [0xD3] = 1,
[0xD4] = 1, [0xD5] = 1, [0xD6] = 1, [0xD7] = 1, [0xD8] = 1, [0xD9] = 1,
[0xDA] = 1, [0xDB] = 1, [0xDC] = 1, [0xDD] = 1, [0xDE] = 1, [0xDF] = 1,
[0xE0] = 1, [0xE1] = 1, [0xE2] = 1, [0xE3] = 1, [0xE4] = 1, [0xE5] = 1,
[0xE6] = 1, [0xE7] = 1, [0xE8] = 1, [0xE9] = 1, [0xEA] = 1, [0xEB] = 1,
[0xEC] = 1, [0xED] = 1, [0xEE] = 1, [0xEF] = 1, [0xF0] = 1, [0xF1] = 1,
[0xF2] = 1, [0xF3] = 1, [0xF4] = 1, [0xF5] = 1, [0xF6] = 1, [0xF7] = 1,
[0xF8] = 1, [0xF9] = 1, [0xFA] = 1, [0xFB] = 1, [0xFC] = 1, [0xFD] = 1,
[0xFE] = 1, [0xFF] = 1,
};
#ifdef __AVX2__
static int contains_bad_header_value_char_avx2(const uint8_t *first,
const uint8_t *last) {
const __m256i ctll = _mm256_set1_epi8(0x00 - 1);
const __m256i ctlr = _mm256_set1_epi8(0x1f + 1);
const __m256i ctlr = _mm256_set1_epi8(0x1F + 1);
const __m256i ht = _mm256_set1_epi8('\t');
const __m256i del = _mm256_set1_epi8(0x7f);
const __m256i del = _mm256_set1_epi8(0x7F);
__m256i s, x;
uint32_t m;
@@ -809,7 +823,7 @@ int nghttp3_check_header_value(const uint8_t *value, size_t len) {
#ifdef __AVX2__
if (len >= 32) {
last32 = value + (len & ~0x1fu);
last32 = value + (len & ~(size_t)0x1FU);
if (contains_bad_header_value_char_avx2(value, last32)) {
return 0;
}
+20 -20
View File
@@ -39,48 +39,48 @@ typedef struct nghttp3_http_state nghttp3_http_state;
/* HTTP related flags to enforce HTTP semantics */
/* NGHTTP3_HTTP_FLAG_NONE indicates that no flag is set. */
#define NGHTTP3_HTTP_FLAG_NONE 0x00u
#define NGHTTP3_HTTP_FLAG_NONE 0x00U
/* header field seen so far */
#define NGHTTP3_HTTP_FLAG__AUTHORITY 0x01u
#define NGHTTP3_HTTP_FLAG__PATH 0x02u
#define NGHTTP3_HTTP_FLAG__METHOD 0x04u
#define NGHTTP3_HTTP_FLAG__SCHEME 0x08u
#define NGHTTP3_HTTP_FLAG__AUTHORITY 0x01U
#define NGHTTP3_HTTP_FLAG__PATH 0x02U
#define NGHTTP3_HTTP_FLAG__METHOD 0x04U
#define NGHTTP3_HTTP_FLAG__SCHEME 0x08U
/* host is not pseudo header, but we require either host or
:authority */
#define NGHTTP3_HTTP_FLAG_HOST 0x10u
#define NGHTTP3_HTTP_FLAG__STATUS 0x20u
#define NGHTTP3_HTTP_FLAG_HOST 0x10U
#define NGHTTP3_HTTP_FLAG__STATUS 0x20U
/* required header fields for HTTP request except for CONNECT
method. */
#define NGHTTP3_HTTP_FLAG_REQ_HEADERS \
(NGHTTP3_HTTP_FLAG__METHOD | NGHTTP3_HTTP_FLAG__PATH | \
NGHTTP3_HTTP_FLAG__SCHEME)
#define NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED 0x40u
#define NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED 0x40U
/* HTTP method flags */
#define NGHTTP3_HTTP_FLAG_METH_CONNECT 0x80u
#define NGHTTP3_HTTP_FLAG_METH_HEAD 0x0100u
#define NGHTTP3_HTTP_FLAG_METH_OPTIONS 0x0200u
#define NGHTTP3_HTTP_FLAG_METH_CONNECT 0x80U
#define NGHTTP3_HTTP_FLAG_METH_HEAD 0x0100U
#define NGHTTP3_HTTP_FLAG_METH_OPTIONS 0x0200U
#define NGHTTP3_HTTP_FLAG_METH_ALL \
(NGHTTP3_HTTP_FLAG_METH_CONNECT | NGHTTP3_HTTP_FLAG_METH_HEAD | \
NGHTTP3_HTTP_FLAG_METH_OPTIONS)
/* :path category */
/* path starts with "/" */
#define NGHTTP3_HTTP_FLAG_PATH_REGULAR 0x0400u
#define NGHTTP3_HTTP_FLAG_PATH_REGULAR 0x0400U
/* path "*" */
#define NGHTTP3_HTTP_FLAG_PATH_ASTERISK 0x0800u
#define NGHTTP3_HTTP_FLAG_PATH_ASTERISK 0x0800U
/* scheme */
/* "http" or "https" scheme */
#define NGHTTP3_HTTP_FLAG_SCHEME_HTTP 0x1000u
#define NGHTTP3_HTTP_FLAG_SCHEME_HTTP 0x1000U
/* set if final response is expected */
#define NGHTTP3_HTTP_FLAG_EXPECT_FINAL_RESPONSE 0x2000u
#define NGHTTP3_HTTP_FLAG_EXPECT_FINAL_RESPONSE 0x2000U
/* NGHTTP3_HTTP_FLAG__PROTOCOL is set when :protocol pseudo header
field is seen. */
#define NGHTTP3_HTTP_FLAG__PROTOCOL 0x4000u
#define NGHTTP3_HTTP_FLAG__PROTOCOL 0x4000U
/* NGHTTP3_HTTP_FLAG_PRIORITY is set when priority header field is
processed. */
#define NGHTTP3_HTTP_FLAG_PRIORITY 0x8000u
#define NGHTTP3_HTTP_FLAG_PRIORITY 0x8000U
/* NGHTTP3_HTTP_FLAG_BAD_PRIORITY is set when an error is encountered
while parsing priority header field. */
#define NGHTTP3_HTTP_FLAG_BAD_PRIORITY 0x010000u
#define NGHTTP3_HTTP_FLAG_BAD_PRIORITY 0x010000U
/*
* This function is called when HTTP header field |nv| received for
@@ -98,7 +98,7 @@ typedef struct nghttp3_http_state nghttp3_http_state;
* Invalid HTTP header field was received but it can be treated as
* if it was not received because of compatibility reasons.
*/
int nghttp3_http_on_header(nghttp3_http_state *http, nghttp3_qpack_nv *nv,
int nghttp3_http_on_header(nghttp3_http_state *http, const nghttp3_qpack_nv *nv,
int request, int trailers, int connect_protocol);
/*
@@ -131,7 +131,7 @@ int nghttp3_http_on_response_headers(nghttp3_http_state *http);
* NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING
* HTTP messaging is violated.
*/
int nghttp3_http_on_remote_end_stream(nghttp3_stream *stream);
int nghttp3_http_on_remote_end_stream(const nghttp3_stream *stream);
/*
* This function is called when chunk of data is received. This
+3 -28
View File
@@ -32,7 +32,6 @@
#include "nghttp3_macro.h"
#include "nghttp3_mem.h"
#include "nghttp3_range.h"
static nghttp3_ksl_blk null_blk;
@@ -57,13 +56,12 @@ void nghttp3_ksl_init(nghttp3_ksl *ksl, nghttp3_ksl_compar compar,
assert(keylen >= sizeof(uint64_t));
aligned_keylen = (keylen + 0x7u) & ~0x7u;
aligned_keylen = (keylen + 0x7U) & ~(size_t)0x7U;
assert(aligned_keylen <= UINT16_MAX);
nghttp3_objalloc_init(&ksl->blkalloc,
(ksl_blklen(aligned_keylen) + 0xfu) & ~(uintptr_t)0xfu,
mem);
nghttp3_objalloc_init(
&ksl->blkalloc, (ksl_blklen(aligned_keylen) + 0xFU) & ~(size_t)0xFU, mem);
ksl->root = NULL;
ksl->front = ksl->back = NULL;
@@ -817,12 +815,6 @@ int nghttp3_ksl_it_begin(const nghttp3_ksl_it *it) {
return it->i == 0 && it->blk->prev == NULL;
}
int nghttp3_ksl_range_compar(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs) {
const nghttp3_range *a = lhs, *b = rhs;
return a->begin < b->begin;
}
nghttp3_ksl_search_def(range, nghttp3_ksl_range_compar)
size_t nghttp3_ksl_range_search(const nghttp3_ksl *ksl, nghttp3_ksl_blk *blk,
@@ -830,13 +822,6 @@ size_t nghttp3_ksl_range_search(const nghttp3_ksl *ksl, nghttp3_ksl_blk *blk,
return ksl_range_search(ksl, blk, key);
}
int nghttp3_ksl_range_exclusive_compar(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs) {
const nghttp3_range *a = lhs, *b = rhs;
return a->begin < b->begin && !(nghttp3_max_uint64(a->begin, b->begin) <
nghttp3_min_uint64(a->end, b->end));
}
nghttp3_ksl_search_def(range_exclusive, nghttp3_ksl_range_exclusive_compar)
size_t nghttp3_ksl_range_exclusive_search(const nghttp3_ksl *ksl,
@@ -845,11 +830,6 @@ size_t nghttp3_ksl_range_exclusive_search(const nghttp3_ksl *ksl,
return ksl_range_exclusive_search(ksl, blk, key);
}
int nghttp3_ksl_uint64_less(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs) {
return *(uint64_t *)lhs < *(uint64_t *)rhs;
}
nghttp3_ksl_search_def(uint64_less, nghttp3_ksl_uint64_less)
size_t nghttp3_ksl_uint64_less_search(const nghttp3_ksl *ksl,
@@ -858,11 +838,6 @@ size_t nghttp3_ksl_uint64_less_search(const nghttp3_ksl *ksl,
return ksl_uint64_less_search(ksl, blk, key);
}
int nghttp3_ksl_int64_greater(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs) {
return *(int64_t *)lhs > *(int64_t *)rhs;
}
nghttp3_ksl_search_def(int64_greater, nghttp3_ksl_int64_greater)
size_t nghttp3_ksl_int64_greater_search(const nghttp3_ksl *ksl,
+23 -8
View File
@@ -35,6 +35,7 @@
#include <nghttp3/nghttp3.h>
#include "nghttp3_objalloc.h"
#include "nghttp3_range.h"
#define NGHTTP3_KSL_DEGR 16
/* NGHTTP3_KSL_MAX_NBLK is the maximum number of nodes which a single
@@ -360,8 +361,12 @@ nghttp3_ksl_it_key(const nghttp3_ksl_it *it) {
* object, and the function returns nonzero if ((const nghttp3_range
* *)lhs)->begin < ((const nghttp3_range *)rhs)->begin.
*/
int nghttp3_ksl_range_compar(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs);
static inline int nghttp3_ksl_range_compar(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs) {
const nghttp3_range *a = (const nghttp3_range *)lhs,
*b = (const nghttp3_range *)rhs;
return a->begin < b->begin;
}
/*
* nghttp3_ksl_range_search is an implementation of nghttp3_ksl_search
@@ -377,8 +382,14 @@ size_t nghttp3_ksl_range_search(const nghttp3_ksl *ksl, nghttp3_ksl_blk *blk,
* *)lhs)->begin < ((const nghttp3_range *)rhs)->begin, and the 2
* ranges do not intersect.
*/
int nghttp3_ksl_range_exclusive_compar(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs);
static inline int
nghttp3_ksl_range_exclusive_compar(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs) {
const nghttp3_range *a = (const nghttp3_range *)lhs,
*b = (const nghttp3_range *)rhs;
return a->begin < b->begin &&
!(nghttp3_max(a->begin, b->begin) < nghttp3_min(a->end, b->end));
}
/*
* nghttp3_ksl_range_exclusive_search is an implementation of
@@ -393,8 +404,10 @@ size_t nghttp3_ksl_range_exclusive_search(const nghttp3_ksl *ksl,
* |lhs| and |rhs| must point to uint64_t objects, and the function
* returns nonzero if *(uint64_t *)|lhs| < *(uint64_t *)|rhs|.
*/
int nghttp3_ksl_uint64_less(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs);
static inline int nghttp3_ksl_uint64_less(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs) {
return *(const uint64_t *)lhs < *(const uint64_t *)rhs;
}
/*
* nghttp3_ksl_uint64_less_search is an implementation of
@@ -410,8 +423,10 @@ size_t nghttp3_ksl_uint64_less_search(const nghttp3_ksl *ksl,
* and the function returns nonzero if *(int64_t *)|lhs| > *(int64_t
* *)|rhs|.
*/
int nghttp3_ksl_int64_greater(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs);
static inline int nghttp3_ksl_int64_greater(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs) {
return *(const int64_t *)lhs > *(const int64_t *)rhs;
}
/*
* nghttp3_ksl_int64_greater_search is an implementation of
+72 -18
View File
@@ -56,27 +56,81 @@
#define nghttp3_max_def(SUFFIX, T) \
static inline T nghttp3_max_##SUFFIX(T a, T b) { return a < b ? b : a; }
nghttp3_max_def(int8, int8_t)
nghttp3_max_def(int16, int16_t)
nghttp3_max_def(int32, int32_t)
nghttp3_max_def(int64, int64_t)
nghttp3_max_def(uint8, uint8_t)
nghttp3_max_def(uint16, uint16_t)
nghttp3_max_def(uint32, uint32_t)
nghttp3_max_def(uint64, uint64_t)
nghttp3_max_def(size, size_t)
nghttp3_max_def(long_long_int, long long int)
nghttp3_max_def(long_int, long int)
nghttp3_max_def(int, int)
nghttp3_max_def(short_int, short int)
nghttp3_max_def(signed_char, signed char)
nghttp3_max_def(char, char)
nghttp3_max_def(unsigned_long_long_int, unsigned long long int)
nghttp3_max_def(unsigned_long_int, unsigned long int)
nghttp3_max_def(unsigned_int, unsigned int)
nghttp3_max_def(unsigned_short_int, unsigned short int)
nghttp3_max_def(unsigned_char, unsigned char)
#define nghttp3_max(A, B) \
_Generic((A), \
long long int: nghttp3_max_long_long_int, \
long int: nghttp3_max_long_int, \
int: _Generic((B), \
long long int: nghttp3_max_long_long_int, \
long int: nghttp3_max_long_int, \
int: nghttp3_max_int, \
short int: nghttp3_max_short_int, \
signed char: nghttp3_max_signed_char, \
char: nghttp3_max_char, \
unsigned long long int: nghttp3_max_unsigned_long_long_int, \
unsigned long int: nghttp3_max_unsigned_long_int, \
unsigned int: nghttp3_max_unsigned_int, \
unsigned short int: nghttp3_max_unsigned_short_int, \
unsigned char: nghttp3_max_unsigned_char), \
short int: nghttp3_max_short_int, \
signed char: nghttp3_max_signed_char, \
char: nghttp3_max_char, \
unsigned long long int: nghttp3_max_unsigned_long_long_int, \
unsigned long int: nghttp3_max_unsigned_long_int, \
unsigned int: nghttp3_max_unsigned_int, \
unsigned short int: nghttp3_max_unsigned_short_int, \
unsigned char: nghttp3_max_unsigned_char)((A), (B))
#define nghttp3_min_def(SUFFIX, T) \
static inline T nghttp3_min_##SUFFIX(T a, T b) { return a < b ? a : b; }
nghttp3_min_def(int8, int8_t)
nghttp3_min_def(int16, int16_t)
nghttp3_min_def(int32, int32_t)
nghttp3_min_def(int64, int64_t)
nghttp3_min_def(uint8, uint8_t)
nghttp3_min_def(uint16, uint16_t)
nghttp3_min_def(uint32, uint32_t)
nghttp3_min_def(uint64, uint64_t)
nghttp3_min_def(size, size_t)
nghttp3_min_def(long_long_int, long long int)
nghttp3_min_def(long_int, long int)
nghttp3_min_def(int, int)
nghttp3_min_def(short_int, short int)
nghttp3_min_def(signed_char, signed char)
nghttp3_min_def(char, char)
nghttp3_min_def(unsigned_long_long_int, unsigned long long int)
nghttp3_min_def(unsigned_long_int, unsigned long int)
nghttp3_min_def(unsigned_int, unsigned int)
nghttp3_min_def(unsigned_short_int, unsigned short int)
nghttp3_min_def(unsigned_char, unsigned char)
#define nghttp3_min(A, B) \
_Generic((A), \
long long int: nghttp3_min_long_long_int, \
long int: nghttp3_min_long_int, \
int: _Generic((B), \
long long int: nghttp3_min_long_long_int, \
long int: nghttp3_min_long_int, \
int: nghttp3_min_int, \
short int: nghttp3_min_short_int, \
signed char: nghttp3_min_signed_char, \
char: nghttp3_min_char, \
unsigned long long int: nghttp3_min_unsigned_long_long_int, \
unsigned long int: nghttp3_min_unsigned_long_int, \
unsigned int: nghttp3_min_unsigned_int, \
unsigned short int: nghttp3_min_unsigned_short_int, \
unsigned char: nghttp3_min_unsigned_char), \
short int: nghttp3_min_short_int, \
signed char: nghttp3_min_signed_char, \
char: nghttp3_min_char, \
unsigned long long int: nghttp3_min_unsigned_long_long_int, \
unsigned long int: nghttp3_min_unsigned_long_int, \
unsigned int: nghttp3_min_unsigned_int, \
unsigned short int: nghttp3_min_unsigned_short_int, \
unsigned char: nghttp3_min_unsigned_char)((A), (B))
#endif /* !defined(NGHTTP3_MACRO_H) */
+2 -2
View File
@@ -78,10 +78,10 @@ int nghttp3_map_each(const nghttp3_map *map, int (*func)(void *data, void *ptr),
/* Hasher from
https://github.com/rust-lang/rustc-hash/blob/dc5c33f1283de2da64d8d7a06401d91aded03ad4/src/lib.rs
to maximize the output's sensitivity to all input bits. */
#define NGHTTP3_MAP_HASHER 0xf1357aea2e62a9c5ull
#define NGHTTP3_MAP_HASHER 0xF1357AEA2E62A9C5ULL
/* 64-bit Fibonacci hashing constant, Golden Ratio constant, to get
the high bits with the good distribution. */
#define NGHTTP3_MAP_FIBO 0x9e3779b97f4a7c15ull
#define NGHTTP3_MAP_FIBO 0x9E3779B97F4A7C15ULL
static size_t map_index(const nghttp3_map *map, nghttp3_map_key_type key) {
key += map->seed;
+2 -2
View File
@@ -70,7 +70,7 @@ void nghttp3_objalloc_clear(nghttp3_objalloc *objalloc);
inline static void nghttp3_objalloc_##NAME##_init( \
nghttp3_objalloc *objalloc, size_t nmemb, const nghttp3_mem *mem) { \
nghttp3_objalloc_init( \
objalloc, ((sizeof(TYPE) + 0xfu) & ~(uintptr_t)0xfu) * nmemb, mem); \
objalloc, ((sizeof(TYPE) + 0xFU) & ~(size_t)0xFU) * nmemb, mem); \
} \
\
TYPE *nghttp3_objalloc_##NAME##_get(nghttp3_objalloc *objalloc); \
@@ -124,7 +124,7 @@ void nghttp3_objalloc_clear(nghttp3_objalloc *objalloc);
inline static void nghttp3_objalloc_##NAME##_init( \
nghttp3_objalloc *objalloc, size_t nmemb, const nghttp3_mem *mem) { \
nghttp3_objalloc_init( \
objalloc, ((sizeof(TYPE) + 0xfu) & ~(uintptr_t)0xfu) * nmemb, mem); \
objalloc, ((sizeof(TYPE) + 0xFU) & ~(size_t)0xFU) * nmemb, mem); \
} \
\
inline static TYPE *nghttp3_objalloc_##NAME##_get( \
+1 -1
View File
@@ -76,7 +76,7 @@ int nghttp3_pq_push(nghttp3_pq *pq, nghttp3_pq_entry *item) {
void *nq;
size_t ncapacity;
ncapacity = nghttp3_max_size(4, pq->capacity * 2);
ncapacity = nghttp3_max(4, pq->capacity * 2);
nq = nghttp3_mem_realloc(pq->mem, pq->q,
ncapacity * sizeof(nghttp3_pq_entry *));
+265 -242
View File
@@ -50,122 +50,122 @@
/* Generated by mkstatichdtbl.py */
static nghttp3_qpack_static_entry token_stable[] = {
MAKE_STATIC_ENT(0, NGHTTP3_QPACK_TOKEN__AUTHORITY, 3153725150u),
MAKE_STATIC_ENT(15, NGHTTP3_QPACK_TOKEN__METHOD, 695666056u),
MAKE_STATIC_ENT(16, NGHTTP3_QPACK_TOKEN__METHOD, 695666056u),
MAKE_STATIC_ENT(17, NGHTTP3_QPACK_TOKEN__METHOD, 695666056u),
MAKE_STATIC_ENT(18, NGHTTP3_QPACK_TOKEN__METHOD, 695666056u),
MAKE_STATIC_ENT(19, NGHTTP3_QPACK_TOKEN__METHOD, 695666056u),
MAKE_STATIC_ENT(20, NGHTTP3_QPACK_TOKEN__METHOD, 695666056u),
MAKE_STATIC_ENT(21, NGHTTP3_QPACK_TOKEN__METHOD, 695666056u),
MAKE_STATIC_ENT(1, NGHTTP3_QPACK_TOKEN__PATH, 3292848686u),
MAKE_STATIC_ENT(22, NGHTTP3_QPACK_TOKEN__SCHEME, 2510477674u),
MAKE_STATIC_ENT(23, NGHTTP3_QPACK_TOKEN__SCHEME, 2510477674u),
MAKE_STATIC_ENT(24, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u),
MAKE_STATIC_ENT(25, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u),
MAKE_STATIC_ENT(26, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u),
MAKE_STATIC_ENT(27, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u),
MAKE_STATIC_ENT(28, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u),
MAKE_STATIC_ENT(63, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u),
MAKE_STATIC_ENT(64, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u),
MAKE_STATIC_ENT(65, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u),
MAKE_STATIC_ENT(66, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u),
MAKE_STATIC_ENT(67, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u),
MAKE_STATIC_ENT(68, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u),
MAKE_STATIC_ENT(69, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u),
MAKE_STATIC_ENT(70, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u),
MAKE_STATIC_ENT(71, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u),
MAKE_STATIC_ENT(29, NGHTTP3_QPACK_TOKEN_ACCEPT, 136609321u),
MAKE_STATIC_ENT(30, NGHTTP3_QPACK_TOKEN_ACCEPT, 136609321u),
MAKE_STATIC_ENT(31, NGHTTP3_QPACK_TOKEN_ACCEPT_ENCODING, 3379649177u),
MAKE_STATIC_ENT(72, NGHTTP3_QPACK_TOKEN_ACCEPT_LANGUAGE, 1979086614u),
MAKE_STATIC_ENT(32, NGHTTP3_QPACK_TOKEN_ACCEPT_RANGES, 1713753958u),
MAKE_STATIC_ENT(0, NGHTTP3_QPACK_TOKEN__AUTHORITY, 3153725150U),
MAKE_STATIC_ENT(15, NGHTTP3_QPACK_TOKEN__METHOD, 695666056U),
MAKE_STATIC_ENT(16, NGHTTP3_QPACK_TOKEN__METHOD, 695666056U),
MAKE_STATIC_ENT(17, NGHTTP3_QPACK_TOKEN__METHOD, 695666056U),
MAKE_STATIC_ENT(18, NGHTTP3_QPACK_TOKEN__METHOD, 695666056U),
MAKE_STATIC_ENT(19, NGHTTP3_QPACK_TOKEN__METHOD, 695666056U),
MAKE_STATIC_ENT(20, NGHTTP3_QPACK_TOKEN__METHOD, 695666056U),
MAKE_STATIC_ENT(21, NGHTTP3_QPACK_TOKEN__METHOD, 695666056U),
MAKE_STATIC_ENT(1, NGHTTP3_QPACK_TOKEN__PATH, 3292848686U),
MAKE_STATIC_ENT(22, NGHTTP3_QPACK_TOKEN__SCHEME, 2510477674U),
MAKE_STATIC_ENT(23, NGHTTP3_QPACK_TOKEN__SCHEME, 2510477674U),
MAKE_STATIC_ENT(24, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(25, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(26, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(27, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(28, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(63, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(64, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(65, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(66, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(67, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(68, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(69, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(70, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(71, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(29, NGHTTP3_QPACK_TOKEN_ACCEPT, 136609321U),
MAKE_STATIC_ENT(30, NGHTTP3_QPACK_TOKEN_ACCEPT, 136609321U),
MAKE_STATIC_ENT(31, NGHTTP3_QPACK_TOKEN_ACCEPT_ENCODING, 3379649177U),
MAKE_STATIC_ENT(72, NGHTTP3_QPACK_TOKEN_ACCEPT_LANGUAGE, 1979086614U),
MAKE_STATIC_ENT(32, NGHTTP3_QPACK_TOKEN_ACCEPT_RANGES, 1713753958U),
MAKE_STATIC_ENT(73, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_CREDENTIALS,
901040780u),
901040780U),
MAKE_STATIC_ENT(74, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_CREDENTIALS,
901040780u),
901040780U),
MAKE_STATIC_ENT(33, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_HEADERS,
1524311232u),
1524311232U),
MAKE_STATIC_ENT(34, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_HEADERS,
1524311232u),
1524311232U),
MAKE_STATIC_ENT(75, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_HEADERS,
1524311232u),
1524311232U),
MAKE_STATIC_ENT(76, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_METHODS,
2175229868u),
2175229868U),
MAKE_STATIC_ENT(77, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_METHODS,
2175229868u),
2175229868U),
MAKE_STATIC_ENT(78, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_METHODS,
2175229868u),
2175229868U),
MAKE_STATIC_ENT(35, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_ORIGIN,
2710797292u),
2710797292U),
MAKE_STATIC_ENT(79, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_EXPOSE_HEADERS,
2449824425u),
2449824425U),
MAKE_STATIC_ENT(80, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_REQUEST_HEADERS,
3599549072u),
3599549072U),
MAKE_STATIC_ENT(81, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_REQUEST_METHOD,
2417078055u),
2417078055U),
MAKE_STATIC_ENT(82, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_REQUEST_METHOD,
2417078055u),
MAKE_STATIC_ENT(2, NGHTTP3_QPACK_TOKEN_AGE, 742476188u),
MAKE_STATIC_ENT(83, NGHTTP3_QPACK_TOKEN_ALT_SVC, 2148877059u),
MAKE_STATIC_ENT(84, NGHTTP3_QPACK_TOKEN_AUTHORIZATION, 2436257726u),
MAKE_STATIC_ENT(36, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669u),
MAKE_STATIC_ENT(37, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669u),
MAKE_STATIC_ENT(38, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669u),
MAKE_STATIC_ENT(39, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669u),
MAKE_STATIC_ENT(40, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669u),
MAKE_STATIC_ENT(41, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669u),
MAKE_STATIC_ENT(3, NGHTTP3_QPACK_TOKEN_CONTENT_DISPOSITION, 3889184348u),
MAKE_STATIC_ENT(42, NGHTTP3_QPACK_TOKEN_CONTENT_ENCODING, 65203592u),
MAKE_STATIC_ENT(43, NGHTTP3_QPACK_TOKEN_CONTENT_ENCODING, 65203592u),
MAKE_STATIC_ENT(4, NGHTTP3_QPACK_TOKEN_CONTENT_LENGTH, 1308181789u),
MAKE_STATIC_ENT(85, NGHTTP3_QPACK_TOKEN_CONTENT_SECURITY_POLICY, 1569039836u),
MAKE_STATIC_ENT(44, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u),
MAKE_STATIC_ENT(45, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u),
MAKE_STATIC_ENT(46, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u),
MAKE_STATIC_ENT(47, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u),
MAKE_STATIC_ENT(48, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u),
MAKE_STATIC_ENT(49, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u),
MAKE_STATIC_ENT(50, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u),
MAKE_STATIC_ENT(51, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u),
MAKE_STATIC_ENT(52, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u),
MAKE_STATIC_ENT(53, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u),
MAKE_STATIC_ENT(54, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u),
MAKE_STATIC_ENT(5, NGHTTP3_QPACK_TOKEN_COOKIE, 2007449791u),
MAKE_STATIC_ENT(6, NGHTTP3_QPACK_TOKEN_DATE, 3564297305u),
MAKE_STATIC_ENT(86, NGHTTP3_QPACK_TOKEN_EARLY_DATA, 4080895051u),
MAKE_STATIC_ENT(7, NGHTTP3_QPACK_TOKEN_ETAG, 113792960u),
MAKE_STATIC_ENT(87, NGHTTP3_QPACK_TOKEN_EXPECT_CT, 1183214960u),
MAKE_STATIC_ENT(88, NGHTTP3_QPACK_TOKEN_FORWARDED, 1485178027u),
MAKE_STATIC_ENT(8, NGHTTP3_QPACK_TOKEN_IF_MODIFIED_SINCE, 2213050793u),
MAKE_STATIC_ENT(9, NGHTTP3_QPACK_TOKEN_IF_NONE_MATCH, 2536202615u),
MAKE_STATIC_ENT(89, NGHTTP3_QPACK_TOKEN_IF_RANGE, 2340978238u),
MAKE_STATIC_ENT(10, NGHTTP3_QPACK_TOKEN_LAST_MODIFIED, 3226950251u),
MAKE_STATIC_ENT(11, NGHTTP3_QPACK_TOKEN_LINK, 232457833u),
MAKE_STATIC_ENT(12, NGHTTP3_QPACK_TOKEN_LOCATION, 200649126u),
MAKE_STATIC_ENT(90, NGHTTP3_QPACK_TOKEN_ORIGIN, 3649018447u),
MAKE_STATIC_ENT(91, NGHTTP3_QPACK_TOKEN_PURPOSE, 4212263681u),
MAKE_STATIC_ENT(55, NGHTTP3_QPACK_TOKEN_RANGE, 4208725202u),
MAKE_STATIC_ENT(13, NGHTTP3_QPACK_TOKEN_REFERER, 3969579366u),
MAKE_STATIC_ENT(92, NGHTTP3_QPACK_TOKEN_SERVER, 1085029842u),
MAKE_STATIC_ENT(14, NGHTTP3_QPACK_TOKEN_SET_COOKIE, 1848371000u),
2417078055U),
MAKE_STATIC_ENT(2, NGHTTP3_QPACK_TOKEN_AGE, 742476188U),
MAKE_STATIC_ENT(83, NGHTTP3_QPACK_TOKEN_ALT_SVC, 2148877059U),
MAKE_STATIC_ENT(84, NGHTTP3_QPACK_TOKEN_AUTHORIZATION, 2436257726U),
MAKE_STATIC_ENT(36, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669U),
MAKE_STATIC_ENT(37, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669U),
MAKE_STATIC_ENT(38, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669U),
MAKE_STATIC_ENT(39, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669U),
MAKE_STATIC_ENT(40, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669U),
MAKE_STATIC_ENT(41, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669U),
MAKE_STATIC_ENT(3, NGHTTP3_QPACK_TOKEN_CONTENT_DISPOSITION, 3889184348U),
MAKE_STATIC_ENT(42, NGHTTP3_QPACK_TOKEN_CONTENT_ENCODING, 65203592U),
MAKE_STATIC_ENT(43, NGHTTP3_QPACK_TOKEN_CONTENT_ENCODING, 65203592U),
MAKE_STATIC_ENT(4, NGHTTP3_QPACK_TOKEN_CONTENT_LENGTH, 1308181789U),
MAKE_STATIC_ENT(85, NGHTTP3_QPACK_TOKEN_CONTENT_SECURITY_POLICY, 1569039836U),
MAKE_STATIC_ENT(44, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277U),
MAKE_STATIC_ENT(45, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277U),
MAKE_STATIC_ENT(46, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277U),
MAKE_STATIC_ENT(47, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277U),
MAKE_STATIC_ENT(48, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277U),
MAKE_STATIC_ENT(49, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277U),
MAKE_STATIC_ENT(50, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277U),
MAKE_STATIC_ENT(51, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277U),
MAKE_STATIC_ENT(52, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277U),
MAKE_STATIC_ENT(53, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277U),
MAKE_STATIC_ENT(54, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277U),
MAKE_STATIC_ENT(5, NGHTTP3_QPACK_TOKEN_COOKIE, 2007449791U),
MAKE_STATIC_ENT(6, NGHTTP3_QPACK_TOKEN_DATE, 3564297305U),
MAKE_STATIC_ENT(86, NGHTTP3_QPACK_TOKEN_EARLY_DATA, 4080895051U),
MAKE_STATIC_ENT(7, NGHTTP3_QPACK_TOKEN_ETAG, 113792960U),
MAKE_STATIC_ENT(87, NGHTTP3_QPACK_TOKEN_EXPECT_CT, 1183214960U),
MAKE_STATIC_ENT(88, NGHTTP3_QPACK_TOKEN_FORWARDED, 1485178027U),
MAKE_STATIC_ENT(8, NGHTTP3_QPACK_TOKEN_IF_MODIFIED_SINCE, 2213050793U),
MAKE_STATIC_ENT(9, NGHTTP3_QPACK_TOKEN_IF_NONE_MATCH, 2536202615U),
MAKE_STATIC_ENT(89, NGHTTP3_QPACK_TOKEN_IF_RANGE, 2340978238U),
MAKE_STATIC_ENT(10, NGHTTP3_QPACK_TOKEN_LAST_MODIFIED, 3226950251U),
MAKE_STATIC_ENT(11, NGHTTP3_QPACK_TOKEN_LINK, 232457833U),
MAKE_STATIC_ENT(12, NGHTTP3_QPACK_TOKEN_LOCATION, 200649126U),
MAKE_STATIC_ENT(90, NGHTTP3_QPACK_TOKEN_ORIGIN, 3649018447U),
MAKE_STATIC_ENT(91, NGHTTP3_QPACK_TOKEN_PURPOSE, 4212263681U),
MAKE_STATIC_ENT(55, NGHTTP3_QPACK_TOKEN_RANGE, 4208725202U),
MAKE_STATIC_ENT(13, NGHTTP3_QPACK_TOKEN_REFERER, 3969579366U),
MAKE_STATIC_ENT(92, NGHTTP3_QPACK_TOKEN_SERVER, 1085029842U),
MAKE_STATIC_ENT(14, NGHTTP3_QPACK_TOKEN_SET_COOKIE, 1848371000U),
MAKE_STATIC_ENT(56, NGHTTP3_QPACK_TOKEN_STRICT_TRANSPORT_SECURITY,
4138147361u),
4138147361U),
MAKE_STATIC_ENT(57, NGHTTP3_QPACK_TOKEN_STRICT_TRANSPORT_SECURITY,
4138147361u),
4138147361U),
MAKE_STATIC_ENT(58, NGHTTP3_QPACK_TOKEN_STRICT_TRANSPORT_SECURITY,
4138147361u),
MAKE_STATIC_ENT(93, NGHTTP3_QPACK_TOKEN_TIMING_ALLOW_ORIGIN, 2432297564u),
4138147361U),
MAKE_STATIC_ENT(93, NGHTTP3_QPACK_TOKEN_TIMING_ALLOW_ORIGIN, 2432297564U),
MAKE_STATIC_ENT(94, NGHTTP3_QPACK_TOKEN_UPGRADE_INSECURE_REQUESTS,
2479169413u),
MAKE_STATIC_ENT(95, NGHTTP3_QPACK_TOKEN_USER_AGENT, 606444526u),
MAKE_STATIC_ENT(59, NGHTTP3_QPACK_TOKEN_VARY, 1085005381u),
MAKE_STATIC_ENT(60, NGHTTP3_QPACK_TOKEN_VARY, 1085005381u),
MAKE_STATIC_ENT(61, NGHTTP3_QPACK_TOKEN_X_CONTENT_TYPE_OPTIONS, 3644557769u),
MAKE_STATIC_ENT(96, NGHTTP3_QPACK_TOKEN_X_FORWARDED_FOR, 2914187656u),
MAKE_STATIC_ENT(97, NGHTTP3_QPACK_TOKEN_X_FRAME_OPTIONS, 3993834824u),
MAKE_STATIC_ENT(98, NGHTTP3_QPACK_TOKEN_X_FRAME_OPTIONS, 3993834824u),
MAKE_STATIC_ENT(62, NGHTTP3_QPACK_TOKEN_X_XSS_PROTECTION, 2501058888u),
2479169413U),
MAKE_STATIC_ENT(95, NGHTTP3_QPACK_TOKEN_USER_AGENT, 606444526U),
MAKE_STATIC_ENT(59, NGHTTP3_QPACK_TOKEN_VARY, 1085005381U),
MAKE_STATIC_ENT(60, NGHTTP3_QPACK_TOKEN_VARY, 1085005381U),
MAKE_STATIC_ENT(61, NGHTTP3_QPACK_TOKEN_X_CONTENT_TYPE_OPTIONS, 3644557769U),
MAKE_STATIC_ENT(96, NGHTTP3_QPACK_TOKEN_X_FORWARDED_FOR, 2914187656U),
MAKE_STATIC_ENT(97, NGHTTP3_QPACK_TOKEN_X_FRAME_OPTIONS, 3993834824U),
MAKE_STATIC_ENT(98, NGHTTP3_QPACK_TOKEN_X_FRAME_OPTIONS, 3993834824U),
MAKE_STATIC_ENT(62, NGHTTP3_QPACK_TOKEN_X_XSS_PROTECTION, 2501058888U),
};
/* Make scalar initialization form of nghttp3_qpack_static_entry */
@@ -749,7 +749,7 @@ static int qpack_nv_value_eq(const nghttp3_qpack_nv *a, const nghttp3_nv *b) {
}
static void qpack_map_init(nghttp3_qpack_map *map) {
memset(map, 0, sizeof(nghttp3_qpack_map));
*map = (nghttp3_qpack_map){0};
}
static void qpack_map_insert(nghttp3_qpack_map *map, nghttp3_qpack_entry *ent) {
@@ -940,8 +940,8 @@ void nghttp3_qpack_encoder_free(nghttp3_qpack_encoder *encoder) {
void nghttp3_qpack_encoder_set_max_dtable_capacity(
nghttp3_qpack_encoder *encoder, size_t max_dtable_capacity) {
max_dtable_capacity = nghttp3_min_size(max_dtable_capacity,
encoder->ctx.hard_max_dtable_capacity);
max_dtable_capacity =
nghttp3_min(max_dtable_capacity, encoder->ctx.hard_max_dtable_capacity);
if (encoder->ctx.max_dtable_capacity == max_dtable_capacity) {
return;
@@ -966,7 +966,8 @@ void nghttp3_qpack_encoder_set_indexing_strat(
encoder->indexing_strat = strat;
}
uint64_t nghttp3_qpack_encoder_get_min_cnt(nghttp3_qpack_encoder *encoder) {
uint64_t
nghttp3_qpack_encoder_get_min_cnt(const nghttp3_qpack_encoder *encoder) {
assert(!nghttp3_pq_empty(&encoder->min_cnts));
return nghttp3_struct_of(nghttp3_pq_top(&encoder->min_cnts),
@@ -1111,15 +1112,15 @@ static int reserve_buf(nghttp3_buf *buf, size_t extra_size,
return 0;
}
n = nghttp3_max_size(n, nghttp3_buf_cap(buf) + extra_size - left);
n = nghttp3_max(n, nghttp3_buf_cap(buf) + extra_size - left);
/* Check whether we are requesting too much memory */
if (n > (1u << 31)) {
if (n > (1U << 31)) {
return NGHTTP3_ERR_NOMEM;
}
#ifndef WIN32
n = 1u << (32 - __builtin_clz((uint32_t)n - 1));
n = 1U << (32 - __builtin_clz((uint32_t)n - 1));
#else /* defined(WIN32) */
/* Round up to the next highest power of 2 from Bit Twiddling
Hacks */
@@ -1271,23 +1272,23 @@ int nghttp3_qpack_encoder_process_dtable_update(nghttp3_qpack_encoder *encoder,
int nghttp3_qpack_encoder_write_set_dtable_cap(nghttp3_qpack_encoder *encoder,
nghttp3_buf *ebuf, size_t cap) {
DEBUGF("qpack::encode: Set Dynamic Table Capacity capacity=%zu\n", cap);
return qpack_write_number(ebuf, 0x20, cap, 5, encoder->ctx.mem);
return qpack_write_number(ebuf, 0x20U, cap, 5, encoder->ctx.mem);
}
nghttp3_qpack_stream *
nghttp3_qpack_encoder_find_stream(nghttp3_qpack_encoder *encoder,
nghttp3_qpack_encoder_find_stream(const nghttp3_qpack_encoder *encoder,
int64_t stream_id) {
return nghttp3_map_find(&encoder->streams, (nghttp3_map_key_type)stream_id);
}
int nghttp3_qpack_encoder_stream_is_blocked(nghttp3_qpack_encoder *encoder,
nghttp3_qpack_stream *stream) {
int nghttp3_qpack_encoder_stream_is_blocked(
const nghttp3_qpack_encoder *encoder, const nghttp3_qpack_stream *stream) {
return stream && encoder->krcnt < nghttp3_qpack_stream_get_max_cnt(stream);
}
static uint32_t qpack_hash_name(const nghttp3_nv *nv) {
/* 32 bit FNV-1a: http://isthe.com/chongo/tech/comp/fnv/ */
uint32_t h = 2166136261u;
uint32_t h = 2166136261U;
size_t i;
for (i = 0; i < nv->namelen; ++i) {
@@ -1304,7 +1305,7 @@ static uint32_t qpack_hash_name(const nghttp3_nv *nv) {
* name.
*/
static nghttp3_qpack_indexing_mode
qpack_encoder_decide_indexing_mode(nghttp3_qpack_encoder *encoder,
qpack_encoder_decide_indexing_mode(const nghttp3_qpack_encoder *encoder,
const nghttp3_nv *nv, int32_t token) {
if (nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) {
return NGHTTP3_QPACK_INDEXING_MODE_NEVER;
@@ -1391,7 +1392,7 @@ static int qpack_encoder_can_index(nghttp3_qpack_encoder *encoder, size_t need,
if (!nghttp3_pq_empty(&encoder->min_cnts)) {
gmin_cnt = nghttp3_qpack_encoder_get_min_cnt(encoder);
min_cnt = nghttp3_min_uint64(min_cnt, gmin_cnt);
min_cnt = nghttp3_min(min_cnt, gmin_cnt);
}
if (min_cnt == UINT64_MAX) {
@@ -1445,7 +1446,7 @@ static int qpack_encoder_can_index_duplicate(nghttp3_qpack_encoder *encoder,
static int qpack_context_check_draining(nghttp3_qpack_context *ctx,
uint64_t absidx) {
const size_t safe = ctx->max_dtable_capacity -
nghttp3_min_size(512, ctx->max_dtable_capacity * 1 / 8);
nghttp3_min(512, ctx->max_dtable_capacity * 1 / 8);
nghttp3_qpack_entry *ent = nghttp3_qpack_context_dtable_get(ctx, absidx);
return ctx->dtable_sum - ent->sum > safe;
@@ -1490,16 +1491,16 @@ int nghttp3_qpack_encoder_encode_nv(nghttp3_qpack_encoder *encoder,
} else {
switch (token) {
case NGHTTP3_QPACK_TOKEN_HOST:
hash = 2952701295u;
hash = 2952701295U;
break;
case NGHTTP3_QPACK_TOKEN_TE:
hash = 1011170994u;
hash = 1011170994U;
break;
case NGHTTP3_QPACK_TOKEN__PROTOCOL:
hash = 1128642621u;
hash = 1128642621U;
break;
case NGHTTP3_QPACK_TOKEN_PRIORITY:
hash = 2498028297u;
hash = 2498028297U;
break;
default:
hash = qpack_hash_name(nv);
@@ -1532,8 +1533,8 @@ int nghttp3_qpack_encoder_encode_nv(nghttp3_qpack_encoder *encoder,
new_ent = nghttp3_qpack_context_dtable_top(&encoder->ctx);
dres.index = (nghttp3_ssize)new_ent->absidx;
}
*pmax_cnt = nghttp3_max_uint64(*pmax_cnt, (uint64_t)(dres.index + 1));
*pmin_cnt = nghttp3_min_uint64(*pmin_cnt, (uint64_t)(dres.index + 1));
*pmax_cnt = nghttp3_max(*pmax_cnt, (uint64_t)(dres.index + 1));
*pmin_cnt = nghttp3_min(*pmin_cnt, (uint64_t)(dres.index + 1));
return nghttp3_qpack_encoder_write_dynamic_indexed(
encoder, rbuf, (size_t)dres.index, base);
@@ -1553,8 +1554,8 @@ int nghttp3_qpack_encoder_encode_nv(nghttp3_qpack_encoder *encoder,
}
if (allow_blocking) {
new_ent = nghttp3_qpack_context_dtable_top(&encoder->ctx);
*pmax_cnt = nghttp3_max_uint64(*pmax_cnt, new_ent->absidx + 1);
*pmin_cnt = nghttp3_min_uint64(*pmin_cnt, new_ent->absidx + 1);
*pmax_cnt = nghttp3_max(*pmax_cnt, new_ent->absidx + 1);
*pmin_cnt = nghttp3_min(*pmin_cnt, new_ent->absidx + 1);
return nghttp3_qpack_encoder_write_dynamic_indexed(
encoder, rbuf, new_ent->absidx, base);
@@ -1569,9 +1570,8 @@ int nghttp3_qpack_encoder_encode_nv(nghttp3_qpack_encoder *encoder,
if (just_index &&
qpack_encoder_can_index_nv(
encoder, nv,
allow_blocking
? *pmin_cnt
: nghttp3_min_uint64((uint64_t)dres.index + 1, *pmin_cnt))) {
allow_blocking ? *pmin_cnt
: nghttp3_min((uint64_t)dres.index + 1, *pmin_cnt))) {
rv = nghttp3_qpack_encoder_write_dynamic_insert(encoder, ebuf,
(size_t)dres.index, nv);
if (rv != 0) {
@@ -1579,7 +1579,7 @@ int nghttp3_qpack_encoder_encode_nv(nghttp3_qpack_encoder *encoder,
}
if (!allow_blocking) {
*pmin_cnt = nghttp3_min_uint64(*pmin_cnt, (uint64_t)dres.index + 1);
*pmin_cnt = nghttp3_min(*pmin_cnt, (uint64_t)dres.index + 1);
}
rv = nghttp3_qpack_encoder_dtable_dynamic_add(encoder, (size_t)dres.index,
@@ -1590,16 +1590,16 @@ int nghttp3_qpack_encoder_encode_nv(nghttp3_qpack_encoder *encoder,
if (allow_blocking) {
new_ent = nghttp3_qpack_context_dtable_top(&encoder->ctx);
*pmax_cnt = nghttp3_max_uint64(*pmax_cnt, new_ent->absidx + 1);
*pmin_cnt = nghttp3_min_uint64(*pmin_cnt, new_ent->absidx + 1);
*pmax_cnt = nghttp3_max(*pmax_cnt, new_ent->absidx + 1);
*pmin_cnt = nghttp3_min(*pmin_cnt, new_ent->absidx + 1);
return nghttp3_qpack_encoder_write_dynamic_indexed(
encoder, rbuf, new_ent->absidx, base);
}
}
*pmax_cnt = nghttp3_max_uint64(*pmax_cnt, (uint64_t)(dres.index + 1));
*pmin_cnt = nghttp3_min_uint64(*pmin_cnt, (uint64_t)(dres.index + 1));
*pmax_cnt = nghttp3_max(*pmax_cnt, (uint64_t)(dres.index + 1));
*pmin_cnt = nghttp3_min(*pmin_cnt, (uint64_t)(dres.index + 1));
return nghttp3_qpack_encoder_write_dynamic_indexed_name(
encoder, rbuf, (size_t)dres.index, base, nv);
@@ -1616,8 +1616,8 @@ int nghttp3_qpack_encoder_encode_nv(nghttp3_qpack_encoder *encoder,
}
if (allow_blocking) {
new_ent = nghttp3_qpack_context_dtable_top(&encoder->ctx);
*pmax_cnt = nghttp3_max_uint64(*pmax_cnt, new_ent->absidx + 1);
*pmin_cnt = nghttp3_min_uint64(*pmin_cnt, new_ent->absidx + 1);
*pmax_cnt = nghttp3_max(*pmax_cnt, new_ent->absidx + 1);
*pmin_cnt = nghttp3_min(*pmin_cnt, new_ent->absidx + 1);
return nghttp3_qpack_encoder_write_dynamic_indexed(encoder, rbuf,
new_ent->absidx, base);
@@ -1782,8 +1782,7 @@ int nghttp3_qpack_stream_add_ref(nghttp3_qpack_stream *stream,
if (nghttp3_ringbuf_full(&stream->refs)) {
rv = nghttp3_ringbuf_reserve(
&stream->refs,
nghttp3_max_size(4, nghttp3_ringbuf_len(&stream->refs) * 2));
&stream->refs, nghttp3_max(4, nghttp3_ringbuf_len(&stream->refs) * 2));
if (rv != 0) {
return rv;
}
@@ -1815,28 +1814,26 @@ void nghttp3_qpack_stream_pop_ref(nghttp3_qpack_stream *stream) {
nghttp3_ringbuf_pop_front(&stream->refs);
}
int nghttp3_qpack_encoder_write_static_indexed(nghttp3_qpack_encoder *encoder,
nghttp3_buf *rbuf,
uint64_t absidx) {
int nghttp3_qpack_encoder_write_static_indexed(
const nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx) {
DEBUGF("qpack::encode: Indexed Field Line (static) absidx=%" PRIu64 "\n",
absidx);
return qpack_write_number(rbuf, 0xc0, absidx, 6, encoder->ctx.mem);
return qpack_write_number(rbuf, 0xC0U, absidx, 6, encoder->ctx.mem);
}
int nghttp3_qpack_encoder_write_dynamic_indexed(nghttp3_qpack_encoder *encoder,
nghttp3_buf *rbuf,
uint64_t absidx,
uint64_t base) {
int nghttp3_qpack_encoder_write_dynamic_indexed(
const nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx,
uint64_t base) {
DEBUGF("qpack::encode: Indexed Field Line (dynamic) absidx=%" PRIu64
" base=%" PRIu64 "\n",
absidx, base);
if (absidx < base) {
return qpack_write_number(rbuf, 0x80, base - absidx - 1, 6,
return qpack_write_number(rbuf, 0x80U, base - absidx - 1, 6,
encoder->ctx.mem);
}
return qpack_write_number(rbuf, 0x10, absidx - base, 4, encoder->ctx.mem);
return qpack_write_number(rbuf, 0x10U, absidx - base, 4, encoder->ctx.mem);
}
/*
@@ -1851,10 +1848,10 @@ int nghttp3_qpack_encoder_write_dynamic_indexed(nghttp3_qpack_encoder *encoder,
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
static int qpack_encoder_write_indexed_name(nghttp3_qpack_encoder *encoder,
nghttp3_buf *buf, uint8_t fb,
uint64_t nameidx, size_t prefix,
const nghttp3_nv *nv) {
static int
qpack_encoder_write_indexed_name(const nghttp3_qpack_encoder *encoder,
nghttp3_buf *buf, uint8_t fb, uint64_t nameidx,
size_t prefix, const nghttp3_nv *nv) {
int rv;
size_t len = nghttp3_qpack_put_varint_len(nameidx, prefix);
uint8_t *p;
@@ -1880,7 +1877,7 @@ static int qpack_encoder_write_indexed_name(nghttp3_qpack_encoder *encoder,
p = nghttp3_qpack_put_varint(p, nameidx, prefix);
if (h) {
*p = 0x80;
*p = 0x80U;
p = nghttp3_qpack_put_varint(p, hlen, 7);
p = nghttp3_qpack_huffman_encode(p, nv->value, nv->valuelen);
} else {
@@ -1899,10 +1896,11 @@ static int qpack_encoder_write_indexed_name(nghttp3_qpack_encoder *encoder,
}
int nghttp3_qpack_encoder_write_static_indexed_name(
nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx,
const nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx,
const nghttp3_nv *nv) {
uint8_t fb =
(uint8_t)(0x50 | ((nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) ? 0x20 : 0));
(uint8_t)(0x50U |
((nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) ? 0x20U : 0x00U));
DEBUGF("qpack::encode: Literal Field Line With Name Reference (static) "
"absidx=%" PRIu64 " never=%d\n",
@@ -1911,7 +1909,7 @@ int nghttp3_qpack_encoder_write_static_indexed_name(
}
int nghttp3_qpack_encoder_write_dynamic_indexed_name(
nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx,
const nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx,
uint64_t base, const nghttp3_nv *nv) {
uint8_t fb;
@@ -1920,13 +1918,13 @@ int nghttp3_qpack_encoder_write_dynamic_indexed_name(
absidx, base, (nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) != 0);
if (absidx < base) {
fb =
(uint8_t)(0x40 | ((nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) ? 0x20 : 0));
fb = (uint8_t)(0x40U |
((nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) ? 0x20U : 0x00U));
return qpack_encoder_write_indexed_name(encoder, rbuf, fb,
base - absidx - 1, 4, nv);
}
fb = (nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) ? 0x08 : 0;
fb = (nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) ? 0x08U : 0x0U;
return qpack_encoder_write_indexed_name(encoder, rbuf, fb, absidx - base, 3,
nv);
}
@@ -1943,7 +1941,7 @@ int nghttp3_qpack_encoder_write_dynamic_indexed_name(
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
static int qpack_encoder_write_literal(nghttp3_qpack_encoder *encoder,
static int qpack_encoder_write_literal(const nghttp3_qpack_encoder *encoder,
nghttp3_buf *buf, uint8_t fb,
size_t prefix, const nghttp3_nv *nv) {
int rv;
@@ -1990,7 +1988,7 @@ static int qpack_encoder_write_literal(nghttp3_qpack_encoder *encoder,
*p = 0;
if (vh) {
*p |= 0x80;
*p |= 0x80U;
p = nghttp3_qpack_put_varint(p, vhlen, 7);
p = nghttp3_qpack_huffman_encode(p, nv->value, nv->valuelen);
} else {
@@ -2007,40 +2005,38 @@ static int qpack_encoder_write_literal(nghttp3_qpack_encoder *encoder,
return 0;
}
int nghttp3_qpack_encoder_write_literal(nghttp3_qpack_encoder *encoder,
int nghttp3_qpack_encoder_write_literal(const nghttp3_qpack_encoder *encoder,
nghttp3_buf *rbuf,
const nghttp3_nv *nv) {
uint8_t fb =
(uint8_t)(0x20 | ((nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) ? 0x10 : 0));
(uint8_t)(0x20U |
((nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) ? 0x10U : 0x0U));
DEBUGF("qpack::encode: Literal Field Line With Literal Name\n");
return qpack_encoder_write_literal(encoder, rbuf, fb, 3, nv);
}
int nghttp3_qpack_encoder_write_static_insert(nghttp3_qpack_encoder *encoder,
nghttp3_buf *ebuf,
uint64_t absidx,
const nghttp3_nv *nv) {
int nghttp3_qpack_encoder_write_static_insert(
const nghttp3_qpack_encoder *encoder, nghttp3_buf *ebuf, uint64_t absidx,
const nghttp3_nv *nv) {
DEBUGF("qpack::encode: Insert With Name Reference (static) absidx=%" PRIu64
"\n",
absidx);
return qpack_encoder_write_indexed_name(encoder, ebuf, 0xc0, absidx, 6, nv);
return qpack_encoder_write_indexed_name(encoder, ebuf, 0xC0U, absidx, 6, nv);
}
int nghttp3_qpack_encoder_write_dynamic_insert(nghttp3_qpack_encoder *encoder,
nghttp3_buf *ebuf,
uint64_t absidx,
const nghttp3_nv *nv) {
int nghttp3_qpack_encoder_write_dynamic_insert(
const nghttp3_qpack_encoder *encoder, nghttp3_buf *ebuf, uint64_t absidx,
const nghttp3_nv *nv) {
DEBUGF("qpack::encode: Insert With Name Reference (dynamic) absidx=%" PRIu64
"\n",
absidx);
return qpack_encoder_write_indexed_name(
encoder, ebuf, 0x80, encoder->ctx.next_absidx - absidx - 1, 6, nv);
encoder, ebuf, 0x80U, encoder->ctx.next_absidx - absidx - 1, 6, nv);
}
int nghttp3_qpack_encoder_write_duplicate_insert(nghttp3_qpack_encoder *encoder,
nghttp3_buf *ebuf,
uint64_t absidx) {
int nghttp3_qpack_encoder_write_duplicate_insert(
const nghttp3_qpack_encoder *encoder, nghttp3_buf *ebuf, uint64_t absidx) {
uint64_t idx = encoder->ctx.next_absidx - absidx - 1;
size_t len = nghttp3_qpack_put_varint_len(idx, 5);
uint8_t *p;
@@ -2065,11 +2061,11 @@ int nghttp3_qpack_encoder_write_duplicate_insert(nghttp3_qpack_encoder *encoder,
return 0;
}
int nghttp3_qpack_encoder_write_literal_insert(nghttp3_qpack_encoder *encoder,
nghttp3_buf *ebuf,
const nghttp3_nv *nv) {
int nghttp3_qpack_encoder_write_literal_insert(
const nghttp3_qpack_encoder *encoder, nghttp3_buf *ebuf,
const nghttp3_nv *nv) {
DEBUGF("qpack::encode: Insert With Literal Name\n");
return qpack_encoder_write_literal(encoder, ebuf, 0x40, 5, nv);
return qpack_encoder_write_literal(encoder, ebuf, 0x40U, 5, nv);
}
int nghttp3_qpack_context_dtable_add(nghttp3_qpack_context *ctx,
@@ -2112,8 +2108,7 @@ int nghttp3_qpack_context_dtable_add(nghttp3_qpack_context *ctx,
if (nghttp3_ringbuf_full(&ctx->dtable)) {
rv = nghttp3_ringbuf_reserve(
&ctx->dtable,
nghttp3_max_size(128, nghttp3_ringbuf_len(&ctx->dtable) * 2));
&ctx->dtable, nghttp3_max(128, nghttp3_ringbuf_len(&ctx->dtable) * 2));
if (rv != 0) {
goto fail;
}
@@ -2418,11 +2413,16 @@ void nghttp3_qpack_encoder_cancel_stream(nghttp3_qpack_encoder *encoder,
size_t
nghttp3_qpack_encoder_get_num_blocked_streams(nghttp3_qpack_encoder *encoder) {
return nghttp3_qpack_encoder_get_num_blocked_streams2(encoder);
}
size_t nghttp3_qpack_encoder_get_num_blocked_streams2(
const nghttp3_qpack_encoder *encoder) {
return nghttp3_ksl_len(&encoder->blocked_streams);
}
int nghttp3_qpack_encoder_write_field_section_prefix(
nghttp3_qpack_encoder *encoder, nghttp3_buf *pbuf, uint64_t ricnt,
const nghttp3_qpack_encoder *encoder, nghttp3_buf *pbuf, uint64_t ricnt,
uint64_t base) {
size_t max_ents =
encoder->ctx.hard_max_dtable_capacity / NGHTTP3_QPACK_ENTRY_OVERHEAD;
@@ -2446,7 +2446,7 @@ int nghttp3_qpack_encoder_write_field_section_prefix(
p = nghttp3_qpack_put_varint(p, encricnt, 8);
if (sign) {
*p = 0x80;
*p = 0x80U;
} else {
*p = 0;
}
@@ -2507,7 +2507,7 @@ static nghttp3_ssize qpack_read_varint(int *fin,
}
for (; p != end; ++p, shift += 7) {
add = (*p) & 0x7f;
add = (*p) & 0x7FU;
if (shift > 62) {
return NGHTTP3_ERR_QPACK_FATAL;
@@ -2568,15 +2568,15 @@ nghttp3_ssize nghttp3_qpack_encoder_read_decoder(nghttp3_qpack_encoder *encoder,
for (; p != end;) {
switch (encoder->state) {
case NGHTTP3_QPACK_DS_STATE_OPCODE:
switch ((*p) & 0xc0) {
case 0x80:
case 0xc0:
switch ((*p) & 0xC0U) {
case 0x80U:
case 0xC0U:
DEBUGF("qpack::encode: OPCODE_SECTION_ACK\n");
encoder->opcode = NGHTTP3_QPACK_DS_OPCODE_SECTION_ACK;
encoder->rstate.prefix = 7;
break;
case 0x40:
case 0x40U:
DEBUGF("qpack::encode: OPCODE_STREAM_CANCEL\n");
encoder->opcode = NGHTTP3_QPACK_DS_OPCODE_STREAM_CANCEL;
encoder->rstate.prefix = 6;
@@ -2673,7 +2673,7 @@ uint8_t *nghttp3_qpack_put_varint(uint8_t *buf, uint64_t n, size_t prefix) {
n -= k;
for (; n >= 128; n >>= 7) {
*buf++ = (uint8_t)((1 << 7) | (n & 0x7f));
*buf++ = (uint8_t)(0x80U | (n & 0x7FU));
}
*buf++ = (uint8_t)n;
@@ -2766,7 +2766,7 @@ static nghttp3_ssize qpack_read_string(nghttp3_qpack_read_state *rstate,
nghttp3_buf *dest, const uint8_t *begin,
const uint8_t *end) {
size_t len = (size_t)(end - begin);
size_t n = (size_t)nghttp3_min_uint64((uint64_t)len, rstate->left);
size_t n = (size_t)nghttp3_min((uint64_t)len, rstate->left);
dest->last = nghttp3_cpymem(dest->last, begin, n);
@@ -2783,8 +2783,9 @@ static nghttp3_ssize qpack_read_string(nghttp3_qpack_read_state *rstate,
* NGHTTP3_ERR_QPACK_FATAL
* rstate->absidx is invalid.
*/
static int qpack_decoder_validate_index(nghttp3_qpack_decoder *decoder,
nghttp3_qpack_read_state *rstate) {
static int
qpack_decoder_validate_index(const nghttp3_qpack_decoder *decoder,
const nghttp3_qpack_read_state *rstate) {
if (rstate->dynamic) {
return rstate->absidx < decoder->ctx.next_absidx &&
decoder->ctx.next_absidx - rstate->absidx - 1 <
@@ -2840,20 +2841,20 @@ nghttp3_ssize nghttp3_qpack_decoder_read_encoder(nghttp3_qpack_decoder *decoder,
busy = 0;
switch (decoder->state) {
case NGHTTP3_QPACK_ES_STATE_OPCODE:
switch ((*p) & 0xe0) {
case 0x80:
case 0xa0:
case 0xc0:
case 0xe0:
switch ((*p) & 0xE0U) {
case 0x80U:
case 0xA0U:
case 0xC0U:
case 0xE0U:
DEBUGF("qpack::decode: OPCODE_INSERT_INDEXED\n");
decoder->opcode = NGHTTP3_QPACK_ES_OPCODE_INSERT_INDEXED;
decoder->rstate.dynamic = !((*p) & 0x40);
decoder->rstate.dynamic = !((*p) & 0x40U);
decoder->rstate.prefix = 6;
decoder->state = NGHTTP3_QPACK_ES_STATE_READ_INDEX;
break;
case 0x40:
case 0x60:
case 0x40U:
case 0x60U:
DEBUGF("qpack::decode: OPCODE_INSERT\n");
decoder->opcode = NGHTTP3_QPACK_ES_OPCODE_INSERT;
decoder->rstate.dynamic = 0;
@@ -2861,7 +2862,7 @@ nghttp3_ssize nghttp3_qpack_decoder_read_encoder(nghttp3_qpack_decoder *decoder,
decoder->state = NGHTTP3_QPACK_ES_STATE_CHECK_NAME_HUFFMAN;
break;
case 0x20:
case 0x20U:
DEBUGF("qpack::decode: OPCODE_SET_DTABLE_TABLE_CAP\n");
decoder->opcode = NGHTTP3_QPACK_ES_OPCODE_SET_DTABLE_CAP;
decoder->rstate.prefix = 5;
@@ -2960,7 +2961,10 @@ nghttp3_ssize nghttp3_qpack_decoder_read_encoder(nghttp3_qpack_decoder *decoder,
decoder->state = NGHTTP3_QPACK_ES_STATE_READ_NAME_HUFFMAN;
nghttp3_qpack_huffman_decode_context_init(&decoder->rstate.huffman_ctx);
rv = nghttp3_rcbuf_new(&decoder->rstate.name,
(size_t)decoder->rstate.left * 2 + 1, mem);
nghttp3_qpack_huffman_estimate_decode_length(
(size_t)decoder->rstate.left) +
1,
mem);
} else {
decoder->state = NGHTTP3_QPACK_ES_STATE_READ_NAME;
rv = nghttp3_rcbuf_new(&decoder->rstate.name,
@@ -3042,7 +3046,10 @@ nghttp3_ssize nghttp3_qpack_decoder_read_encoder(nghttp3_qpack_decoder *decoder,
decoder->state = NGHTTP3_QPACK_ES_STATE_READ_VALUE_HUFFMAN;
nghttp3_qpack_huffman_decode_context_init(&decoder->rstate.huffman_ctx);
rv = nghttp3_rcbuf_new(&decoder->rstate.value,
(size_t)decoder->rstate.left * 2 + 1, mem);
nghttp3_qpack_huffman_estimate_decode_length(
(size_t)decoder->rstate.left) +
1,
mem);
} else {
decoder->state = NGHTTP3_QPACK_ES_STATE_READ_VALUE;
rv = nghttp3_rcbuf_new(&decoder->rstate.value,
@@ -3288,7 +3295,7 @@ int nghttp3_qpack_decoder_dtable_literal_add(nghttp3_qpack_decoder *decoder) {
void nghttp3_qpack_decoder_set_max_concurrent_streams(
nghttp3_qpack_decoder *decoder, size_t max_concurrent_streams) {
decoder->max_concurrent_streams =
nghttp3_max_size(decoder->max_concurrent_streams, max_concurrent_streams);
nghttp3_max(decoder->max_concurrent_streams, max_concurrent_streams);
}
void nghttp3_qpack_stream_context_init(nghttp3_qpack_stream_context *sctx,
@@ -3316,6 +3323,11 @@ void nghttp3_qpack_stream_context_reset(nghttp3_qpack_stream_context *sctx) {
uint64_t
nghttp3_qpack_stream_context_get_ricnt(nghttp3_qpack_stream_context *sctx) {
return nghttp3_qpack_stream_context_get_ricnt2(sctx);
}
uint64_t nghttp3_qpack_stream_context_get_ricnt2(
const nghttp3_qpack_stream_context *sctx) {
return sctx->ricnt;
}
@@ -3363,7 +3375,7 @@ nghttp3_qpack_decoder_read_request(nghttp3_qpack_decoder *decoder,
sctx->state = NGHTTP3_QPACK_RS_STATE_DBASE_SIGN;
break;
case NGHTTP3_QPACK_RS_STATE_DBASE_SIGN:
if ((*p) & 0x80) {
if ((*p) & 0x80U) {
sctx->dbase_sign = 1;
}
sctx->state = NGHTTP3_QPACK_RS_STATE_DBASE;
@@ -3413,45 +3425,45 @@ nghttp3_qpack_decoder_read_request(nghttp3_qpack_decoder *decoder,
case NGHTTP3_QPACK_RS_STATE_OPCODE:
assert(sctx->rstate.left == 0);
assert(sctx->rstate.shift == 0);
switch ((*p) & 0xf0) {
case 0x80:
case 0x90:
case 0xa0:
case 0xb0:
case 0xc0:
case 0xd0:
case 0xe0:
case 0xf0:
switch ((*p) & 0xF0U) {
case 0x80U:
case 0x90U:
case 0xA0U:
case 0xB0U:
case 0xC0U:
case 0xD0U:
case 0xE0U:
case 0xF0U:
DEBUGF("qpack::decode: OPCODE_INDEXED\n");
sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED;
sctx->rstate.dynamic = !((*p) & 0x40);
sctx->rstate.dynamic = !((*p) & 0x40U);
sctx->rstate.prefix = 6;
sctx->state = NGHTTP3_QPACK_RS_STATE_READ_INDEX;
break;
case 0x40:
case 0x50:
case 0x60:
case 0x70:
case 0x40U:
case 0x50U:
case 0x60U:
case 0x70U:
DEBUGF("qpack::decode: OPCODE_INDEXED_NAME\n");
sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME;
sctx->rstate.never = (*p) & 0x20;
sctx->rstate.dynamic = !((*p) & 0x10);
sctx->rstate.never = (*p) & 0x20U;
sctx->rstate.dynamic = !((*p) & 0x10U);
sctx->rstate.prefix = 4;
sctx->state = NGHTTP3_QPACK_RS_STATE_READ_INDEX;
break;
case 0x20:
case 0x30:
case 0x20U:
case 0x30U:
DEBUGF("qpack::decode: OPCODE_LITERAL\n");
sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_LITERAL;
sctx->rstate.never = (*p) & 0x10;
sctx->rstate.never = (*p) & 0x10U;
sctx->rstate.dynamic = 0;
sctx->rstate.prefix = 3;
sctx->state = NGHTTP3_QPACK_RS_STATE_CHECK_NAME_HUFFMAN;
break;
case 0x10:
case 0x10U:
DEBUGF("qpack::decode: OPCODE_INDEXED_PB\n");
sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED_PB;
sctx->rstate.dynamic = 1;
@@ -3462,7 +3474,7 @@ nghttp3_qpack_decoder_read_request(nghttp3_qpack_decoder *decoder,
default:
DEBUGF("qpack::decode: OPCODE_INDEXED_NAME_PB\n");
sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME_PB;
sctx->rstate.never = (*p) & 0x08;
sctx->rstate.never = (*p) & 0x08U;
sctx->rstate.dynamic = 1;
sctx->rstate.prefix = 3;
sctx->state = NGHTTP3_QPACK_RS_STATE_READ_INDEX;
@@ -3556,7 +3568,10 @@ nghttp3_qpack_decoder_read_request(nghttp3_qpack_decoder *decoder,
sctx->state = NGHTTP3_QPACK_RS_STATE_READ_NAME_HUFFMAN;
nghttp3_qpack_huffman_decode_context_init(&sctx->rstate.huffman_ctx);
rv = nghttp3_rcbuf_new(&sctx->rstate.name,
(size_t)sctx->rstate.left * 2 + 1, mem);
nghttp3_qpack_huffman_estimate_decode_length(
(size_t)sctx->rstate.left) +
1,
mem);
} else {
sctx->state = NGHTTP3_QPACK_RS_STATE_READ_NAME;
rv = nghttp3_rcbuf_new(&sctx->rstate.name,
@@ -3636,7 +3651,10 @@ nghttp3_qpack_decoder_read_request(nghttp3_qpack_decoder *decoder,
sctx->state = NGHTTP3_QPACK_RS_STATE_READ_VALUE_HUFFMAN;
nghttp3_qpack_huffman_decode_context_init(&sctx->rstate.huffman_ctx);
rv = nghttp3_rcbuf_new(&sctx->rstate.value,
(size_t)sctx->rstate.left * 2 + 1, mem);
nghttp3_qpack_huffman_estimate_decode_length(
(size_t)sctx->rstate.left) +
1,
mem);
} else {
sctx->state = NGHTTP3_QPACK_RS_STATE_READ_VALUE;
rv = nghttp3_rcbuf_new(&sctx->rstate.value,
@@ -3766,8 +3784,8 @@ fail:
return rv;
}
static int qpack_decoder_dbuf_overflow(nghttp3_qpack_decoder *decoder) {
size_t limit = nghttp3_max_size(decoder->max_concurrent_streams, 100);
static int qpack_decoder_dbuf_overflow(const nghttp3_qpack_decoder *decoder) {
size_t limit = nghttp3_max(decoder->max_concurrent_streams, 100);
/* 10 = nghttp3_qpack_put_varint_len((1ULL << 62) - 1, 2)) */
return nghttp3_buf_len(&decoder->dbuf) > limit * 2 * 10;
}
@@ -3790,7 +3808,7 @@ int nghttp3_qpack_decoder_write_section_ack(
}
p = dbuf->last;
*p = 0x80;
*p = 0x80U;
dbuf->last = nghttp3_qpack_put_varint(p, (uint64_t)sctx->stream_id, 7);
if (decoder->written_icnt < sctx->ricnt) {
@@ -3802,6 +3820,11 @@ int nghttp3_qpack_decoder_write_section_ack(
size_t
nghttp3_qpack_decoder_get_decoder_streamlen(nghttp3_qpack_decoder *decoder) {
return nghttp3_qpack_decoder_get_decoder_streamlen2(decoder);
}
size_t nghttp3_qpack_decoder_get_decoder_streamlen2(
const nghttp3_qpack_decoder *decoder) {
uint64_t n;
size_t len = 0;
@@ -3863,14 +3886,14 @@ int nghttp3_qpack_decoder_cancel_stream(nghttp3_qpack_decoder *decoder,
}
p = decoder->dbuf.last;
*p = 0x40;
*p = 0x40U;
decoder->dbuf.last = nghttp3_qpack_put_varint(p, (uint64_t)stream_id, 6);
return 0;
}
int nghttp3_qpack_decoder_reconstruct_ricnt(nghttp3_qpack_decoder *decoder,
uint64_t *dest, uint64_t encricnt) {
int nghttp3_qpack_decoder_reconstruct_ricnt(
const nghttp3_qpack_decoder *decoder, uint64_t *dest, uint64_t encricnt) {
uint64_t max_ents, full, max, max_wrapped, ricnt;
if (encricnt == 0) {
@@ -3906,7 +3929,7 @@ int nghttp3_qpack_decoder_reconstruct_ricnt(nghttp3_qpack_decoder *decoder,
return 0;
}
int nghttp3_qpack_decoder_rel2abs(nghttp3_qpack_decoder *decoder,
int nghttp3_qpack_decoder_rel2abs(const nghttp3_qpack_decoder *decoder,
nghttp3_qpack_read_state *rstate) {
DEBUGF("qpack::decode: dynamic=%d relidx=%" PRIu64 " icnt=%" PRIu64 "\n",
rstate->dynamic, rstate->left, decoder->ctx.next_absidx);
@@ -3925,7 +3948,7 @@ int nghttp3_qpack_decoder_rel2abs(nghttp3_qpack_decoder *decoder,
return 0;
}
int nghttp3_qpack_decoder_brel2abs(nghttp3_qpack_decoder *decoder,
int nghttp3_qpack_decoder_brel2abs(const nghttp3_qpack_decoder *decoder,
nghttp3_qpack_stream_context *sctx) {
nghttp3_qpack_read_state *rstate = &sctx->rstate;
@@ -3952,7 +3975,7 @@ int nghttp3_qpack_decoder_brel2abs(nghttp3_qpack_decoder *decoder,
return 0;
}
int nghttp3_qpack_decoder_pbrel2abs(nghttp3_qpack_decoder *decoder,
int nghttp3_qpack_decoder_pbrel2abs(const nghttp3_qpack_decoder *decoder,
nghttp3_qpack_stream_context *sctx) {
nghttp3_qpack_read_state *rstate = &sctx->rstate;
@@ -3974,8 +3997,8 @@ int nghttp3_qpack_decoder_pbrel2abs(nghttp3_qpack_decoder *decoder,
}
static void
qpack_decoder_emit_static_indexed(nghttp3_qpack_decoder *decoder,
nghttp3_qpack_stream_context *sctx,
qpack_decoder_emit_static_indexed(const nghttp3_qpack_decoder *decoder,
const nghttp3_qpack_stream_context *sctx,
nghttp3_qpack_nv *nv) {
const nghttp3_qpack_static_header *shd = &stable[sctx->rstate.absidx];
(void)decoder;
@@ -3988,7 +4011,7 @@ qpack_decoder_emit_static_indexed(nghttp3_qpack_decoder *decoder,
static void
qpack_decoder_emit_dynamic_indexed(nghttp3_qpack_decoder *decoder,
nghttp3_qpack_stream_context *sctx,
const nghttp3_qpack_stream_context *sctx,
nghttp3_qpack_nv *nv) {
nghttp3_qpack_entry *ent =
nghttp3_qpack_context_dtable_get(&decoder->ctx, sctx->rstate.absidx);
@@ -3999,9 +4022,9 @@ qpack_decoder_emit_dynamic_indexed(nghttp3_qpack_decoder *decoder,
nghttp3_rcbuf_incref(nv->value);
}
void nghttp3_qpack_decoder_emit_indexed(nghttp3_qpack_decoder *decoder,
nghttp3_qpack_stream_context *sctx,
nghttp3_qpack_nv *nv) {
void nghttp3_qpack_decoder_emit_indexed(
nghttp3_qpack_decoder *decoder, const nghttp3_qpack_stream_context *sctx,
nghttp3_qpack_nv *nv) {
DEBUGF("qpack::decode: Indexed (%s) absidx=%" PRIu64 "\n",
sctx->rstate.dynamic ? "dynamic" : "static", sctx->rstate.absidx);
@@ -4013,7 +4036,7 @@ void nghttp3_qpack_decoder_emit_indexed(nghttp3_qpack_decoder *decoder,
}
static void
qpack_decoder_emit_static_indexed_name(nghttp3_qpack_decoder *decoder,
qpack_decoder_emit_static_indexed_name(const nghttp3_qpack_decoder *decoder,
nghttp3_qpack_stream_context *sctx,
nghttp3_qpack_nv *nv) {
const nghttp3_qpack_static_header *shd = &stable[sctx->rstate.absidx];
@@ -4073,7 +4096,7 @@ int nghttp3_qpack_decoder_emit_indexed_name(nghttp3_qpack_decoder *decoder,
return 0;
}
void nghttp3_qpack_decoder_emit_literal(nghttp3_qpack_decoder *decoder,
void nghttp3_qpack_decoder_emit_literal(const nghttp3_qpack_decoder *decoder,
nghttp3_qpack_stream_context *sctx,
nghttp3_qpack_nv *nv) {
(void)decoder;
+37 -40
View File
@@ -40,7 +40,7 @@
#include "nghttp3_ksl.h"
#include "nghttp3_qpack_huffman.h"
#define NGHTTP3_QPACK_INT_MAX ((1ull << 62) - 1)
#define NGHTTP3_QPACK_INT_MAX ((1ULL << 62) - 1)
/* NGHTTP3_QPACK_MAX_NAMELEN is the maximum (compressed) length of
header name this library can decode. */
@@ -223,10 +223,10 @@ typedef enum nghttp3_qpack_decoder_stream_opcode {
/* QPACK encoder flags */
/* NGHTTP3_QPACK_ENCODER_FLAG_NONE indicates that no flag is set. */
#define NGHTTP3_QPACK_ENCODER_FLAG_NONE 0x00u
#define NGHTTP3_QPACK_ENCODER_FLAG_NONE 0x00U
/* NGHTTP3_QPACK_ENCODER_FLAG_PENDING_SET_DTABLE_CAP indicates that
Set Dynamic Table Capacity is required. */
#define NGHTTP3_QPACK_ENCODER_FLAG_PENDING_SET_DTABLE_CAP 0x01u
#define NGHTTP3_QPACK_ENCODER_FLAG_PENDING_SET_DTABLE_CAP 0x01U
struct nghttp3_qpack_encoder {
nghttp3_qpack_context ctx;
@@ -350,7 +350,7 @@ nghttp3_qpack_lookup_result nghttp3_qpack_encoder_lookup_dtable(
* Out of memory.
*/
int nghttp3_qpack_encoder_write_field_section_prefix(
nghttp3_qpack_encoder *encoder, nghttp3_buf *pbuf, uint64_t ricnt,
const nghttp3_qpack_encoder *encoder, nghttp3_buf *pbuf, uint64_t ricnt,
uint64_t base);
/*
@@ -363,9 +363,8 @@ int nghttp3_qpack_encoder_write_field_section_prefix(
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
int nghttp3_qpack_encoder_write_static_indexed(nghttp3_qpack_encoder *encoder,
nghttp3_buf *rbuf,
uint64_t absidx);
int nghttp3_qpack_encoder_write_static_indexed(
const nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx);
/*
* nghttp3_qpack_encoder_write_dynamic_indexed writes Indexed Header
@@ -378,9 +377,9 @@ int nghttp3_qpack_encoder_write_static_indexed(nghttp3_qpack_encoder *encoder,
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
int nghttp3_qpack_encoder_write_dynamic_indexed(nghttp3_qpack_encoder *encoder,
nghttp3_buf *rbuf,
uint64_t absidx, uint64_t base);
int nghttp3_qpack_encoder_write_dynamic_indexed(
const nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx,
uint64_t base);
/*
* nghttp3_qpack_encoder_write_static_indexed writes Literal Header
@@ -395,7 +394,7 @@ int nghttp3_qpack_encoder_write_dynamic_indexed(nghttp3_qpack_encoder *encoder,
* Out of memory.
*/
int nghttp3_qpack_encoder_write_static_indexed_name(
nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx,
const nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx,
const nghttp3_nv *nv);
/*
@@ -411,7 +410,7 @@ int nghttp3_qpack_encoder_write_static_indexed_name(
* Out of memory.
*/
int nghttp3_qpack_encoder_write_dynamic_indexed_name(
nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx,
const nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx,
uint64_t base, const nghttp3_nv *nv);
/*
@@ -424,7 +423,7 @@ int nghttp3_qpack_encoder_write_dynamic_indexed_name(
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
int nghttp3_qpack_encoder_write_literal(nghttp3_qpack_encoder *encoder,
int nghttp3_qpack_encoder_write_literal(const nghttp3_qpack_encoder *encoder,
nghttp3_buf *rbuf,
const nghttp3_nv *nv);
@@ -439,10 +438,9 @@ int nghttp3_qpack_encoder_write_literal(nghttp3_qpack_encoder *encoder,
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
int nghttp3_qpack_encoder_write_static_insert(nghttp3_qpack_encoder *encoder,
nghttp3_buf *ebuf,
uint64_t absidx,
const nghttp3_nv *nv);
int nghttp3_qpack_encoder_write_static_insert(
const nghttp3_qpack_encoder *encoder, nghttp3_buf *ebuf, uint64_t absidx,
const nghttp3_nv *nv);
/*
* nghttp3_qpack_encoder_write_dynamic_insert writes Insert With Name
@@ -455,10 +453,9 @@ int nghttp3_qpack_encoder_write_static_insert(nghttp3_qpack_encoder *encoder,
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
int nghttp3_qpack_encoder_write_dynamic_insert(nghttp3_qpack_encoder *encoder,
nghttp3_buf *ebuf,
uint64_t absidx,
const nghttp3_nv *nv);
int nghttp3_qpack_encoder_write_dynamic_insert(
const nghttp3_qpack_encoder *encoder, nghttp3_buf *ebuf, uint64_t absidx,
const nghttp3_nv *nv);
/*
* nghttp3_qpack_encoder_write_duplicate_insert writes Duplicate to
@@ -471,9 +468,8 @@ int nghttp3_qpack_encoder_write_dynamic_insert(nghttp3_qpack_encoder *encoder,
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
int nghttp3_qpack_encoder_write_duplicate_insert(nghttp3_qpack_encoder *encoder,
nghttp3_buf *ebuf,
uint64_t absidx);
int nghttp3_qpack_encoder_write_duplicate_insert(
const nghttp3_qpack_encoder *encoder, nghttp3_buf *ebuf, uint64_t absidx);
/*
* nghttp3_qpack_encoder_write_literal_insert writes Insert With
@@ -485,12 +481,12 @@ int nghttp3_qpack_encoder_write_duplicate_insert(nghttp3_qpack_encoder *encoder,
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
int nghttp3_qpack_encoder_write_literal_insert(nghttp3_qpack_encoder *encoder,
nghttp3_buf *ebuf,
const nghttp3_nv *nv);
int nghttp3_qpack_encoder_write_literal_insert(
const nghttp3_qpack_encoder *encoder, nghttp3_buf *ebuf,
const nghttp3_nv *nv);
int nghttp3_qpack_encoder_stream_is_blocked(nghttp3_qpack_encoder *encoder,
nghttp3_qpack_stream *stream);
int nghttp3_qpack_encoder_stream_is_blocked(
const nghttp3_qpack_encoder *encoder, const nghttp3_qpack_stream *stream);
/*
* nghttp3_qpack_encoder_block_stream blocks |stream|.
@@ -523,10 +519,11 @@ void nghttp3_qpack_encoder_unblock(nghttp3_qpack_encoder *encoder,
* stream.
*/
nghttp3_qpack_stream *
nghttp3_qpack_encoder_find_stream(nghttp3_qpack_encoder *encoder,
nghttp3_qpack_encoder_find_stream(const nghttp3_qpack_encoder *encoder,
int64_t stream_id);
uint64_t nghttp3_qpack_encoder_get_min_cnt(nghttp3_qpack_encoder *encoder);
uint64_t
nghttp3_qpack_encoder_get_min_cnt(const nghttp3_qpack_encoder *encoder);
/*
* nghttp3_qpack_encoder_shrink_dtable shrinks dynamic table so that
@@ -927,8 +924,8 @@ void nghttp3_qpack_stream_context_free(nghttp3_qpack_stream_context *sctx);
* NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED
* Unable to reconstruct Required Insert Count.
*/
int nghttp3_qpack_decoder_reconstruct_ricnt(nghttp3_qpack_decoder *decoder,
uint64_t *dest, uint64_t encricnt);
int nghttp3_qpack_decoder_reconstruct_ricnt(
const nghttp3_qpack_decoder *decoder, uint64_t *dest, uint64_t encricnt);
/*
* nghttp3_qpack_decoder_rel2abs converts relative index rstate->left
@@ -941,7 +938,7 @@ int nghttp3_qpack_decoder_reconstruct_ricnt(nghttp3_qpack_decoder *decoder,
* NGHTTP3_ERR_QPACK_ENCODER_STREAM
* Relative index is invalid.
*/
int nghttp3_qpack_decoder_rel2abs(nghttp3_qpack_decoder *decoder,
int nghttp3_qpack_decoder_rel2abs(const nghttp3_qpack_decoder *decoder,
nghttp3_qpack_read_state *rstate);
/*
@@ -955,7 +952,7 @@ int nghttp3_qpack_decoder_rel2abs(nghttp3_qpack_decoder *decoder,
* NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED
* Base relative index is invalid.
*/
int nghttp3_qpack_decoder_brel2abs(nghttp3_qpack_decoder *decoder,
int nghttp3_qpack_decoder_brel2abs(const nghttp3_qpack_decoder *decoder,
nghttp3_qpack_stream_context *sctx);
/*
@@ -969,18 +966,18 @@ int nghttp3_qpack_decoder_brel2abs(nghttp3_qpack_decoder *decoder,
* NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED
* Post-Base relative index is invalid.
*/
int nghttp3_qpack_decoder_pbrel2abs(nghttp3_qpack_decoder *decoder,
int nghttp3_qpack_decoder_pbrel2abs(const nghttp3_qpack_decoder *decoder,
nghttp3_qpack_stream_context *sctx);
void nghttp3_qpack_decoder_emit_indexed(nghttp3_qpack_decoder *decoder,
nghttp3_qpack_stream_context *sctx,
nghttp3_qpack_nv *nv);
void nghttp3_qpack_decoder_emit_indexed(
nghttp3_qpack_decoder *decoder, const nghttp3_qpack_stream_context *sctx,
nghttp3_qpack_nv *nv);
int nghttp3_qpack_decoder_emit_indexed_name(nghttp3_qpack_decoder *decoder,
nghttp3_qpack_stream_context *sctx,
nghttp3_qpack_nv *nv);
void nghttp3_qpack_decoder_emit_literal(nghttp3_qpack_decoder *decoder,
void nghttp3_qpack_decoder_emit_literal(const nghttp3_qpack_decoder *decoder,
nghttp3_qpack_stream_context *sctx,
nghttp3_qpack_nv *nv);
+3 -3
View File
@@ -107,7 +107,7 @@ nghttp3_qpack_huffman_decode(nghttp3_qpack_huffman_decode_context *ctx,
*p++ = t.sym;
}
t = qpack_huffman_decode_table[t.fstate][c & 0xf];
t = qpack_huffman_decode_table[t.fstate][c & 0xFU];
if (t.flags & NGHTTP3_QPACK_HUFFMAN_SYM) {
*p++ = t.sym;
}
@@ -124,6 +124,6 @@ nghttp3_qpack_huffman_decode(nghttp3_qpack_huffman_decode_context *ctx,
}
int nghttp3_qpack_huffman_decode_failure_state(
nghttp3_qpack_huffman_decode_context *ctx) {
return ctx->fstate == 0x100;
const nghttp3_qpack_huffman_decode_context *ctx) {
return ctx->fstate == 0x100U;
}
+9 -1
View File
@@ -105,6 +105,14 @@ nghttp3_qpack_huffman_decode(nghttp3_qpack_huffman_decode_context *ctx,
* indicates that huffman decoding context is in failure state.
*/
int nghttp3_qpack_huffman_decode_failure_state(
nghttp3_qpack_huffman_decode_context *ctx);
const nghttp3_qpack_huffman_decode_context *ctx);
/*
* nghttp3_qpack_huffman_estimate_decode_length returns the estimated
* decoded length of the huffman encoded string of length |len|.
*/
static inline size_t nghttp3_qpack_huffman_estimate_decode_length(size_t len) {
return len * 8 / 5;
}
#endif /* !defined(NGHTTP3_QPACK_HUFFMAN_H) */
File diff suppressed because it is too large. Load diff
+2 -2
View File
@@ -36,8 +36,8 @@ void nghttp3_range_init(nghttp3_range *r, uint64_t begin, uint64_t end) {
nghttp3_range nghttp3_range_intersect(const nghttp3_range *a,
const nghttp3_range *b) {
nghttp3_range r;
uint64_t begin = nghttp3_max_uint64(a->begin, b->begin);
uint64_t end = nghttp3_min_uint64(a->end, b->end);
uint64_t begin = nghttp3_max(a->begin, b->begin);
uint64_t end = nghttp3_min(a->end, b->end);
if (begin < end) {
nghttp3_range_init(&r, begin, end);
+4 -2
View File
@@ -70,7 +70,7 @@ void nghttp3_ringbuf_free(nghttp3_ringbuf *rb) {
void *nghttp3_ringbuf_push_front(nghttp3_ringbuf *rb) {
rb->first = (rb->first - 1) & (rb->nmemb - 1);
rb->len = nghttp3_min_size(rb->nmemb, rb->len + 1);
rb->len = nghttp3_min(rb->nmemb, rb->len + 1);
return (void *)&rb->buf[rb->first * rb->size];
}
@@ -108,7 +108,9 @@ void *nghttp3_ringbuf_get(nghttp3_ringbuf *rb, size_t offset) {
return &rb->buf[offset * rb->size];
}
int nghttp3_ringbuf_full(nghttp3_ringbuf *rb) { return rb->len == rb->nmemb; }
int nghttp3_ringbuf_full(const nghttp3_ringbuf *rb) {
return rb->len == rb->nmemb;
}
int nghttp3_ringbuf_reserve(nghttp3_ringbuf *rb, size_t nmemb) {
uint8_t *buf;
+1 -1
View File
@@ -108,7 +108,7 @@ static inline size_t nghttp3_ringbuf_len(const nghttp3_ringbuf *rb) {
}
/* nghttp3_ringbuf_full returns nonzero if |rb| is full. */
int nghttp3_ringbuf_full(nghttp3_ringbuf *rb);
int nghttp3_ringbuf_full(const nghttp3_ringbuf *rb);
int nghttp3_ringbuf_reserve(nghttp3_ringbuf *rb, size_t nmemb);
+28 -28
View File
@@ -70,36 +70,36 @@ static const uint8_t DOWNCASE_TBL[] = {
124 /* | */, 125 /* } */, 126 /* ~ */, 127 /* DEL */,
128 /* 0x80 */, 129 /* 0x81 */, 130 /* 0x82 */, 131 /* 0x83 */,
132 /* 0x84 */, 133 /* 0x85 */, 134 /* 0x86 */, 135 /* 0x87 */,
136 /* 0x88 */, 137 /* 0x89 */, 138 /* 0x8a */, 139 /* 0x8b */,
140 /* 0x8c */, 141 /* 0x8d */, 142 /* 0x8e */, 143 /* 0x8f */,
136 /* 0x88 */, 137 /* 0x89 */, 138 /* 0x8A */, 139 /* 0x8B */,
140 /* 0x8C */, 141 /* 0x8D */, 142 /* 0x8E */, 143 /* 0x8F */,
144 /* 0x90 */, 145 /* 0x91 */, 146 /* 0x92 */, 147 /* 0x93 */,
148 /* 0x94 */, 149 /* 0x95 */, 150 /* 0x96 */, 151 /* 0x97 */,
152 /* 0x98 */, 153 /* 0x99 */, 154 /* 0x9a */, 155 /* 0x9b */,
156 /* 0x9c */, 157 /* 0x9d */, 158 /* 0x9e */, 159 /* 0x9f */,
160 /* 0xa0 */, 161 /* 0xa1 */, 162 /* 0xa2 */, 163 /* 0xa3 */,
164 /* 0xa4 */, 165 /* 0xa5 */, 166 /* 0xa6 */, 167 /* 0xa7 */,
168 /* 0xa8 */, 169 /* 0xa9 */, 170 /* 0xaa */, 171 /* 0xab */,
172 /* 0xac */, 173 /* 0xad */, 174 /* 0xae */, 175 /* 0xaf */,
176 /* 0xb0 */, 177 /* 0xb1 */, 178 /* 0xb2 */, 179 /* 0xb3 */,
180 /* 0xb4 */, 181 /* 0xb5 */, 182 /* 0xb6 */, 183 /* 0xb7 */,
184 /* 0xb8 */, 185 /* 0xb9 */, 186 /* 0xba */, 187 /* 0xbb */,
188 /* 0xbc */, 189 /* 0xbd */, 190 /* 0xbe */, 191 /* 0xbf */,
192 /* 0xc0 */, 193 /* 0xc1 */, 194 /* 0xc2 */, 195 /* 0xc3 */,
196 /* 0xc4 */, 197 /* 0xc5 */, 198 /* 0xc6 */, 199 /* 0xc7 */,
200 /* 0xc8 */, 201 /* 0xc9 */, 202 /* 0xca */, 203 /* 0xcb */,
204 /* 0xcc */, 205 /* 0xcd */, 206 /* 0xce */, 207 /* 0xcf */,
208 /* 0xd0 */, 209 /* 0xd1 */, 210 /* 0xd2 */, 211 /* 0xd3 */,
212 /* 0xd4 */, 213 /* 0xd5 */, 214 /* 0xd6 */, 215 /* 0xd7 */,
216 /* 0xd8 */, 217 /* 0xd9 */, 218 /* 0xda */, 219 /* 0xdb */,
220 /* 0xdc */, 221 /* 0xdd */, 222 /* 0xde */, 223 /* 0xdf */,
224 /* 0xe0 */, 225 /* 0xe1 */, 226 /* 0xe2 */, 227 /* 0xe3 */,
228 /* 0xe4 */, 229 /* 0xe5 */, 230 /* 0xe6 */, 231 /* 0xe7 */,
232 /* 0xe8 */, 233 /* 0xe9 */, 234 /* 0xea */, 235 /* 0xeb */,
236 /* 0xec */, 237 /* 0xed */, 238 /* 0xee */, 239 /* 0xef */,
240 /* 0xf0 */, 241 /* 0xf1 */, 242 /* 0xf2 */, 243 /* 0xf3 */,
244 /* 0xf4 */, 245 /* 0xf5 */, 246 /* 0xf6 */, 247 /* 0xf7 */,
248 /* 0xf8 */, 249 /* 0xf9 */, 250 /* 0xfa */, 251 /* 0xfb */,
252 /* 0xfc */, 253 /* 0xfd */, 254 /* 0xfe */, 255 /* 0xff */,
152 /* 0x98 */, 153 /* 0x99 */, 154 /* 0x9A */, 155 /* 0x9B */,
156 /* 0x9C */, 157 /* 0x9D */, 158 /* 0x9E */, 159 /* 0x9F */,
160 /* 0xA0 */, 161 /* 0xA1 */, 162 /* 0xA2 */, 163 /* 0xA3 */,
164 /* 0xA4 */, 165 /* 0xA5 */, 166 /* 0xA6 */, 167 /* 0xA7 */,
168 /* 0xA8 */, 169 /* 0xA9 */, 170 /* 0xAA */, 171 /* 0xAB */,
172 /* 0xAC */, 173 /* 0xAD */, 174 /* 0xAE */, 175 /* 0xAF */,
176 /* 0xB0 */, 177 /* 0xB1 */, 178 /* 0xB2 */, 179 /* 0xB3 */,
180 /* 0xB4 */, 181 /* 0xB5 */, 182 /* 0xB6 */, 183 /* 0xB7 */,
184 /* 0xB8 */, 185 /* 0xB9 */, 186 /* 0xBA */, 187 /* 0xBB */,
188 /* 0xBC */, 189 /* 0xBD */, 190 /* 0xBE */, 191 /* 0xBF */,
192 /* 0xC0 */, 193 /* 0xC1 */, 194 /* 0xC2 */, 195 /* 0xC3 */,
196 /* 0xC4 */, 197 /* 0xC5 */, 198 /* 0xC6 */, 199 /* 0xC7 */,
200 /* 0xC8 */, 201 /* 0xC9 */, 202 /* 0xCA */, 203 /* 0xCB */,
204 /* 0xCC */, 205 /* 0xCD */, 206 /* 0xCE */, 207 /* 0xCF */,
208 /* 0xD0 */, 209 /* 0xD1 */, 210 /* 0xD2 */, 211 /* 0xD3 */,
212 /* 0xD4 */, 213 /* 0xD5 */, 214 /* 0xD6 */, 215 /* 0xD7 */,
216 /* 0xD8 */, 217 /* 0xD9 */, 218 /* 0xDA */, 219 /* 0xDB */,
220 /* 0xDC */, 221 /* 0xDD */, 222 /* 0xDE */, 223 /* 0xDF */,
224 /* 0xE0 */, 225 /* 0xE1 */, 226 /* 0xE2 */, 227 /* 0xE3 */,
228 /* 0xE4 */, 229 /* 0xE5 */, 230 /* 0xE6 */, 231 /* 0xE7 */,
232 /* 0xE8 */, 233 /* 0xE9 */, 234 /* 0xEA */, 235 /* 0xEB */,
236 /* 0xEC */, 237 /* 0xED */, 238 /* 0xEE */, 239 /* 0xEF */,
240 /* 0xF0 */, 241 /* 0xF1 */, 242 /* 0xF2 */, 243 /* 0xF3 */,
244 /* 0xF4 */, 245 /* 0xF5 */, 246 /* 0xF6 */, 247 /* 0xF7 */,
248 /* 0xF8 */, 249 /* 0xF9 */, 250 /* 0xFA */, 251 /* 0xFB */,
252 /* 0xFC */, 253 /* 0xFD */, 254 /* 0xFE */, 255 /* 0xFF */,
};
void nghttp3_downcase(uint8_t *s, size_t len) {
+38 -41
View File
@@ -172,11 +172,11 @@ void nghttp3_stream_del(nghttp3_stream *stream) {
}
void nghttp3_varint_read_state_reset(nghttp3_varint_read_state *rvint) {
memset(rvint, 0, sizeof(*rvint));
*rvint = (nghttp3_varint_read_state){0};
}
void nghttp3_stream_read_state_reset(nghttp3_stream_read_state *rstate) {
memset(rstate, 0, sizeof(*rstate));
*rstate = (nghttp3_stream_read_state){0};
}
nghttp3_ssize nghttp3_read_varint(nghttp3_varint_read_state *rvint,
@@ -190,10 +190,10 @@ nghttp3_ssize nghttp3_read_varint(nghttp3_varint_read_state *rvint,
if (rvint->left == 0) {
assert(rvint->acc == 0);
vlen = nghttp3_get_varintlen(begin);
len = nghttp3_min_size(vlen, (size_t)(end - begin));
vlen = nghttp3_get_uvarintlen(begin);
len = nghttp3_min(vlen, (size_t)(end - begin));
if (vlen <= len) {
nghttp3_get_varint(&rvint->acc, begin);
nghttp3_get_uvarint(&rvint->acc, begin);
return (nghttp3_ssize)vlen;
}
@@ -203,19 +203,19 @@ nghttp3_ssize nghttp3_read_varint(nghttp3_varint_read_state *rvint,
p = (uint8_t *)&rvint->acc + (sizeof(rvint->acc) - vlen);
memcpy(p, begin, len);
*p &= 0x3f;
*p &= 0x3FU;
rvint->left = vlen - len;
return (nghttp3_ssize)len;
}
len = nghttp3_min_size(rvint->left, (size_t)(end - begin));
len = nghttp3_min(rvint->left, (size_t)(end - begin));
p = (uint8_t *)&rvint->acc + (sizeof(rvint->acc) - rvint->left);
memcpy(p, begin, len);
rvint->left -= len;
if (rvint->left == 0) {
rvint->acc = (int64_t)nghttp3_ntohl64((uint64_t)rvint->acc);
rvint->acc = nghttp3_ntohl64(rvint->acc);
} else if (fin) {
return NGHTTP3_ERR_INVALID_ARGUMENT;
}
@@ -223,22 +223,19 @@ nghttp3_ssize nghttp3_read_varint(nghttp3_varint_read_state *rvint,
return (nghttp3_ssize)len;
}
int nghttp3_stream_frq_add(nghttp3_stream *stream, const nghttp3_frame *fr) {
int nghttp3_stream_frq_emplace(nghttp3_stream *stream, nghttp3_frame **pfr) {
nghttp3_ringbuf *frq = &stream->frq;
nghttp3_frame *dest;
int rv;
if (nghttp3_ringbuf_full(frq)) {
size_t nlen =
nghttp3_max_size(NGHTTP3_MIN_RBLEN, nghttp3_ringbuf_len(frq) * 2);
size_t nlen = nghttp3_max(NGHTTP3_MIN_RBLEN, nghttp3_ringbuf_len(frq) * 2);
rv = nghttp3_ringbuf_reserve(frq, nlen);
if (rv != 0) {
return rv;
}
}
dest = nghttp3_ringbuf_push_back(frq);
*dest = *fr;
*pfr = nghttp3_ringbuf_push_back(frq);
return 0;
}
@@ -311,7 +308,7 @@ int nghttp3_stream_fill_outq(nghttp3_stream *stream) {
}
int nghttp3_stream_write_stream_type(nghttp3_stream *stream) {
size_t len = nghttp3_put_varintlen((int64_t)stream->type);
size_t len = nghttp3_put_uvarintlen(stream->type);
nghttp3_buf *chunk;
nghttp3_typed_buf tbuf;
int rv;
@@ -324,7 +321,7 @@ int nghttp3_stream_write_stream_type(nghttp3_stream *stream) {
chunk = nghttp3_stream_get_chunk(stream);
nghttp3_typed_buf_shared_init(&tbuf, chunk);
chunk->last = nghttp3_put_varint(chunk->last, (int64_t)stream->type);
chunk->last = nghttp3_put_uvarint(chunk->last, stream->type);
tbuf.buf.last = chunk->last;
return nghttp3_stream_outq_add(stream, &tbuf);
@@ -343,7 +340,7 @@ int nghttp3_stream_write_settings(nghttp3_stream *stream,
.iv = ents,
};
const nghttp3_settings *local_settings = infr->local_settings;
int64_t payloadlen;
uint64_t payloadlen;
ents[0] = (nghttp3_settings_entry){
.id = NGHTTP3_SETTINGS_ID_MAX_FIELD_SECTION_SIZE,
@@ -399,7 +396,7 @@ int nghttp3_stream_write_goaway(nghttp3_stream *stream,
int rv;
nghttp3_buf *chunk;
nghttp3_typed_buf tbuf;
int64_t payloadlen;
uint64_t payloadlen;
len = nghttp3_frame_write_goaway_len(&payloadlen, fr);
@@ -424,7 +421,7 @@ int nghttp3_stream_write_priority_update(
int rv;
nghttp3_buf *chunk;
nghttp3_typed_buf tbuf;
int64_t payloadlen;
uint64_t payloadlen;
len = nghttp3_frame_write_priority_update_len(&payloadlen, fr);
@@ -452,7 +449,7 @@ int nghttp3_stream_write_origin(nghttp3_stream *stream,
int rv;
rv = nghttp3_stream_ensure_chunk(
stream, nghttp3_frame_write_hd_len(fr->type, (int64_t)fr->origin_list.len));
stream, nghttp3_frame_write_hd_len(fr->type, fr->origin_list.len));
if (rv != 0) {
return rv;
}
@@ -461,7 +458,7 @@ int nghttp3_stream_write_origin(nghttp3_stream *stream,
nghttp3_typed_buf_shared_init(&tbuf, chunk);
chunk->last =
nghttp3_frame_write_hd(chunk->last, fr->type, (int64_t)fr->origin_list.len);
nghttp3_frame_write_hd(chunk->last, fr->type, fr->origin_list.len);
tbuf.buf.last = chunk->last;
@@ -497,8 +494,8 @@ int nghttp3_stream_write_header_block(nghttp3_stream *stream,
nghttp3_qpack_encoder *qenc,
nghttp3_stream *qenc_stream,
nghttp3_buf *rbuf, nghttp3_buf *ebuf,
int64_t frame_type, const nghttp3_nv *nva,
size_t nvlen) {
uint64_t frame_type,
const nghttp3_nv *nva, size_t nvlen) {
nghttp3_buf pbuf;
int rv;
size_t len;
@@ -506,7 +503,7 @@ int nghttp3_stream_write_header_block(nghttp3_stream *stream,
nghttp3_typed_buf tbuf;
uint8_t raw_pbuf[16];
size_t pbuflen, rbuflen, ebuflen;
int64_t payloadlen;
uint64_t payloadlen;
nghttp3_buf_wrap_init(&pbuf, raw_pbuf, sizeof(raw_pbuf));
@@ -520,7 +517,7 @@ int nghttp3_stream_write_header_block(nghttp3_stream *stream,
rbuflen = nghttp3_buf_len(rbuf);
ebuflen = nghttp3_buf_len(ebuf);
payloadlen = (int64_t)(pbuflen + rbuflen);
payloadlen = pbuflen + rbuflen;
len = nghttp3_frame_write_hd_len(frame_type, payloadlen) + pbuflen;
@@ -612,7 +609,7 @@ int nghttp3_stream_write_data(nghttp3_stream *stream, int *peof,
nghttp3_buf *chunk;
nghttp3_read_data_callback read_data = fr->dr.read_data;
nghttp3_conn *conn = stream->conn;
int64_t datalen;
uint64_t datalen;
uint32_t flags = 0;
nghttp3_vec vec[8];
nghttp3_vec *v;
@@ -635,8 +632,8 @@ int nghttp3_stream_write_data(nghttp3_stream *stream, int *peof,
return NGHTTP3_ERR_CALLBACK_FAILURE;
}
datalen = nghttp3_vec_len_varint(vec, (size_t)sveccnt);
if (datalen == -1) {
rv = nghttp3_vec_len_uvarint(&datalen, vec, (size_t)sveccnt);
if (rv == -1) {
return NGHTTP3_ERR_STREAM_DATA_OVERFLOW;
}
@@ -720,7 +717,7 @@ int nghttp3_stream_write_qpack_decoder_stream(nghttp3_stream *stream) {
assert(qdec);
len = nghttp3_qpack_decoder_get_decoder_streamlen(qdec);
len = nghttp3_qpack_decoder_get_decoder_streamlen2(qdec);
if (len == 0) {
return 0;
}
@@ -774,7 +771,7 @@ int nghttp3_stream_outq_add(nghttp3_stream *stream,
}
if (nghttp3_ringbuf_full(outq)) {
size_t nlen = nghttp3_max_size(NGHTTP3_MIN_RBLEN, len * 2);
size_t nlen = nghttp3_max(NGHTTP3_MIN_RBLEN, len * 2);
rv = nghttp3_ringbuf_reserve(outq, nlen);
if (rv != 0) {
return rv;
@@ -816,7 +813,7 @@ int nghttp3_stream_ensure_chunk(nghttp3_stream *stream, size_t need) {
}
if (nghttp3_ringbuf_full(chunks)) {
size_t nlen = nghttp3_max_size(NGHTTP3_MIN_RBLEN, len * 2);
size_t nlen = nghttp3_max(NGHTTP3_MIN_RBLEN, len * 2);
rv = nghttp3_ringbuf_reserve(chunks, nlen);
if (rv != 0) {
return rv;
@@ -838,13 +835,13 @@ nghttp3_buf *nghttp3_stream_get_chunk(nghttp3_stream *stream) {
return nghttp3_ringbuf_get(chunks, len - 1);
}
int nghttp3_stream_is_blocked(nghttp3_stream *stream) {
int nghttp3_stream_is_blocked(const nghttp3_stream *stream) {
return (stream->flags & NGHTTP3_STREAM_FLAG_FC_BLOCKED) ||
(stream->flags & NGHTTP3_STREAM_FLAG_SHUT_WR) ||
(stream->flags & NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED);
}
int nghttp3_stream_require_schedule(nghttp3_stream *stream) {
int nghttp3_stream_require_schedule(const nghttp3_stream *stream) {
return (!nghttp3_stream_outq_write_done(stream) &&
!(stream->flags & NGHTTP3_STREAM_FLAG_FC_BLOCKED) &&
!(stream->flags & NGHTTP3_STREAM_FLAG_SHUT_WR)) ||
@@ -912,8 +909,8 @@ void nghttp3_stream_add_outq_offset(nghttp3_stream *stream, size_t n) {
stream->outq_idx = i;
}
int nghttp3_stream_outq_write_done(nghttp3_stream *stream) {
nghttp3_ringbuf *outq = &stream->outq;
int nghttp3_stream_outq_write_done(const nghttp3_stream *stream) {
const nghttp3_ringbuf *outq = &stream->outq;
size_t len = nghttp3_ringbuf_len(outq);
return len == 0 || stream->outq_idx >= len;
@@ -969,8 +966,8 @@ int nghttp3_stream_update_ack_offset(nghttp3_stream *stream, uint64_t offset) {
/* For NGHTTP3_BUF_TYPE_ALIEN, we never add 0 length buffer. */
if (tbuf->type == NGHTTP3_BUF_TYPE_ALIEN && stream->ack_offset < offset &&
stream->callbacks.acked_data) {
nack = nghttp3_min_uint64(offset, stream->ack_base + buflen) -
stream->ack_offset;
nack =
nghttp3_min(offset, stream->ack_base + buflen) - stream->ack_offset;
rv = stream->callbacks.acked_data(stream, stream->node.id, nack,
stream->user_data);
@@ -1011,7 +1008,7 @@ int nghttp3_stream_buffer_data(nghttp3_stream *stream, const uint8_t *data,
if (len) {
buf = nghttp3_ringbuf_get(inq, len - 1);
bufleft = nghttp3_buf_left(buf);
nwrite = nghttp3_min_size(datalen, bufleft);
nwrite = nghttp3_min(datalen, bufleft);
buf->last = nghttp3_cpymem(buf->last, data, nwrite);
data += nwrite;
datalen -= nwrite;
@@ -1020,7 +1017,7 @@ int nghttp3_stream_buffer_data(nghttp3_stream *stream, const uint8_t *data,
for (; datalen;) {
if (nghttp3_ringbuf_full(inq)) {
size_t nlen =
nghttp3_max_size(NGHTTP3_MIN_RBLEN, nghttp3_ringbuf_len(inq) * 2);
nghttp3_max(NGHTTP3_MIN_RBLEN, nghttp3_ringbuf_len(inq) * 2);
rv = nghttp3_ringbuf_reserve(inq, nlen);
if (rv != 0) {
return rv;
@@ -1035,7 +1032,7 @@ int nghttp3_stream_buffer_data(nghttp3_stream *stream, const uint8_t *data,
buf = nghttp3_ringbuf_push_back(inq);
nghttp3_buf_wrap_init(buf, rawbuf, 16384);
bufleft = nghttp3_buf_left(buf);
nwrite = nghttp3_min_size(datalen, bufleft);
nwrite = nghttp3_min(datalen, bufleft);
buf->last = nghttp3_cpymem(buf->last, data, nwrite);
data += nwrite;
datalen -= nwrite;
@@ -1229,7 +1226,7 @@ int nghttp3_stream_transit_rx_http_state(nghttp3_stream *stream,
}
}
int nghttp3_stream_empty_headers_allowed(nghttp3_stream *stream) {
int nghttp3_stream_empty_headers_allowed(const nghttp3_stream *stream) {
switch (stream->rx.hstate) {
case NGHTTP3_HTTP_STATE_REQ_TRAILERS_BEGIN:
case NGHTTP3_HTTP_STATE_RESP_TRAILERS_BEGIN:
+35 -24
View File
@@ -52,10 +52,10 @@
/* nghttp3_stream_type is unidirectional stream type. */
typedef uint64_t nghttp3_stream_type;
#define NGHTTP3_STREAM_TYPE_CONTROL 0x00
#define NGHTTP3_STREAM_TYPE_PUSH 0x01
#define NGHTTP3_STREAM_TYPE_QPACK_ENCODER 0x02
#define NGHTTP3_STREAM_TYPE_QPACK_DECODER 0x03
#define NGHTTP3_STREAM_TYPE_CONTROL 0x00U
#define NGHTTP3_STREAM_TYPE_PUSH 0x01U
#define NGHTTP3_STREAM_TYPE_QPACK_ENCODER 0x02U
#define NGHTTP3_STREAM_TYPE_QPACK_DECODER 0x03U
#define NGHTTP3_STREAM_TYPE_UNKNOWN UINT64_MAX
typedef enum nghttp3_ctrl_stream_state {
@@ -83,7 +83,7 @@ typedef enum nghttp3_req_stream_state {
} nghttp3_req_stream_state;
typedef struct nghttp3_varint_read_state {
int64_t acc;
uint64_t acc;
size_t left;
} nghttp3_varint_read_state;
@@ -91,43 +91,43 @@ typedef struct nghttp3_stream_read_state {
nghttp3_varint_read_state rvint;
nghttp3_settings_entry iv;
nghttp3_frame fr;
int64_t left;
uint64_t left;
int state;
} nghttp3_stream_read_state;
/* NGHTTP3_STREAM_FLAG_NONE indicates that no flag is set. */
#define NGHTTP3_STREAM_FLAG_NONE 0x0000u
#define NGHTTP3_STREAM_FLAG_NONE 0x0000U
/* NGHTTP3_STREAM_FLAG_TYPE_IDENTIFIED is set when a unidirectional
stream type is identified. */
#define NGHTTP3_STREAM_FLAG_TYPE_IDENTIFIED 0x0001u
#define NGHTTP3_STREAM_FLAG_TYPE_IDENTIFIED 0x0001U
/* NGHTTP3_STREAM_FLAG_FC_BLOCKED indicates that stream is blocked by
QUIC flow control. */
#define NGHTTP3_STREAM_FLAG_FC_BLOCKED 0x0002u
#define NGHTTP3_STREAM_FLAG_FC_BLOCKED 0x0002U
/* NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED indicates that application is
temporarily unable to provide data. */
#define NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED 0x0004u
#define NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED 0x0004U
/* NGHTTP3_STREAM_FLAG_WRITE_END_STREAM indicates that application
finished to feed outgoing data. */
#define NGHTTP3_STREAM_FLAG_WRITE_END_STREAM 0x0008u
#define NGHTTP3_STREAM_FLAG_WRITE_END_STREAM 0x0008U
/* NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED indicates that stream is
blocked due to QPACK decoding. */
#define NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED 0x0010u
#define NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED 0x0010U
/* NGHTTP3_STREAM_FLAG_READ_EOF indicates that remote endpoint sent
fin. */
#define NGHTTP3_STREAM_FLAG_READ_EOF 0x0020u
#define NGHTTP3_STREAM_FLAG_READ_EOF 0x0020U
/* NGHTTP3_STREAM_FLAG_SHUT_WR indicates that any further write
operation to a stream is prohibited. */
#define NGHTTP3_STREAM_FLAG_SHUT_WR 0x0100u
#define NGHTTP3_STREAM_FLAG_SHUT_WR 0x0100U
/* NGHTTP3_STREAM_FLAG_SHUT_RD indicates that a read-side stream is
closed abruptly and any incoming and pending stream data is just
discarded for a stream. */
#define NGHTTP3_STREAM_FLAG_SHUT_RD 0x0200u
#define NGHTTP3_STREAM_FLAG_SHUT_RD 0x0200U
/* NGHTTP3_STREAM_FLAG_SERVER_PRIORITY_SET indicates that server
overrides stream priority. */
#define NGHTTP3_STREAM_FLAG_SERVER_PRIORITY_SET 0x0400u
#define NGHTTP3_STREAM_FLAG_SERVER_PRIORITY_SET 0x0400U
/* NGHTTP3_STREAM_FLAG_PRIORITY_UPDATE_RECVED indicates that server
received PRIORITY_UPDATE frame for this stream. */
#define NGHTTP3_STREAM_FLAG_PRIORITY_UPDATE_RECVED 0x0800u
#define NGHTTP3_STREAM_FLAG_PRIORITY_UPDATE_RECVED 0x0800U
typedef enum nghttp3_stream_http_state {
NGHTTP3_HTTP_STATE_NONE,
@@ -262,7 +262,18 @@ nghttp3_ssize nghttp3_read_varint(nghttp3_varint_read_state *rvint,
const uint8_t *begin, const uint8_t *end,
int fin);
int nghttp3_stream_frq_add(nghttp3_stream *stream, const nghttp3_frame *fr);
/*
* nghttp3_stream_frq_emplace adds new space for nghttp3_frame to
* stream->frq, and assigns the pointer to the space to |*pfr| if it
* succeeds.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
int nghttp3_stream_frq_emplace(nghttp3_stream *stream, nghttp3_frame **pfr);
int nghttp3_stream_fill_outq(nghttp3_stream *stream);
@@ -283,8 +294,8 @@ int nghttp3_stream_write_header_block(nghttp3_stream *stream,
nghttp3_qpack_encoder *qenc,
nghttp3_stream *qenc_stream,
nghttp3_buf *rbuf, nghttp3_buf *ebuf,
int64_t frame_type, const nghttp3_nv *nva,
size_t nvlen);
uint64_t frame_type,
const nghttp3_nv *nva, size_t nvlen);
int nghttp3_stream_write_data(nghttp3_stream *stream, int *peof,
const nghttp3_frame_data *fr);
@@ -305,7 +316,7 @@ int nghttp3_stream_ensure_chunk(nghttp3_stream *stream, size_t need);
nghttp3_buf *nghttp3_stream_get_chunk(nghttp3_stream *stream);
int nghttp3_stream_is_blocked(nghttp3_stream *stream);
int nghttp3_stream_is_blocked(const nghttp3_stream *stream);
void nghttp3_stream_add_outq_offset(nghttp3_stream *stream, size_t n);
@@ -313,7 +324,7 @@ void nghttp3_stream_add_outq_offset(nghttp3_stream *stream, size_t n);
* nghttp3_stream_outq_write_done returns nonzero if all contents in
* outq have been written.
*/
int nghttp3_stream_outq_write_done(nghttp3_stream *stream);
int nghttp3_stream_outq_write_done(const nghttp3_stream *stream);
/*
* nghttp2_stream_update_ack_offset updates the last acknowledged
@@ -333,7 +344,7 @@ int nghttp3_stream_is_active(nghttp3_stream *stream);
* be scheduled. In other words, |stream| or its descendants have
* something to send.
*/
int nghttp3_stream_require_schedule(nghttp3_stream *stream);
int nghttp3_stream_require_schedule(const nghttp3_stream *stream);
int nghttp3_stream_buffer_data(nghttp3_stream *stream, const uint8_t *src,
size_t srclen);
@@ -347,7 +358,7 @@ void nghttp3_stream_delete_qpack_stream_context(nghttp3_stream *stream);
int nghttp3_stream_transit_rx_http_state(nghttp3_stream *stream,
nghttp3_stream_http_event event);
int nghttp3_stream_empty_headers_allowed(nghttp3_stream *stream);
int nghttp3_stream_empty_headers_allowed(const nghttp3_stream *stream);
/*
* nghttp3_stream_uni returns nonzero if stream identified by
+4 -4
View File
@@ -56,7 +56,7 @@ void nghttp3_tnode_unschedule(nghttp3_tnode *tnode, nghttp3_pq *pq) {
tnode_unschedule(tnode, pq);
}
static uint64_t pq_get_first_cycle(nghttp3_pq *pq) {
static uint64_t pq_get_first_cycle(const nghttp3_pq *pq) {
nghttp3_tnode *top;
if (nghttp3_pq_empty(pq)) {
@@ -74,7 +74,7 @@ int nghttp3_tnode_schedule(nghttp3_tnode *tnode, nghttp3_pq *pq,
if (tnode->pe.index == NGHTTP3_PQ_BAD_INDEX) {
tnode->cycle =
pq_get_first_cycle(pq) +
((nwrite == 0 || !tnode->pri.inc) ? 0 : nghttp3_max_uint64(1, penalty));
((nwrite == 0 || !tnode->pri.inc) ? 0 : nghttp3_max(1, penalty));
} else if (nwrite > 0) {
if (!tnode->pri.inc || nghttp3_pq_size(pq) == 1) {
return 0;
@@ -82,7 +82,7 @@ int nghttp3_tnode_schedule(nghttp3_tnode *tnode, nghttp3_pq *pq,
nghttp3_pq_remove(pq, &tnode->pe);
tnode->pe.index = NGHTTP3_PQ_BAD_INDEX;
tnode->cycle += nghttp3_max_uint64(1, penalty);
tnode->cycle += nghttp3_max(1, penalty);
} else {
return 0;
}
@@ -90,6 +90,6 @@ int nghttp3_tnode_schedule(nghttp3_tnode *tnode, nghttp3_pq *pq,
return nghttp3_pq_push(pq, &tnode->pe);
}
int nghttp3_tnode_is_scheduled(nghttp3_tnode *tnode) {
int nghttp3_tnode_is_scheduled(const nghttp3_tnode *tnode) {
return tnode->pe.index != NGHTTP3_PQ_BAD_INDEX;
}
+2 -3
View File
@@ -33,13 +33,12 @@
#include "nghttp3_pq.h"
#define NGHTTP3_TNODE_MAX_CYCLE_GAP (1llu << 24)
#define NGHTTP3_TNODE_MAX_CYCLE_GAP (1ULL << 24)
typedef struct nghttp3_tnode {
nghttp3_pq_entry pe;
int64_t id;
uint64_t cycle;
/* pri is a stream priority produced by nghttp3_pri_to_uint8. */
nghttp3_pri pri;
} nghttp3_tnode;
@@ -60,6 +59,6 @@ int nghttp3_tnode_schedule(nghttp3_tnode *tnode, nghttp3_pq *pq,
/*
* nghttp3_tnode_is_scheduled returns nonzero if |tnode| is scheduled.
*/
int nghttp3_tnode_is_scheduled(nghttp3_tnode *tnode);
int nghttp3_tnode_is_scheduled(const nghttp3_tnode *tnode);
#endif /* !defined(NGHTTP3_TNODE_H) */
+4 -2
View File
@@ -37,7 +37,7 @@ uint64_t nghttp3_vec_len(const nghttp3_vec *vec, size_t n) {
return res;
}
int64_t nghttp3_vec_len_varint(const nghttp3_vec *vec, size_t n) {
int nghttp3_vec_len_uvarint(uint64_t *dest, const nghttp3_vec *vec, size_t n) {
uint64_t res = 0;
size_t len;
size_t i;
@@ -51,5 +51,7 @@ int64_t nghttp3_vec_len_varint(const nghttp3_vec *vec, size_t n) {
res += len;
}
return (int64_t)res;
*dest = res;
return 0;
}
+5 -3
View File
@@ -33,9 +33,11 @@
#include <nghttp3/nghttp3.h>
/*
* nghttp3_vec_len_varint is similar to nghttp3_vec_len, but it
* returns -1 if the sum of the length exceeds NGHTTP3_MAX_VARINT.
* nghttp3_vec_len_uvarint is similar to nghttp3_vec_len, but it
* stores the return value from nghttp3_vec_len(|vec|, |n|) into
* |dest| if it does not exceed NGHTTP3_MAX_VARINT, and returns 0.
* Otherwise returns -1.
*/
int64_t nghttp3_vec_len_varint(const nghttp3_vec *vec, size_t n);
int nghttp3_vec_len_uvarint(uint64_t *dest, const nghttp3_vec *vec, size_t n);
#endif /* !defined(NGHTTP3_VEC_H) */