deps: update nghttp3 to 1.14.0

PR-URL: https://github.com/nodejs/node/pull/61187
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Node.js GitHub Bot authored and Antoine du Hamel committed 2026-05-07 17:32:43 +02:00
1 parent 5304db93d3
commit 722c0c3274
24 files changed
+451 -587

No files matched your search

+78 -2
View File
@@ -1749,7 +1749,11 @@ typedef struct nghttp3_conn nghttp3_conn;
typedef struct nghttp3_settings {
/**
* :member:`max_field_section_size` specifies the maximum header
* section (block) size.
* section (block) size. nghttp3 library does not enforce this
* limit. Applications are responsible for imposing their own
* limits to protect against resource exhaustion. See
* https://datatracker.ietf.org/doc/html/rfc9114#section-4.2.2 for
* details.
*/
uint64_t max_field_section_size;
/**
@@ -1828,6 +1832,44 @@ typedef struct nghttp3_settings {
nghttp3_qpack_indexing_strat qpack_indexing_strat;
} nghttp3_settings;
#define NGHTTP3_PROTO_SETTINGS_V1 1
#define NGHTTP3_PROTO_SETTINGS_VERSION NGHTTP3_PROTO_SETTINGS_V1
/**
* @struct
*
* :type:`nghttp3_proto_settings` contains HTTP/3 settings that this
* library can recognize. This field is available since v1.14.0.
*/
typedef struct nghttp3_proto_settings {
/**
* :member:`max_field_section_size` specifies the maximum header
* section (block) size.
*/
uint64_t max_field_section_size;
/**
* :member:`qpack_max_dtable_capacity` is the maximum size of QPACK
* dynamic table.
*/
size_t qpack_max_dtable_capacity;
/**
* :member:`qpack_blocked_streams` is the maximum number of streams
* which can be blocked while they are being decoded.
*/
size_t qpack_blocked_streams;
/**
* :member:`enable_connect_protocol`, if set to nonzero, enables
* Extended CONNECT Method (see :rfc:`9220`). Client ignores this
* field.
*/
uint8_t enable_connect_protocol;
/**
* :member:`h3_datagram`, if set to nonzero, enables HTTP/3
* Datagrams (see :rfc:`9297`).
*/
uint8_t h3_datagram;
} nghttp3_proto_settings;
/**
* @functypedef
*
@@ -2052,6 +2094,11 @@ typedef int (*nghttp3_shutdown)(nghttp3_conn *conn, int64_t id,
/**
* @functypedef
*
* .. warning::
*
* Deprecated since v1.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
* remote HTTP/3 settings.
@@ -2103,9 +2150,27 @@ typedef int (*nghttp3_end_origin)(nghttp3_conn *conn, void *conn_user_data);
*/
typedef void (*nghttp3_rand)(uint8_t *dest, size_t destlen);
/**
* @functypedef
*
* :type:`nghttp3_recv_settings2` is a callback function which is
* invoked when SETTINGS frame is received. |settings| is a received
* remote HTTP/3 settings.
*
* 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.
*/
typedef int (*nghttp3_recv_settings2)(nghttp3_conn *conn,
const nghttp3_proto_settings *settings,
void *conn_user_data);
#define NGHTTP3_CALLBACKS_V1 1
#define NGHTTP3_CALLBACKS_V2 2
#define NGHTTP3_CALLBACKS_VERSION NGHTTP3_CALLBACKS_V2
#define NGHTTP3_CALLBACKS_V3 3
#define NGHTTP3_CALLBACKS_VERSION NGHTTP3_CALLBACKS_V3
/**
* @struct
@@ -2195,6 +2260,11 @@ typedef struct nghttp3_callbacks {
*/
nghttp3_shutdown shutdown;
/**
* .. warning::
*
* Deprecated since v1.14.0. Use :member:`recv_settings2`
* instead.
*
* :member:`recv_settings` is a callback function which is invoked
* when SETTINGS frame is received.
*/
@@ -2221,6 +2291,12 @@ typedef struct nghttp3_callbacks {
* v1.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.
*/
nghttp3_recv_settings2 recv_settings2;
} nghttp3_callbacks;
/**
+2 -2
View File
@@ -31,7 +31,7 @@
*
* Version number of the nghttp3 library release.
*/
#define NGHTTP3_VERSION "1.13.1"
#define NGHTTP3_VERSION "1.14.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 0x010d01
#define NGHTTP3_VERSION_NUM 0x010e00
#endif /* !defined(NGHTTP3_VERSION_H) */
+1 -1
View File
@@ -64,7 +64,7 @@ typedef struct nghttp3_balloc {
/*
* nghttp3_balloc_init initializes |balloc| with |blklen| which is the
* size of memory block.
* size of memory block. |blklen| must be divisible by 16.
*/
void nghttp3_balloc_init(nghttp3_balloc *balloc, size_t blklen,
const nghttp3_mem *mem);
+6 -4
View File
@@ -72,10 +72,12 @@ int nghttp3_buf_reserve(nghttp3_buf *buf, size_t size, const nghttp3_mem *mem) {
return NGHTTP3_ERR_NOMEM;
}
buf->begin = p;
buf->end = p + size;
buf->pos = p + pos_offset;
buf->last = p + last_offset;
*buf = (nghttp3_buf){
.begin = p,
.end = p + size,
.pos = p + pos_offset,
.last = p + last_offset,
};
return 0;
}
+2
View File
@@ -66,6 +66,8 @@ size_t nghttp3_callbackslen_version(int callbacks_version) {
switch (callbacks_version) {
case NGHTTP3_CALLBACKS_VERSION:
return sizeof(callbacks);
case NGHTTP3_CALLBACKS_V2:
return offsetof(nghttp3_callbacks, rand) + sizeof(callbacks.rand);
case NGHTTP3_CALLBACKS_V1:
return offsetof(nghttp3_callbacks, recv_settings) +
sizeof(callbacks.recv_settings);
+74 -46
View File
@@ -192,12 +192,32 @@ static int conn_call_deferred_consume(nghttp3_conn *conn,
static int conn_call_recv_settings(nghttp3_conn *conn) {
int rv;
if (!conn->callbacks.recv_settings) {
if (!conn->callbacks.recv_settings2) {
if (!conn->callbacks.recv_settings) {
return 0;
}
rv = conn->callbacks.recv_settings(
conn,
&(nghttp3_settings){
.max_field_section_size = conn->remote.settings.max_field_section_size,
.qpack_max_dtable_capacity =
conn->remote.settings.qpack_max_dtable_capacity,
.qpack_blocked_streams = conn->remote.settings.qpack_blocked_streams,
.enable_connect_protocol =
conn->remote.settings.enable_connect_protocol,
.h3_datagram = conn->remote.settings.h3_datagram,
},
conn->user_data);
if (rv != 0) {
return NGHTTP3_ERR_CALLBACK_FAILURE;
}
return 0;
}
rv = conn->callbacks.recv_settings(conn, &conn->remote.settings,
conn->user_data);
rv = conn->callbacks.recv_settings2(conn, &conn->remote.settings,
conn->user_data);
if (rv != 0) {
return NGHTTP3_ERR_CALLBACK_FAILURE;
}
@@ -334,7 +354,7 @@ static int conn_new(nghttp3_conn **pconn, int server, int callbacks_version,
conn->local.settings.enable_connect_protocol = 0;
conn->local.settings.origin_list = NULL;
}
nghttp3_settings_default(&conn->remote.settings);
conn->remote.settings.max_field_section_size = NGHTTP3_VARINT_MAX;
conn->mem = mem;
conn->user_data = user_data;
conn->server = server;
@@ -507,7 +527,6 @@ nghttp3_ssize nghttp3_conn_read_stream2(nghttp3_conn *conn, int64_t stream_id,
}
stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL;
stream->tx.hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL;
} else if (nghttp3_server_stream_uni(stream_id)) {
if (srclen == 0 && fin) {
return 0;
@@ -519,7 +538,6 @@ nghttp3_ssize nghttp3_conn_read_stream2(nghttp3_conn *conn, int64_t stream_id,
}
stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_INITIAL;
stream->tx.hstate = NGHTTP3_HTTP_STATE_RESP_INITIAL;
} else {
/* client doesn't expect to receive new bidirectional stream or
client initiated unidirectional stream from server. */
@@ -743,7 +761,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
return (nghttp3_ssize)nconsumed;
}
rstate->fr.type = rvint->acc;
rstate->fr.hd.type = rvint->acc;
nghttp3_varint_read_state_reset(rvint);
rstate->state = NGHTTP3_CTRL_STREAM_STATE_FRAME_LENGTH;
if (p == end) {
@@ -767,15 +785,15 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
nghttp3_varint_read_state_reset(rvint);
if (!(conn->flags & NGHTTP3_CONN_FLAG_SETTINGS_RECVED)) {
if (rstate->fr.type != NGHTTP3_FRAME_SETTINGS) {
if (rstate->fr.hd.type != NGHTTP3_FRAME_SETTINGS) {
return NGHTTP3_ERR_H3_MISSING_SETTINGS;
}
conn->flags |= NGHTTP3_CONN_FLAG_SETTINGS_RECVED;
} else if (rstate->fr.type == NGHTTP3_FRAME_SETTINGS) {
} else if (rstate->fr.hd.type == NGHTTP3_FRAME_SETTINGS) {
return NGHTTP3_ERR_H3_FRAME_UNEXPECTED;
}
switch (rstate->fr.type) {
switch (rstate->fr.hd.type) {
case NGHTTP3_FRAME_SETTINGS:
/* SETTINGS frame might be empty. */
if (rstate->left == 0) {
@@ -787,6 +805,7 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
nghttp3_stream_read_state_reset(rstate);
break;
}
rstate->fr.settings.iv = &rstate->iv;
rstate->state = NGHTTP3_CTRL_STREAM_STATE_SETTINGS;
break;
case NGHTTP3_FRAME_GOAWAY:
@@ -1094,8 +1113,9 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
nghttp3_varint_read_state_reset(rvint);
if (rstate->left == 0) {
rstate->fr.priority_update.pri.urgency = NGHTTP3_DEFAULT_URGENCY;
rstate->fr.priority_update.pri.inc = 0;
rstate->fr.priority_update.pri = (nghttp3_pri){
.urgency = NGHTTP3_DEFAULT_URGENCY,
};
rv = nghttp3_conn_on_priority_update(conn, &rstate->fr.priority_update);
if (rv != 0) {
@@ -1154,8 +1174,9 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
return (nghttp3_ssize)nconsumed;
}
rstate->fr.priority_update.pri.urgency = NGHTTP3_DEFAULT_URGENCY;
rstate->fr.priority_update.pri.inc = 0;
rstate->fr.priority_update.pri = (nghttp3_pri){
.urgency = NGHTTP3_DEFAULT_URGENCY,
};
if (nghttp3_http_parse_priority(&rstate->fr.priority_update.pri,
pri_field_value,
@@ -1393,7 +1414,7 @@ static int conn_process_blocked_stream_data(nghttp3_conn *conn,
rv = conn_call_deferred_consume(conn, stream, (size_t)nconsumed);
if (rv != 0) {
return 0;
return rv;
}
if (nghttp3_buf_len(buf) == 0) {
@@ -1521,7 +1542,7 @@ nghttp3_ssize nghttp3_conn_read_bidi(nghttp3_conn *conn, size_t *pnproc,
goto almost_done;
}
rstate->fr.type = rvint->acc;
rstate->fr.hd.type = rvint->acc;
nghttp3_varint_read_state_reset(rvint);
rstate->state = NGHTTP3_REQ_STREAM_STATE_FRAME_LENGTH;
if (p == end) {
@@ -1544,7 +1565,7 @@ nghttp3_ssize nghttp3_conn_read_bidi(nghttp3_conn *conn, size_t *pnproc,
rstate->left = rvint->acc;
nghttp3_varint_read_state_reset(rvint);
switch (rstate->fr.type) {
switch (rstate->fr.hd.type) {
case NGHTTP3_FRAME_DATA:
rv = nghttp3_stream_transit_rx_http_state(
stream, NGHTTP3_HTTP_EVENT_DATA_BEGIN);
@@ -1921,7 +1942,7 @@ nghttp3_ssize nghttp3_conn_on_headers(nghttp3_conn *conn,
int nghttp3_conn_on_settings_entry_received(nghttp3_conn *conn,
const nghttp3_frame_settings *fr) {
const nghttp3_settings_entry *ent = &fr->iv[0];
nghttp3_settings *dest = &conn->remote.settings;
nghttp3_proto_settings *dest = &conn->remote.settings;
/* TODO Check for duplicates */
switch (ent->id) {
@@ -1957,7 +1978,7 @@ int nghttp3_conn_on_settings_entry_received(nghttp3_conn *conn,
&conn->qenc, (size_t)nghttp3_min_uint64(100, ent->value));
break;
case NGHTTP3_SETTINGS_ID_ENABLE_CONNECT_PROTOCOL:
if (!conn->server) {
if (conn->server) {
break;
}
@@ -2042,7 +2063,6 @@ conn_on_priority_update_stream(nghttp3_conn *conn,
stream->node.pri = fr->pri;
stream->flags |= NGHTTP3_STREAM_FLAG_PRIORITY_UPDATE_RECVED;
stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL;
stream->tx.hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL;
return 0;
}
@@ -2086,11 +2106,11 @@ int nghttp3_conn_create_stream(nghttp3_conn *conn, nghttp3_stream **pstream,
int64_t stream_id) {
nghttp3_stream *stream;
int rv;
nghttp3_stream_callbacks callbacks = {
.acked_data = conn_stream_acked_data,
};
rv = nghttp3_stream_new(&stream, stream_id, &callbacks,
rv = nghttp3_stream_new(&stream, stream_id,
&(nghttp3_stream_callbacks){
.acked_data = conn_stream_acked_data,
},
&conn->out_chunk_objalloc, &conn->stream_objalloc,
conn->mem);
if (rv != 0) {
@@ -2148,7 +2168,7 @@ int nghttp3_conn_bind_control_stream(nghttp3_conn *conn, int64_t stream_id) {
return rv;
}
frent.fr.type = NGHTTP3_FRAME_SETTINGS;
frent.fr.settings.type = NGHTTP3_FRAME_SETTINGS;
frent.aux.settings.local_settings = &conn->local.settings;
rv = nghttp3_stream_frq_add(stream, &frent);
@@ -2159,8 +2179,10 @@ int nghttp3_conn_bind_control_stream(nghttp3_conn *conn, int64_t stream_id) {
if (conn->local.settings.origin_list) {
assert(conn->server);
frent.fr.origin.type = NGHTTP3_FRAME_ORIGIN;
frent.fr.origin.origin_list = *conn->local.settings.origin_list;
frent.fr.origin = (nghttp3_frame_origin){
.type = NGHTTP3_FRAME_ORIGIN,
.origin_list = *conn->local.settings.origin_list,
};
rv = nghttp3_stream_frq_add(stream, &frent);
if (rv != 0) {
@@ -2399,9 +2421,11 @@ static int conn_submit_headers_data(nghttp3_conn *conn, nghttp3_stream *stream,
return rv;
}
frent.fr.type = NGHTTP3_FRAME_HEADERS;
frent.fr.headers.nva = nnva;
frent.fr.headers.nvlen = nvlen;
frent.fr.headers = (nghttp3_frame_headers){
.type = NGHTTP3_FRAME_HEADERS,
.nva = nnva,
.nvlen = nvlen,
};
rv = nghttp3_stream_frq_add(stream, &frent);
if (rv != 0) {
@@ -2410,7 +2434,9 @@ static int conn_submit_headers_data(nghttp3_conn *conn, nghttp3_stream *stream,
}
if (dr) {
frent.fr.type = NGHTTP3_FRAME_DATA;
frent.fr.data = (nghttp3_frame_data){
.type = NGHTTP3_FRAME_DATA,
};
frent.aux.data.dr = *dr;
rv = nghttp3_stream_frq_add(stream, &frent);
@@ -2488,7 +2514,6 @@ int nghttp3_conn_submit_request(nghttp3_conn *conn, int64_t stream_id,
return rv;
}
stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_INITIAL;
stream->tx.hstate = NGHTTP3_HTTP_STATE_REQ_END;
stream->user_data = stream_user_data;
nghttp3_http_record_request_method(stream, nva, nvlen);
@@ -2565,9 +2590,11 @@ int nghttp3_conn_submit_shutdown_notice(nghttp3_conn *conn) {
assert(conn->tx.ctrl);
frent.fr.type = NGHTTP3_FRAME_GOAWAY;
frent.fr.goaway.id = conn->server ? NGHTTP3_SHUTDOWN_NOTICE_STREAM_ID
: NGHTTP3_SHUTDOWN_NOTICE_PUSH_ID;
frent.fr.goaway = (nghttp3_frame_goaway){
.type = NGHTTP3_FRAME_GOAWAY,
.id = conn->server ? NGHTTP3_SHUTDOWN_NOTICE_STREAM_ID
: NGHTTP3_SHUTDOWN_NOTICE_PUSH_ID,
};
assert(frent.fr.goaway.id <= conn->tx.goaway_id);
@@ -2588,13 +2615,12 @@ int nghttp3_conn_shutdown(nghttp3_conn *conn) {
assert(conn->tx.ctrl);
frent.fr.type = NGHTTP3_FRAME_GOAWAY;
if (conn->server) {
frent.fr.goaway.id =
nghttp3_min_int64((1ll << 62) - 4, conn->rx.max_stream_id_bidi + 4);
} else {
frent.fr.goaway.id = 0;
}
frent.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(frent.fr.goaway.id <= conn->tx.goaway_id);
@@ -2869,10 +2895,12 @@ int nghttp3_conn_set_client_stream_priority(nghttp3_conn *conn,
memcpy(buf, data, datalen);
}
frent.fr.type = NGHTTP3_FRAME_PRIORITY_UPDATE;
frent.fr.priority_update.pri_elem_id = stream_id;
frent.fr.priority_update.data = buf;
frent.fr.priority_update.datalen = datalen;
frent.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, &frent);
}
+1 -1
View File
@@ -121,7 +121,7 @@ struct nghttp3_conn {
use only. */
size_t num_streams;
} bidi;
nghttp3_settings settings;
nghttp3_proto_settings settings;
} remote;
struct {
+15 -15
View File
@@ -32,33 +32,33 @@
#include "nghttp3_unreachable.h"
const uint8_t *nghttp3_get_varint(int64_t *dest, const uint8_t *p) {
union {
uint8_t n8;
uint16_t n16;
uint32_t n32;
uint64_t n64;
} n;
uint16_t n16;
uint32_t n32;
uint64_t n64;
switch (*p >> 6) {
case 0:
*dest = *p++;
return p;
case 1:
memcpy(&n, p, 2);
n.n8 &= 0x3f;
*dest = ntohs(n.n16);
memcpy(&n16, p, 2);
n16 = ntohs(n16);
n16 &= 0x3fff;
*dest = n16;
return p + 2;
case 2:
memcpy(&n, p, 4);
n.n8 &= 0x3f;
*dest = ntohl(n.n32);
memcpy(&n32, p, 4);
n32 = ntohl(n32);
n32 &= 0x3fffffff;
*dest = n32;
return p + 4;
case 3:
memcpy(&n, p, 8);
n.n8 &= 0x3f;
*dest = (int64_t)nghttp3_ntohl64(n.n64);
memcpy(&n64, p, 8);
n64 = nghttp3_ntohl64(n64);
n64 &= 0x3fffffffffffffff;
*dest = (int64_t)n64;
return p + 8;
default:
+11 -3
View File
@@ -54,6 +54,10 @@
#define NGHTTP3_H2_FRAME_WINDOW_UPDATE 0x08
#define NGHTTP3_H2_FRAME_CONTINUATION 0x9
typedef struct nghttp3_frame_hd {
int64_t type;
} nghttp3_frame_hd;
typedef struct nghttp3_frame_data {
int64_t type;
} nghttp3_frame_data;
@@ -83,7 +87,7 @@ typedef struct nghttp3_settings_entry {
typedef struct nghttp3_frame_settings {
int64_t type;
size_t niv;
nghttp3_settings_entry iv[1];
nghttp3_settings_entry *iv;
} nghttp3_frame_settings;
typedef struct nghttp3_frame_goaway {
@@ -103,11 +107,15 @@ typedef struct nghttp3_frame_priority_update {
set to datalen. On reception, pri contains the decoded priority
header value. */
union {
nghttp3_pri pri;
/* Unnamed struct first, so that in unit test, it is
zero-initialized in the initialization without initializer,
which is convenient to pass nghttp3_frame to
nghttp3_write_frame test helper function. */
struct {
uint8_t *data;
size_t datalen;
};
nghttp3_pri pri;
};
} nghttp3_frame_priority_update;
@@ -119,7 +127,7 @@ typedef struct nghttp3_frame_origin {
} nghttp3_frame_origin;
typedef union nghttp3_frame {
int64_t type;
nghttp3_frame_hd hd;
nghttp3_frame_data data;
nghttp3_frame_headers headers;
nghttp3_frame_settings settings;
+16 -14
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) {
nghttp3_range range = {
.end = UINT64_MAX,
};
return nghttp3_ksl_insert(&gaptr->gap, NULL, &range, NULL);
return nghttp3_ksl_insert(&gaptr->gap, NULL,
&(nghttp3_range){
.end = UINT64_MAX,
},
NULL);
}
void nghttp3_gaptr_free(nghttp3_gaptr *gaptr) {
@@ -104,7 +104,7 @@ int nghttp3_gaptr_push(nghttp3_gaptr *gaptr, uint64_t offset,
return 0;
}
uint64_t nghttp3_gaptr_first_gap_offset(nghttp3_gaptr *gaptr) {
uint64_t nghttp3_gaptr_first_gap_offset(const nghttp3_gaptr *gaptr) {
nghttp3_ksl_it it;
if (nghttp3_ksl_len(&gaptr->gap) == 0) {
@@ -116,20 +116,22 @@ uint64_t nghttp3_gaptr_first_gap_offset(nghttp3_gaptr *gaptr) {
return ((nghttp3_range *)nghttp3_ksl_it_key(&it))->begin;
}
nghttp3_range nghttp3_gaptr_get_first_gap_after(nghttp3_gaptr *gaptr,
nghttp3_range nghttp3_gaptr_get_first_gap_after(const nghttp3_gaptr *gaptr,
uint64_t offset) {
nghttp3_range q = {
.begin = offset,
.end = offset + 1,
};
nghttp3_ksl_it it;
if (nghttp3_ksl_len(&gaptr->gap) == 0) {
nghttp3_range r = {0, UINT64_MAX};
nghttp3_range r = {
.end = UINT64_MAX,
};
return r;
}
it = nghttp3_ksl_lower_bound_search(&gaptr->gap, &q,
it = nghttp3_ksl_lower_bound_search(&gaptr->gap,
&(nghttp3_range){
.begin = offset,
.end = offset + 1,
},
nghttp3_ksl_range_exclusive_search);
assert(!nghttp3_ksl_it_end(&it));
@@ -137,7 +139,7 @@ nghttp3_range nghttp3_gaptr_get_first_gap_after(nghttp3_gaptr *gaptr,
return *(nghttp3_range *)nghttp3_ksl_it_key(&it);
}
int nghttp3_gaptr_is_pushed(nghttp3_gaptr *gaptr, uint64_t offset,
int nghttp3_gaptr_is_pushed(const nghttp3_gaptr *gaptr, uint64_t offset,
uint64_t datalen) {
nghttp3_range q = {
.begin = offset,
+3 -3
View File
@@ -73,20 +73,20 @@ int nghttp3_gaptr_push(nghttp3_gaptr *gaptr, uint64_t offset, uint64_t datalen);
* nghttp3_gaptr_first_gap_offset returns the offset to the first gap.
* If there is no gap, it returns UINT64_MAX.
*/
uint64_t nghttp3_gaptr_first_gap_offset(nghttp3_gaptr *gaptr);
uint64_t nghttp3_gaptr_first_gap_offset(const nghttp3_gaptr *gaptr);
/*
* nghttp3_gaptr_get_first_gap_after returns the first gap which
* includes or comes after |offset|.
*/
nghttp3_range nghttp3_gaptr_get_first_gap_after(nghttp3_gaptr *gaptr,
nghttp3_range nghttp3_gaptr_get_first_gap_after(const nghttp3_gaptr *gaptr,
uint64_t offset);
/*
* nghttp3_gaptr_is_pushed returns nonzero if range [offset, offset +
* datalen) is completely pushed into this object.
*/
int nghttp3_gaptr_is_pushed(nghttp3_gaptr *gaptr, uint64_t offset,
int nghttp3_gaptr_is_pushed(const nghttp3_gaptr *gaptr, uint64_t offset,
uint64_t datalen);
/*
+4 -4
View File
@@ -180,7 +180,7 @@ int nghttp3_pri_parse_priority_versioned(int pri_version, nghttp3_pri *dest,
return nghttp3_http_parse_priority(dest, value, valuelen);
}
static const char VALID_AUTHORITY_CHARS[256] = {
static const int8_t VALID_AUTHORITY_CHARS[256] = {
['!'] = 1, ['$'] = 1, ['%'] = 1, ['&'] = 1, ['\''] = 1, ['('] = 1, [')'] = 1,
['*'] = 1, ['+'] = 1, [','] = 1, ['-'] = 1, ['.'] = 1, ['0'] = 1, ['1'] = 1,
['2'] = 1, ['3'] = 1, ['4'] = 1, ['5'] = 1, ['6'] = 1, ['7'] = 1, ['8'] = 1,
@@ -229,7 +229,7 @@ static int check_scheme(const uint8_t *value, size_t len) {
return 1;
}
static const char VALID_METHOD_CHARS[256] = {
static const int8_t VALID_METHOD_CHARS[256] = {
['!'] = 1, ['#'] = 1, ['$'] = 1, ['%'] = 1, ['&'] = 1, ['\''] = 1, ['*'] = 1,
['+'] = 1, ['-'] = 1, ['.'] = 1, ['0'] = 1, ['1'] = 1, ['2'] = 1, ['3'] = 1,
['4'] = 1, ['5'] = 1, ['6'] = 1, ['7'] = 1, ['8'] = 1, ['9'] = 1, ['A'] = 1,
@@ -256,7 +256,7 @@ static int check_method(const uint8_t *value, size_t len) {
return 1;
}
static const char VALID_PATH_CHARS[256] = {
static const int8_t VALID_PATH_CHARS[256] = {
['!'] = 1, ['"'] = 1, ['#'] = 1, ['$'] = 1, ['%'] = 1, ['&'] = 1,
['\''] = 1, ['('] = 1, [')'] = 1, ['*'] = 1, ['+'] = 1, [','] = 1,
['-'] = 1, ['.'] = 1, ['/'] = 1, ['0'] = 1, ['1'] = 1, ['2'] = 1,
@@ -714,7 +714,7 @@ static int http_check_nonempty_header_name(const uint8_t *name, size_t len) {
return 1;
}
static const char VALID_HD_VALUE_CHARS[256] = {
static const int8_t VALID_HD_VALUE_CHARS[256] = {
[0x09] = 1, [' '] = 1, ['!'] = 1, ['"'] = 1, ['#'] = 1, ['$'] = 1,
['%'] = 1, ['&'] = 1, ['\''] = 1, ['('] = 1, [')'] = 1, ['*'] = 1,
['+'] = 1, [','] = 1, ['-'] = 1, ['.'] = 1, ['/'] = 1, ['0'] = 1,
+1 -1
View File
@@ -58,7 +58,7 @@ int nghttp3_idtr_open(nghttp3_idtr *idtr, int64_t stream_id) {
return nghttp3_gaptr_push(&idtr->gap, q, 1);
}
int nghttp3_idtr_is_open(nghttp3_idtr *idtr, int64_t stream_id) {
int nghttp3_idtr_is_open(const nghttp3_idtr *idtr, int64_t stream_id) {
uint64_t q;
q = id_from_stream_id(stream_id);
+1 -1
View File
@@ -72,6 +72,6 @@ int nghttp3_idtr_open(nghttp3_idtr *idtr, int64_t stream_id);
/*
* nghttp3_idtr_open returns nonzero if |stream_id| is in use.
*/
int nghttp3_idtr_is_open(nghttp3_idtr *idtr, int64_t stream_id);
int nghttp3_idtr_is_open(const nghttp3_idtr *idtr, int64_t stream_id);
#endif /* !defined(NGHTTP3_IDTR_H) */
+11 -4
View File
@@ -39,8 +39,7 @@ static nghttp3_ksl_blk null_blk;
nghttp3_objalloc_def(ksl_blk, nghttp3_ksl_blk, oplent)
static size_t ksl_blklen(size_t aligned_keylen) {
return sizeof(nghttp3_ksl_blk) + NGHTTP3_KSL_MAX_NBLK * aligned_keylen -
sizeof(uint64_t);
return sizeof(nghttp3_ksl_blk) + NGHTTP3_KSL_MAX_NBLK * aligned_keylen;
}
/*
@@ -74,8 +73,16 @@ void nghttp3_ksl_init(nghttp3_ksl *ksl, nghttp3_ksl_compar compar,
}
static nghttp3_ksl_blk *ksl_blk_objalloc_new(nghttp3_ksl *ksl) {
return nghttp3_objalloc_ksl_blk_len_get(&ksl->blkalloc,
ksl_blklen(ksl->aligned_keylen));
nghttp3_ksl_blk *blk = nghttp3_objalloc_ksl_blk_len_get(
&ksl->blkalloc, ksl_blklen(ksl->aligned_keylen));
if (!blk) {
return NULL;
}
blk->keys = (uint8_t *)blk + sizeof(*blk);
return blk;
}
static void ksl_blk_objalloc_del(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk) {
+5 -8
View File
@@ -81,14 +81,11 @@ struct nghttp3_ksl_blk {
/* leaf is nonzero if this block contains leaf nodes. */
uint32_t leaf;
nghttp3_ksl_node nodes[NGHTTP3_KSL_MAX_NBLK];
union {
uint64_t align;
/* keys is a buffer to include NGHTTP3_KSL_MAX_NBLK keys.
Because the length of key is unknown until nghttp3_ksl_init
is called, the actual buffer will be allocated after this
field. */
uint8_t keys[1];
};
/* keys is a pointer to the buffer to include
NGHTTP3_KSL_MAX_NBLK keys. Because the length of key is
unknown until nghttp3_ksl_init is called, the actual buffer
will be allocated after this field. */
uint8_t *keys;
};
nghttp3_opl_entry oplent;
+15 -7
View File
@@ -27,18 +27,22 @@
#include "nghttp3_macro.h"
void nghttp3_range_init(nghttp3_range *r, uint64_t begin, uint64_t end) {
r->begin = begin;
r->end = end;
*r = (nghttp3_range){
.begin = begin,
.end = end,
};
}
nghttp3_range nghttp3_range_intersect(const nghttp3_range *a,
const nghttp3_range *b) {
nghttp3_range r = {0};
nghttp3_range r;
uint64_t begin = nghttp3_max_uint64(a->begin, b->begin);
uint64_t end = nghttp3_min_uint64(a->end, b->end);
if (begin < end) {
nghttp3_range_init(&r, begin, end);
} else {
r = (nghttp3_range){0};
}
return r;
@@ -53,10 +57,14 @@ int nghttp3_range_eq(const nghttp3_range *a, const nghttp3_range *b) {
void nghttp3_range_cut(nghttp3_range *left, nghttp3_range *right,
const nghttp3_range *a, const nghttp3_range *b) {
/* Assume that b is included in a */
left->begin = a->begin;
left->end = b->begin;
right->begin = b->end;
right->end = a->end;
*left = (nghttp3_range){
.begin = a->begin,
.end = b->begin,
};
*right = (nghttp3_range){
.begin = b->end,
.end = a->end,
};
}
int nghttp3_range_not_after(const nghttp3_range *a, const nghttp3_range *b) {
+44 -42
View File
@@ -141,7 +141,7 @@ static void delete_frq(nghttp3_ringbuf *frq, const nghttp3_mem *mem) {
for (i = 0; i < len; ++i) {
frent = nghttp3_ringbuf_get(frq, i);
switch (frent->fr.type) {
switch (frent->fr.hd.type) {
case NGHTTP3_FRAME_HEADERS:
nghttp3_frame_headers_free(&frent->fr.headers, mem);
break;
@@ -254,7 +254,7 @@ int nghttp3_stream_fill_outq(nghttp3_stream *stream) {
stream->unsent_bytes < NGHTTP3_MIN_UNSENT_BYTES;) {
frent = nghttp3_ringbuf_get(frq, 0);
switch (frent->fr.type) {
switch (frent->fr.hd.type) {
case NGHTTP3_FRAME_SETTINGS:
rv = nghttp3_stream_write_settings(stream, frent);
if (rv != 0) {
@@ -338,44 +338,47 @@ int nghttp3_stream_write_settings(nghttp3_stream *stream,
int rv;
nghttp3_buf *chunk;
nghttp3_typed_buf tbuf;
struct {
nghttp3_frame_settings settings;
nghttp3_settings_entry iv[15];
} fr = {
.settings =
{
.type = NGHTTP3_FRAME_SETTINGS,
.niv = 3,
},
nghttp3_settings_entry ents[16];
nghttp3_frame_settings fr = {
.type = NGHTTP3_FRAME_SETTINGS,
.niv = 3,
.iv = ents,
};
nghttp3_settings_entry *iv;
nghttp3_settings *local_settings = frent->aux.settings.local_settings;
int64_t payloadlen;
iv = &fr.settings.iv[0];
iv[0].id = NGHTTP3_SETTINGS_ID_MAX_FIELD_SECTION_SIZE;
iv[0].value = local_settings->max_field_section_size;
iv[1].id = NGHTTP3_SETTINGS_ID_QPACK_MAX_TABLE_CAPACITY;
iv[1].value = local_settings->qpack_max_dtable_capacity;
iv[2].id = NGHTTP3_SETTINGS_ID_QPACK_BLOCKED_STREAMS;
iv[2].value = local_settings->qpack_blocked_streams;
ents[0] = (nghttp3_settings_entry){
.id = NGHTTP3_SETTINGS_ID_MAX_FIELD_SECTION_SIZE,
.value = local_settings->max_field_section_size,
};
ents[1] = (nghttp3_settings_entry){
.id = NGHTTP3_SETTINGS_ID_QPACK_MAX_TABLE_CAPACITY,
.value = local_settings->qpack_max_dtable_capacity,
};
ents[2] = (nghttp3_settings_entry){
.id = NGHTTP3_SETTINGS_ID_QPACK_BLOCKED_STREAMS,
.value = local_settings->qpack_blocked_streams,
};
if (local_settings->h3_datagram) {
iv[fr.settings.niv].id = NGHTTP3_SETTINGS_ID_H3_DATAGRAM;
iv[fr.settings.niv].value = 1;
ents[fr.niv] = (nghttp3_settings_entry){
.id = NGHTTP3_SETTINGS_ID_H3_DATAGRAM,
.value = 1,
};
++fr.settings.niv;
++fr.niv;
}
if (local_settings->enable_connect_protocol) {
iv[fr.settings.niv].id = NGHTTP3_SETTINGS_ID_ENABLE_CONNECT_PROTOCOL;
iv[fr.settings.niv].value = 1;
ents[fr.niv] = (nghttp3_settings_entry){
.id = NGHTTP3_SETTINGS_ID_ENABLE_CONNECT_PROTOCOL,
.value = 1,
};
++fr.settings.niv;
++fr.niv;
}
len = nghttp3_frame_write_settings_len(&payloadlen, &fr.settings);
len = nghttp3_frame_write_settings_len(&payloadlen, &fr);
rv = nghttp3_stream_ensure_chunk(stream, len);
if (rv != 0) {
@@ -385,8 +388,7 @@ int nghttp3_stream_write_settings(nghttp3_stream *stream,
chunk = nghttp3_stream_get_chunk(stream);
nghttp3_typed_buf_shared_init(&tbuf, chunk);
chunk->last =
nghttp3_frame_write_settings(chunk->last, &fr.settings, payloadlen);
chunk->last = nghttp3_frame_write_settings(chunk->last, &fr, payloadlen);
tbuf.buf.last = chunk->last;
@@ -691,19 +693,19 @@ int nghttp3_stream_write_data(nghttp3_stream *stream, int *peof,
return rv;
}
if (datalen) {
for (i = 0; i < (size_t)sveccnt; ++i) {
v = &vec[i];
if (v->len == 0) {
continue;
}
nghttp3_buf_wrap_init(&buf, v->base, v->len);
buf.last = buf.end;
nghttp3_typed_buf_init(&tbuf, &buf, NGHTTP3_BUF_TYPE_ALIEN);
rv = nghttp3_stream_outq_add(stream, &tbuf);
if (rv != 0) {
return rv;
}
assert(datalen);
for (i = 0; i < (size_t)sveccnt; ++i) {
v = &vec[i];
if (v->len == 0) {
continue;
}
nghttp3_buf_wrap_init(&buf, v->base, v->len);
buf.last = buf.end;
nghttp3_typed_buf_init(&tbuf, &buf, NGHTTP3_BUF_TYPE_ALIEN);
rv = nghttp3_stream_outq_add(stream, &tbuf);
if (rv != 0) {
return rv;
}
}
+1 -1
View File
@@ -89,6 +89,7 @@ typedef struct nghttp3_varint_read_state {
typedef struct nghttp3_stream_read_state {
nghttp3_varint_read_state rvint;
nghttp3_settings_entry iv;
nghttp3_frame fr;
int64_t left;
int state;
@@ -229,7 +230,6 @@ struct nghttp3_stream {
struct {
uint64_t offset;
nghttp3_stream_http_state hstate;
} tx;
struct {
+5 -5
View File
@@ -32,11 +32,11 @@
#include "nghttp3_conv.h"
void nghttp3_tnode_init(nghttp3_tnode *tnode, int64_t id) {
tnode->pe.index = NGHTTP3_PQ_BAD_INDEX;
tnode->id = id;
tnode->cycle = 0;
tnode->pri.urgency = NGHTTP3_DEFAULT_URGENCY;
tnode->pri.inc = 0;
*tnode = (nghttp3_tnode){
.pe.index = NGHTTP3_PQ_BAD_INDEX,
.id = id,
.pri.urgency = NGHTTP3_DEFAULT_URGENCY,
};
}
void nghttp3_tnode_free(nghttp3_tnode *tnode) { (void)tnode; }
-1
View File
@@ -37,7 +37,6 @@
typedef struct nghttp3_tnode {
nghttp3_pq_entry pe;
size_t num_children;
int64_t id;
uint64_t cycle;
/* pri is a stream priority produced by nghttp3_pri_to_uint8. */
+11 -8
View File
@@ -27,20 +27,22 @@
#include <stdio.h>
#include <errno.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* defined(HAVE_UNISTD_H) */
#include <stdlib.h>
#ifdef WIN32
#ifdef HAVE_UNISTD_H
# define NGHTTP3_UNREACHABLE_LOG
# include <unistd.h>
#elif defined(WIN32)
# define NGHTTP3_UNREACHABLE_LOG
# include <io.h>
#endif /* defined(WIN32) */
void nghttp3_unreachable_fail(const char *file, int line, const char *func) {
#ifdef NGHTTP3_UNREACHABLE_LOG
char *buf;
size_t buflen;
int rv;
#define NGHTTP3_UNREACHABLE_TEMPLATE "%s:%d %s: Unreachable.\n"
# define NGHTTP3_UNREACHABLE_TEMPLATE "%s:%d %s: Unreachable.\n"
rv = snprintf(NULL, 0, NGHTTP3_UNREACHABLE_TEMPLATE, file, line, func);
if (rv < 0) {
@@ -59,14 +61,15 @@ void nghttp3_unreachable_fail(const char *file, int line, const char *func) {
abort();
}
#ifndef WIN32
# ifndef WIN32
while (write(STDERR_FILENO, buf, (size_t)rv) == -1 && errno == EINTR)
;
#else /* defined(WIN32) */
# else /* defined(WIN32) */
_write(_fileno(stderr), buf, (unsigned int)rv);
#endif /* defined(WIN32) */
# endif /* defined(WIN32) */
free(buf);
#endif /* defined(NGHTTP3_UNREACHABLE_LOG) */
abort();
}
+142 -413
View File
@@ -71,312 +71,31 @@
#define SFPARSE_STATE_INITIAL 0x00u
#define DIGIT_CASES \
case '0': \
case '1': \
case '2': \
case '3': \
case '4': \
case '5': \
case '6': \
case '7': \
case '8': \
case '9'
#define LCALPHAS \
['a'] = 1, ['b'] = 1, ['c'] = 1, ['d'] = 1, ['e'] = 1, ['f'] = 1, ['g'] = 1, \
['h'] = 1, ['i'] = 1, ['j'] = 1, ['k'] = 1, ['l'] = 1, ['m'] = 1, ['n'] = 1, \
['o'] = 1, ['p'] = 1, ['q'] = 1, ['r'] = 1, ['s'] = 1, ['t'] = 1, ['u'] = 1, \
['v'] = 1, ['w'] = 1, ['x'] = 1, ['y'] = 1, ['z'] = 1
#define LCALPHA_CASES \
case 'a': \
case 'b': \
case 'c': \
case 'd': \
case 'e': \
case 'f': \
case 'g': \
case 'h': \
case 'i': \
case 'j': \
case 'k': \
case 'l': \
case 'm': \
case 'n': \
case 'o': \
case 'p': \
case 'q': \
case 'r': \
case 's': \
case 't': \
case 'u': \
case 'v': \
case 'w': \
case 'x': \
case 'y': \
case 'z'
#define ALPHAS(N) \
['A'] = (N), ['B'] = (N), ['C'] = (N), ['D'] = (N), ['E'] = (N), \
['F'] = (N), ['G'] = (N), ['H'] = (N), ['I'] = (N), ['J'] = (N), \
['K'] = (N), ['L'] = (N), ['M'] = (N), ['N'] = (N), ['O'] = (N), \
['P'] = (N), ['Q'] = (N), ['R'] = (N), ['S'] = (N), ['T'] = (N), \
['U'] = (N), ['V'] = (N), ['W'] = (N), ['X'] = (N), ['Y'] = (N), \
['Z'] = (N), ['a'] = (N), ['b'] = (N), ['c'] = (N), ['d'] = (N), \
['e'] = (N), ['f'] = (N), ['g'] = (N), ['h'] = (N), ['i'] = (N), \
['j'] = (N), ['k'] = (N), ['l'] = (N), ['m'] = (N), ['n'] = (N), \
['o'] = (N), ['p'] = (N), ['q'] = (N), ['r'] = (N), ['s'] = (N), \
['t'] = (N), ['u'] = (N), ['v'] = (N), ['w'] = (N), ['x'] = (N), \
['y'] = (N), ['z'] = (N)
#define UCALPHA_CASES \
case 'A': \
case 'B': \
case 'C': \
case 'D': \
case 'E': \
case 'F': \
case 'G': \
case 'H': \
case 'I': \
case 'J': \
case 'K': \
case 'L': \
case 'M': \
case 'N': \
case 'O': \
case 'P': \
case 'Q': \
case 'R': \
case 'S': \
case 'T': \
case 'U': \
case 'V': \
case 'W': \
case 'X': \
case 'Y': \
case 'Z'
#define DIGITS(N) \
['0'] = (N), ['1'] = (N), ['2'] = (N), ['3'] = (N), ['4'] = (N), \
['5'] = (N), ['6'] = (N), ['7'] = (N), ['8'] = (N), ['9'] = (N)
#define ALPHA_CASES \
UCALPHA_CASES: \
LCALPHA_CASES
#define TOKEN_CASES \
case '!': \
case '#': \
case '$': \
case '%': \
case '&': \
case '\'': \
case '*': \
case '+': \
case '-': \
case '.': \
case '/': \
DIGIT_CASES: \
case ':': \
UCALPHA_CASES: \
case '^': \
case '_': \
case '`': \
LCALPHA_CASES: \
case '|': \
case '~'
#define LCHEXALPHA_CASES \
case 'a': \
case 'b': \
case 'c': \
case 'd': \
case 'e': \
case 'f'
#define X00_1F_CASES \
case 0x00: \
case 0x01: \
case 0x02: \
case 0x03: \
case 0x04: \
case 0x05: \
case 0x06: \
case 0x07: \
case 0x08: \
case 0x09: \
case 0x0a: \
case 0x0b: \
case 0x0c: \
case 0x0d: \
case 0x0e: \
case 0x0f: \
case 0x10: \
case 0x11: \
case 0x12: \
case 0x13: \
case 0x14: \
case 0x15: \
case 0x16: \
case 0x17: \
case 0x18: \
case 0x19: \
case 0x1a: \
case 0x1b: \
case 0x1c: \
case 0x1d: \
case 0x1e: \
case 0x1f
#define X20_21_CASES \
case ' ': \
case '!'
#define X23_5B_CASES \
case '#': \
case '$': \
case '%': \
case '&': \
case '\'': \
case '(': \
case ')': \
case '*': \
case '+': \
case ',': \
case '-': \
case '.': \
case '/': \
DIGIT_CASES: \
case ':': \
case ';': \
case '<': \
case '=': \
case '>': \
case '?': \
case '@': \
UCALPHA_CASES: \
case '['
#define X5D_7E_CASES \
case ']': \
case '^': \
case '_': \
case '`': \
LCALPHA_CASES: \
case '{': \
case '|': \
case '}': \
case '~'
#define X7F_FF_CASES \
case 0x7f: \
case 0x80: \
case 0x81: \
case 0x82: \
case 0x83: \
case 0x84: \
case 0x85: \
case 0x86: \
case 0x87: \
case 0x88: \
case 0x89: \
case 0x8a: \
case 0x8b: \
case 0x8c: \
case 0x8d: \
case 0x8e: \
case 0x8f: \
case 0x90: \
case 0x91: \
case 0x92: \
case 0x93: \
case 0x94: \
case 0x95: \
case 0x96: \
case 0x97: \
case 0x98: \
case 0x99: \
case 0x9a: \
case 0x9b: \
case 0x9c: \
case 0x9d: \
case 0x9e: \
case 0x9f: \
case 0xa0: \
case 0xa1: \
case 0xa2: \
case 0xa3: \
case 0xa4: \
case 0xa5: \
case 0xa6: \
case 0xa7: \
case 0xa8: \
case 0xa9: \
case 0xaa: \
case 0xab: \
case 0xac: \
case 0xad: \
case 0xae: \
case 0xaf: \
case 0xb0: \
case 0xb1: \
case 0xb2: \
case 0xb3: \
case 0xb4: \
case 0xb5: \
case 0xb6: \
case 0xb7: \
case 0xb8: \
case 0xb9: \
case 0xba: \
case 0xbb: \
case 0xbc: \
case 0xbd: \
case 0xbe: \
case 0xbf: \
case 0xc0: \
case 0xc1: \
case 0xc2: \
case 0xc3: \
case 0xc4: \
case 0xc5: \
case 0xc6: \
case 0xc7: \
case 0xc8: \
case 0xc9: \
case 0xca: \
case 0xcb: \
case 0xcc: \
case 0xcd: \
case 0xce: \
case 0xcf: \
case 0xd0: \
case 0xd1: \
case 0xd2: \
case 0xd3: \
case 0xd4: \
case 0xd5: \
case 0xd6: \
case 0xd7: \
case 0xd8: \
case 0xd9: \
case 0xda: \
case 0xdb: \
case 0xdc: \
case 0xdd: \
case 0xde: \
case 0xdf: \
case 0xe0: \
case 0xe1: \
case 0xe2: \
case 0xe3: \
case 0xe4: \
case 0xe5: \
case 0xe6: \
case 0xe7: \
case 0xe8: \
case 0xe9: \
case 0xea: \
case 0xeb: \
case 0xec: \
case 0xed: \
case 0xee: \
case 0xef: \
case 0xf0: \
case 0xf1: \
case 0xf2: \
case 0xf3: \
case 0xf4: \
case 0xf5: \
case 0xf6: \
case 0xf7: \
case 0xf8: \
case 0xf9: \
case 0xfa: \
case 0xfb: \
case 0xfc: \
case 0xfd: \
case 0xfe: \
case 0xff
#define HEXALPHAS(N) \
['a'] = (N), ['b'] = (N), ['c'] = (N), ['d'] = (N), ['e'] = (N), ['f'] = (N)
static int is_ws(uint8_t c) {
switch (c) {
@@ -463,17 +182,17 @@ static const uint8_t *find_char_key(const uint8_t *first, const uint8_t *last) {
}
#endif /* __AVX2__ */
static const uint8_t key_tbl[256] = {
['*'] = 1, LCALPHAS, ['_'] = 2, ['-'] = 2, ['.'] = 2, DIGITS(2),
};
static int parser_key(sfparse_parser *sfp, sfparse_vec *dest) {
const uint8_t *base;
#ifdef __AVX2__
const uint8_t *last;
#endif /* __AVX2__ */
switch (*sfp->pos) {
case '*':
LCALPHA_CASES:
break;
default:
if (key_tbl[*sfp->pos] != 1) {
return SFPARSE_ERR_PARSE;
}
@@ -490,19 +209,8 @@ static int parser_key(sfparse_parser *sfp, sfparse_vec *dest) {
}
#endif /* __AVX2__ */
for (; !parser_eof(sfp); ++sfp->pos) {
switch (*sfp->pos) {
case '_':
case '-':
case '.':
case '*':
DIGIT_CASES:
LCALPHA_CASES:
continue;
}
break;
}
for (; !parser_eof(sfp) && key_tbl[*sfp->pos]; ++sfp->pos)
;
#ifdef __AVX2__
fin:
@@ -515,6 +223,10 @@ fin:
return 0;
}
static const uint8_t number_tbl[256] = {
DIGITS(1),
};
static int parser_number(sfparse_parser *sfp, sfparse_value *dest) {
int sign = 1;
int64_t value = 0;
@@ -532,20 +244,13 @@ static int parser_number(sfparse_parser *sfp, sfparse_value *dest) {
assert(!parser_eof(sfp));
for (; !parser_eof(sfp); ++sfp->pos) {
switch (*sfp->pos) {
DIGIT_CASES:
if (++len > 15) {
return SFPARSE_ERR_PARSE;
}
value *= 10;
value += *sfp->pos - '0';
continue;
for (; !parser_eof(sfp) && number_tbl[*sfp->pos]; ++sfp->pos) {
if (++len > 15) {
return SFPARSE_ERR_PARSE;
}
break;
value *= 10;
value += *sfp->pos - '0';
}
if (len == 0) {
@@ -572,20 +277,13 @@ static int parser_number(sfparse_parser *sfp, sfparse_value *dest) {
++sfp->pos;
for (; !parser_eof(sfp); ++sfp->pos) {
switch (*sfp->pos) {
DIGIT_CASES:
if (++len > 15) {
return SFPARSE_ERR_PARSE;
}
value *= 10;
value += *sfp->pos - '0';
continue;
for (; !parser_eof(sfp) && number_tbl[*sfp->pos]; ++sfp->pos) {
if (++len > 15) {
return SFPARSE_ERR_PARSE;
}
break;
value *= 10;
value += *sfp->pos - '0';
}
if (fpos == len || len - fpos > 3) {
@@ -674,6 +372,14 @@ static const uint8_t *find_char_string(const uint8_t *first,
}
#endif /* __AVX2__ */
static const uint8_t string_tbl[256] = {
[' '] = 1, ['!'] = 1, ['#'] = 1, ['$'] = 1, ['%'] = 1, ['&'] = 1, ['\''] = 1,
['('] = 1, [')'] = 1, ['*'] = 1, ['+'] = 1, [','] = 1, ['-'] = 1, ['.'] = 1,
['/'] = 1, DIGITS(1), [':'] = 1, [';'] = 1, ['<'] = 1, ['='] = 1, ['>'] = 1,
['?'] = 1, ['@'] = 1, ALPHAS(1), ['['] = 1, [']'] = 1, ['^'] = 1, ['_'] = 1,
['`'] = 1, ['{'] = 1, ['|'] = 1, ['}'] = 1, ['~'] = 1, ['\\'] = 2, ['"'] = 3,
};
static int parser_string(sfparse_parser *sfp, sfparse_value *dest) {
const uint8_t *base;
#ifdef __AVX2__
@@ -722,12 +428,12 @@ static int parser_string(sfparse_parser *sfp, sfparse_value *dest) {
#endif /* __AVX2__ */
for (; !parser_eof(sfp); ++sfp->pos) {
switch (*sfp->pos) {
X20_21_CASES:
X23_5B_CASES:
X5D_7E_CASES:
switch (string_tbl[*sfp->pos]) {
case 0:
return SFPARSE_ERR_PARSE;
case 1:
break;
case '\\':
case 2:
++sfp->pos;
if (parser_eof(sfp)) {
return SFPARSE_ERR_PARSE;
@@ -744,10 +450,8 @@ static int parser_string(sfparse_parser *sfp, sfparse_value *dest) {
}
break;
case '"':
case 3:
goto fin;
default:
return SFPARSE_ERR_PARSE;
}
}
@@ -820,6 +524,12 @@ static const uint8_t *find_char_token(const uint8_t *first,
}
#endif /* __AVX2__ */
static const uint8_t token_tbl[256] = {
['!'] = 1, ['#'] = 1, ['$'] = 1, ['%'] = 1, ['&'] = 1, ['\''] = 1, ['*'] = 1,
['+'] = 1, ['-'] = 1, ['.'] = 1, ['/'] = 1, DIGITS(1), [':'] = 1, ALPHAS(1),
['^'] = 1, ['_'] = 1, ['`'] = 1, ['|'] = 1, ['~'] = 1,
};
static int parser_token(sfparse_parser *sfp, sfparse_value *dest) {
const uint8_t *base;
#ifdef __AVX2__
@@ -840,14 +550,8 @@ static int parser_token(sfparse_parser *sfp, sfparse_value *dest) {
}
#endif /* __AVX2__ */
for (; !parser_eof(sfp); ++sfp->pos) {
switch (*sfp->pos) {
TOKEN_CASES:
continue;
}
break;
}
for (; !parser_eof(sfp) && token_tbl[*sfp->pos]; ++sfp->pos)
;
#ifdef __AVX2__
fin:
@@ -901,6 +605,10 @@ static const uint8_t *find_char_byteseq(const uint8_t *first,
}
#endif /* __AVX2__ */
static const uint8_t byteseq_tbl[256] = {
['+'] = 1, ['/'] = 1, DIGITS(1), ALPHAS(1), ['='] = 2, [':'] = 3,
};
static int parser_byteseq(sfparse_parser *sfp, sfparse_value *dest) {
const uint8_t *base;
#ifdef __AVX2__
@@ -920,13 +628,12 @@ static int parser_byteseq(sfparse_parser *sfp, sfparse_value *dest) {
#endif /* __AVX2__ */
for (; !parser_eof(sfp); ++sfp->pos) {
switch (*sfp->pos) {
case '+':
case '/':
DIGIT_CASES:
ALPHA_CASES:
switch (byteseq_tbl[*sfp->pos]) {
case 0:
return SFPARSE_ERR_PARSE;
case 1:
continue;
case '=':
case 2:
switch ((sfp->pos - base) & 0x3) {
case 0:
case 1:
@@ -954,14 +661,12 @@ static int parser_byteseq(sfparse_parser *sfp, sfparse_value *dest) {
}
goto fin;
case ':':
case 3:
if (((sfp->pos - base) & 0x3) == 1) {
return SFPARSE_ERR_PARSE;
}
goto fin;
default:
return SFPARSE_ERR_PARSE;
}
}
@@ -1016,35 +721,43 @@ static int parser_boolean(sfparse_parser *sfp, sfparse_value *dest) {
return 0;
}
static const uint8_t pct_tbl[256] = {
DIGITS(1),
HEXALPHAS(2),
};
static int pctdecode(uint8_t *pc, const uint8_t **ppos) {
uint8_t c, b = **ppos;
switch (b) {
DIGIT_CASES:
switch (pct_tbl[b]) {
case 0:
return -1;
case 1:
c = (uint8_t)((b - '0') << 4);
break;
LCHEXALPHA_CASES:
case 2:
c = (uint8_t)((b - 'a' + 10) << 4);
break;
default:
return -1;
assert(0);
abort();
}
b = *++*ppos;
switch (b) {
DIGIT_CASES:
switch (pct_tbl[b]) {
case 0:
return -1;
case 1:
c |= (uint8_t)(b - '0');
break;
LCHEXALPHA_CASES:
case 2:
c |= (uint8_t)(b - 'a' + 10);
break;
default:
return -1;
}
*pc = c;
@@ -1115,6 +828,14 @@ static void utf8_decode(uint32_t *state, uint8_t byte) {
/* End of utf8 dfa */
static const uint8_t dispstring_tbl[256] = {
[' '] = 1, ['!'] = 1, ['#'] = 1, ['$'] = 1, ['&'] = 1, ['\''] = 1, ['('] = 1,
[')'] = 1, ['*'] = 1, ['+'] = 1, [','] = 1, ['-'] = 1, ['.'] = 1, ['/'] = 1,
DIGITS(1), [':'] = 1, [';'] = 1, ['<'] = 1, ['='] = 1, ['>'] = 1, ['?'] = 1,
['@'] = 1, ALPHAS(1), ['['] = 1, ['\\'] = 1, [']'] = 1, ['^'] = 1, ['_'] = 1,
['`'] = 1, ['{'] = 1, ['|'] = 1, ['}'] = 1, ['~'] = 1, ['%'] = 2, ['"'] = 3,
};
static int parser_dispstring(sfparse_parser *sfp, sfparse_value *dest) {
const uint8_t *base;
uint8_t c;
@@ -1131,31 +852,39 @@ static int parser_dispstring(sfparse_parser *sfp, sfparse_value *dest) {
base = ++sfp->pos;
for (; !parser_eof(sfp);) {
switch (*sfp->pos) {
X00_1F_CASES:
X7F_FF_CASES:
switch (dispstring_tbl[*sfp->pos]) {
case 0:
return SFPARSE_ERR_PARSE;
case '%':
case 1:
++sfp->pos;
if (sfp->pos + 2 > sfp->end) {
return SFPARSE_ERR_PARSE;
}
break;
case 2:
for (;;) {
++sfp->pos;
if (pctdecode(&c, &sfp->pos) != 0) {
return SFPARSE_ERR_PARSE;
}
if (sfp->pos + 2 > sfp->end || pctdecode(&c, &sfp->pos) != 0) {
return SFPARSE_ERR_PARSE;
}
utf8_decode(&utf8state, c);
if (utf8state == UTF8_REJECT) {
return SFPARSE_ERR_PARSE;
utf8_decode(&utf8state, c);
if (utf8state == UTF8_ACCEPT) {
if (sfp->pos != sfp->end && *sfp->pos == '%') {
continue;
}
break;
}
if (utf8state == UTF8_REJECT || sfp->pos + 1 > sfp->end ||
*sfp->pos != '%') {
return SFPARSE_ERR_PARSE;
}
}
break;
case '"':
if (utf8state != UTF8_ACCEPT) {
return SFPARSE_ERR_PARSE;
}
case 3:
assert(utf8state == UTF8_ACCEPT);
if (dest) {
dest->type = SFPARSE_TYPE_DISPSTRING;
@@ -1167,38 +896,38 @@ static int parser_dispstring(sfparse_parser *sfp, sfparse_value *dest) {
++sfp->pos;
return 0;
default:
if (utf8state != UTF8_ACCEPT) {
return SFPARSE_ERR_PARSE;
}
++sfp->pos;
}
}
return SFPARSE_ERR_PARSE;
}
static const uint8_t bare_item_tbl[256] = {
['"'] = 1, ['-'] = 2, DIGITS(2), ['@'] = 3, [':'] = 4,
['?'] = 5, ['*'] = 6, ALPHAS(6), ['%'] = 7,
};
static int parser_bare_item(sfparse_parser *sfp, sfparse_value *dest) {
switch (*sfp->pos) {
case '"':
switch (bare_item_tbl[*sfp->pos]) {
case 0:
return SFPARSE_ERR_PARSE;
case 1:
return parser_string(sfp, dest);
case '-':
DIGIT_CASES:
case 2:
return parser_number(sfp, dest);
case '@':
case 3:
return parser_date(sfp, dest);
case ':':
case 4:
return parser_byteseq(sfp, dest);
case '?':
case 5:
return parser_boolean(sfp, dest);
case '*':
ALPHA_CASES:
case 6:
return parser_token(sfp, dest);
case '%':
case 7:
return parser_dispstring(sfp, dest);
default:
return SFPARSE_ERR_PARSE;
assert(0);
abort();
}
}
+2 -1
View File
@@ -983,7 +983,8 @@ class Http3ApplicationImpl final : public Session::Application {
on_receive_settings,
on_receive_origin,
on_end_origin,
on_rand};
on_rand,
nullptr};
};
std::unique_ptr<Session::Application> Http3Application::Create(