Eliminate _U_ macro

Instead use (void)VAR for better compiler compatibility.
This commit is contained in:
Tatsuhiro Tsujikawa 2017-03-11 17:46:39 +09:00
parent 3e0e3f5459
commit 85a12429ee
25 changed files with 485 additions and 289 deletions

View File

@ -110,19 +110,9 @@ foreach(_build_type "Release" "MinSizeRel" "RelWithDebInfo")
endforeach() endforeach()
endforeach() endforeach()
#
# If we're running GCC or clang define _U_ to be "__attribute__((unused))"
# so we can use _U_ to flag unused function parameters and not get warnings
# about them. Otherwise, define _U_ to be an empty string so that _U_ used
# to flag an unused function parameters will compile with other compilers.
#
# XXX - similar hints for other compilers?
#
if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
set(HINT_UNUSED_PARAM "__attribute__((unused))")
set(HINT_NORETURN "__attribute__((noreturn))") set(HINT_NORETURN "__attribute__((noreturn))")
else() else()
set(HINT_UNUSED_PARAM)
set(HINT_NORETURN) set(HINT_NORETURN)
endif() endif()

View File

@ -1,7 +1,3 @@
/* Hint to the compiler that a function parameter is not used */
#define _U_ @HINT_UNUSED_PARAM@
/* Hint to the compiler that a function never returns */ /* Hint to the compiler that a function never returns */
#define NGHTTP2_NORETURN @HINT_NORETURN@ #define NGHTTP2_NORETURN @HINT_NORETURN@

View File

@ -176,19 +176,9 @@ else
AC_SUBST([CYTHON]) AC_SUBST([CYTHON])
fi fi
#
# If we're running GCC or clang define _U_ to be "__attribute__((unused))"
# so we can use _U_ to flag unused function parameters and not get warnings
# about them. Otherwise, define _U_ to be an empty string so that _U_ used
# to flag an unused function parameters will compile with other compilers.
#
# XXX - similar hints for other compilers?
#
if test "x$GCC" = "xyes" -o "x$CC" = "xclang" ; then if test "x$GCC" = "xyes" -o "x$CC" = "xclang" ; then
AC_DEFINE([_U_], [__attribute__((unused))], [Hint to the compiler that a function parameters is not used])
AC_DEFINE([NGHTTP2_NORETURN], [__attribute__((noreturn))], [Hint to the compiler that a function never return]) AC_DEFINE([NGHTTP2_NORETURN], [__attribute__((noreturn))], [Hint to the compiler that a function never return])
else else
AC_DEFINE([_U_], , [Hint to the compiler that a function parameter is not used])
AC_DEFINE([NGHTTP2_NORETURN], , [Hint to the compiler that a function never return]) AC_DEFINE([NGHTTP2_NORETURN], , [Hint to the compiler that a function never return])
fi fi

View File

@ -159,10 +159,13 @@ static void diec(const char *func, int error_code) {
* bytes actually written. See the documentation of * bytes actually written. See the documentation of
* nghttp2_send_callback for the details. * nghttp2_send_callback for the details.
*/ */
static ssize_t send_callback(nghttp2_session *session _U_, const uint8_t *data, static ssize_t send_callback(nghttp2_session *session, const uint8_t *data,
size_t length, int flags _U_, void *user_data) { size_t length, int flags, void *user_data) {
struct Connection *connection; struct Connection *connection;
int rv; int rv;
(void)session;
(void)flags;
connection = (struct Connection *)user_data; connection = (struct Connection *)user_data;
connection->want_io = IO_NONE; connection->want_io = IO_NONE;
ERR_clear_error(); ERR_clear_error();
@ -186,10 +189,13 @@ static ssize_t send_callback(nghttp2_session *session _U_, const uint8_t *data,
* |length| bytes. Returns the number of bytes stored in |buf|. See * |length| bytes. Returns the number of bytes stored in |buf|. See
* the documentation of nghttp2_recv_callback for the details. * the documentation of nghttp2_recv_callback for the details.
*/ */
static ssize_t recv_callback(nghttp2_session *session _U_, uint8_t *buf, static ssize_t recv_callback(nghttp2_session *session, uint8_t *buf,
size_t length, int flags _U_, void *user_data) { size_t length, int flags, void *user_data) {
struct Connection *connection; struct Connection *connection;
int rv; int rv;
(void)session;
(void)flags;
connection = (struct Connection *)user_data; connection = (struct Connection *)user_data;
connection->want_io = IO_NONE; connection->want_io = IO_NONE;
ERR_clear_error(); ERR_clear_error();
@ -210,9 +216,10 @@ static ssize_t recv_callback(nghttp2_session *session _U_, uint8_t *buf,
} }
static int on_frame_send_callback(nghttp2_session *session, static int on_frame_send_callback(nghttp2_session *session,
const nghttp2_frame *frame, const nghttp2_frame *frame, void *user_data) {
void *user_data _U_) {
size_t i; size_t i;
(void)user_data;
switch (frame->hd.type) { switch (frame->hd.type) {
case NGHTTP2_HEADERS: case NGHTTP2_HEADERS:
if (nghttp2_session_get_stream_user_data(session, frame->hd.stream_id)) { if (nghttp2_session_get_stream_user_data(session, frame->hd.stream_id)) {
@ -237,9 +244,10 @@ static int on_frame_send_callback(nghttp2_session *session,
} }
static int on_frame_recv_callback(nghttp2_session *session, static int on_frame_recv_callback(nghttp2_session *session,
const nghttp2_frame *frame, const nghttp2_frame *frame, void *user_data) {
void *user_data _U_) {
size_t i; size_t i;
(void)user_data;
switch (frame->hd.type) { switch (frame->hd.type) {
case NGHTTP2_HEADERS: case NGHTTP2_HEADERS:
if (frame->headers.cat == NGHTTP2_HCAT_RESPONSE) { if (frame->headers.cat == NGHTTP2_HCAT_RESPONSE) {
@ -274,9 +282,11 @@ static int on_frame_recv_callback(nghttp2_session *session,
* we submit GOAWAY and close the session. * we submit GOAWAY and close the session.
*/ */
static int on_stream_close_callback(nghttp2_session *session, int32_t stream_id, static int on_stream_close_callback(nghttp2_session *session, int32_t stream_id,
uint32_t error_code _U_, uint32_t error_code, void *user_data) {
void *user_data _U_) {
struct Request *req; struct Request *req;
(void)error_code;
(void)user_data;
req = nghttp2_session_get_stream_user_data(session, stream_id); req = nghttp2_session_get_stream_user_data(session, stream_id);
if (req) { if (req) {
int rv; int rv;
@ -293,11 +303,13 @@ static int on_stream_close_callback(nghttp2_session *session, int32_t stream_id,
* The implementation of nghttp2_on_data_chunk_recv_callback type. We * The implementation of nghttp2_on_data_chunk_recv_callback type. We
* use this function to print the received response body. * use this function to print the received response body.
*/ */
static int on_data_chunk_recv_callback(nghttp2_session *session, static int on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags,
uint8_t flags _U_, int32_t stream_id, int32_t stream_id, const uint8_t *data,
const uint8_t *data, size_t len, size_t len, void *user_data) {
void *user_data _U_) {
struct Request *req; struct Request *req;
(void)flags;
(void)user_data;
req = nghttp2_session_get_stream_user_data(session, stream_id); req = nghttp2_session_get_stream_user_data(session, stream_id);
if (req) { if (req) {
printf("[INFO] C <---------------------------- S (DATA chunk)\n" printf("[INFO] C <---------------------------- S (DATA chunk)\n"
@ -338,10 +350,13 @@ static void setup_nghttp2_callbacks(nghttp2_session_callbacks *callbacks) {
* HTTP/2 protocol, if server does not offer HTTP/2 the nghttp2 * HTTP/2 protocol, if server does not offer HTTP/2 the nghttp2
* library supports, we terminate program. * library supports, we terminate program.
*/ */
static int select_next_proto_cb(SSL *ssl _U_, unsigned char **out, static int select_next_proto_cb(SSL *ssl, unsigned char **out,
unsigned char *outlen, const unsigned char *in, unsigned char *outlen, const unsigned char *in,
unsigned int inlen, void *arg _U_) { unsigned int inlen, void *arg) {
int rv; int rv;
(void)ssl;
(void)arg;
/* nghttp2_select_next_protocol() selects HTTP/2 protocol the /* nghttp2_select_next_protocol() selects HTTP/2 protocol the
nghttp2 library supports. */ nghttp2 library supports. */
rv = nghttp2_select_next_protocol(out, outlen, in, inlen); rv = nghttp2_select_next_protocol(out, outlen, in, inlen);

View File

@ -44,7 +44,7 @@ static void deflate(nghttp2_hd_deflater *deflater,
static int inflate_header_block(nghttp2_hd_inflater *inflater, uint8_t *in, static int inflate_header_block(nghttp2_hd_inflater *inflater, uint8_t *in,
size_t inlen, int final); size_t inlen, int final);
int main(int argc _U_, char **argv _U_) { int main() {
int rv; int rv;
nghttp2_hd_deflater *deflater; nghttp2_hd_deflater *deflater;
nghttp2_hd_inflater *inflater; nghttp2_hd_inflater *inflater;

View File

@ -199,22 +199,27 @@ static void print_headers(FILE *f, nghttp2_nv *nva, size_t nvlen) {
/* nghttp2_send_callback. Here we transmit the |data|, |length| bytes, /* nghttp2_send_callback. Here we transmit the |data|, |length| bytes,
to the network. Because we are using libevent bufferevent, we just to the network. Because we are using libevent bufferevent, we just
write those bytes into bufferevent buffer. */ write those bytes into bufferevent buffer. */
static ssize_t send_callback(nghttp2_session *session _U_, const uint8_t *data, static ssize_t send_callback(nghttp2_session *session, const uint8_t *data,
size_t length, int flags _U_, void *user_data) { size_t length, int flags, void *user_data) {
http2_session_data *session_data = (http2_session_data *)user_data; http2_session_data *session_data = (http2_session_data *)user_data;
struct bufferevent *bev = session_data->bev; struct bufferevent *bev = session_data->bev;
(void)session;
(void)flags;
bufferevent_write(bev, data, length); bufferevent_write(bev, data, length);
return (ssize_t)length; return (ssize_t)length;
} }
/* nghttp2_on_header_callback: Called when nghttp2 library emits /* nghttp2_on_header_callback: Called when nghttp2 library emits
single header name/value pair. */ single header name/value pair. */
static int on_header_callback(nghttp2_session *session _U_, static int on_header_callback(nghttp2_session *session,
const nghttp2_frame *frame, const uint8_t *name, const nghttp2_frame *frame, const uint8_t *name,
size_t namelen, const uint8_t *value, size_t namelen, const uint8_t *value,
size_t valuelen, uint8_t flags _U_, size_t valuelen, uint8_t flags, void *user_data) {
void *user_data) {
http2_session_data *session_data = (http2_session_data *)user_data; http2_session_data *session_data = (http2_session_data *)user_data;
(void)session;
(void)flags;
switch (frame->hd.type) { switch (frame->hd.type) {
case NGHTTP2_HEADERS: case NGHTTP2_HEADERS:
if (frame->headers.cat == NGHTTP2_HCAT_RESPONSE && if (frame->headers.cat == NGHTTP2_HCAT_RESPONSE &&
@ -229,10 +234,12 @@ static int on_header_callback(nghttp2_session *session _U_,
/* nghttp2_on_begin_headers_callback: Called when nghttp2 library gets /* nghttp2_on_begin_headers_callback: Called when nghttp2 library gets
started to receive header block. */ started to receive header block. */
static int on_begin_headers_callback(nghttp2_session *session _U_, static int on_begin_headers_callback(nghttp2_session *session,
const nghttp2_frame *frame, const nghttp2_frame *frame,
void *user_data) { void *user_data) {
http2_session_data *session_data = (http2_session_data *)user_data; http2_session_data *session_data = (http2_session_data *)user_data;
(void)session;
switch (frame->hd.type) { switch (frame->hd.type) {
case NGHTTP2_HEADERS: case NGHTTP2_HEADERS:
if (frame->headers.cat == NGHTTP2_HCAT_RESPONSE && if (frame->headers.cat == NGHTTP2_HCAT_RESPONSE &&
@ -247,9 +254,11 @@ static int on_begin_headers_callback(nghttp2_session *session _U_,
/* nghttp2_on_frame_recv_callback: Called when nghttp2 library /* nghttp2_on_frame_recv_callback: Called when nghttp2 library
received a complete frame from the remote peer. */ received a complete frame from the remote peer. */
static int on_frame_recv_callback(nghttp2_session *session _U_, static int on_frame_recv_callback(nghttp2_session *session,
const nghttp2_frame *frame, void *user_data) { const nghttp2_frame *frame, void *user_data) {
http2_session_data *session_data = (http2_session_data *)user_data; http2_session_data *session_data = (http2_session_data *)user_data;
(void)session;
switch (frame->hd.type) { switch (frame->hd.type) {
case NGHTTP2_HEADERS: case NGHTTP2_HEADERS:
if (frame->headers.cat == NGHTTP2_HCAT_RESPONSE && if (frame->headers.cat == NGHTTP2_HCAT_RESPONSE &&
@ -266,11 +275,13 @@ static int on_frame_recv_callback(nghttp2_session *session _U_,
is meant to the stream we initiated, print the received data in is meant to the stream we initiated, print the received data in
stdout, so that the user can redirect its output to the file stdout, so that the user can redirect its output to the file
easily. */ easily. */
static int on_data_chunk_recv_callback(nghttp2_session *session _U_, static int on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags,
uint8_t flags _U_, int32_t stream_id, int32_t stream_id, const uint8_t *data,
const uint8_t *data, size_t len, size_t len, void *user_data) {
void *user_data) {
http2_session_data *session_data = (http2_session_data *)user_data; http2_session_data *session_data = (http2_session_data *)user_data;
(void)session;
(void)flags;
if (session_data->stream_data->stream_id == stream_id) { if (session_data->stream_data->stream_id == stream_id) {
fwrite(data, 1, len, stdout); fwrite(data, 1, len, stdout);
} }
@ -300,9 +311,12 @@ static int on_stream_close_callback(nghttp2_session *session, int32_t stream_id,
/* NPN TLS extension client callback. We check that server advertised /* NPN TLS extension client callback. We check that server advertised
the HTTP/2 protocol the nghttp2 library supports. If not, exit the HTTP/2 protocol the nghttp2 library supports. If not, exit
the program. */ the program. */
static int select_next_proto_cb(SSL *ssl _U_, unsigned char **out, static int select_next_proto_cb(SSL *ssl, unsigned char **out,
unsigned char *outlen, const unsigned char *in, unsigned char *outlen, const unsigned char *in,
unsigned int inlen, void *arg _U_) { unsigned int inlen, void *arg) {
(void)ssl;
(void)arg;
if (nghttp2_select_next_protocol(out, outlen, in, inlen) <= 0) { if (nghttp2_select_next_protocol(out, outlen, in, inlen) <= 0) {
errx(1, "Server did not advertise " NGHTTP2_PROTO_VERSION_ID); errx(1, "Server did not advertise " NGHTTP2_PROTO_VERSION_ID);
} }
@ -461,8 +475,10 @@ static void readcb(struct bufferevent *bev, void *ptr) {
receiving GOAWAY, we check the some conditions on the nghttp2 receiving GOAWAY, we check the some conditions on the nghttp2
library and output buffer of bufferevent. If it indicates we have library and output buffer of bufferevent. If it indicates we have
no business to this session, tear down the connection. */ no business to this session, tear down the connection. */
static void writecb(struct bufferevent *bev _U_, void *ptr) { static void writecb(struct bufferevent *bev, void *ptr) {
http2_session_data *session_data = (http2_session_data *)ptr; http2_session_data *session_data = (http2_session_data *)ptr;
(void)bev;
if (nghttp2_session_want_read(session_data->session) == 0 && if (nghttp2_session_want_read(session_data->session) == 0 &&
nghttp2_session_want_write(session_data->session) == 0 && nghttp2_session_want_write(session_data->session) == 0 &&
evbuffer_get_length(bufferevent_get_output(session_data->bev)) == 0) { evbuffer_get_length(bufferevent_get_output(session_data->bev)) == 0) {

View File

@ -109,18 +109,23 @@ struct app_context {
static unsigned char next_proto_list[256]; static unsigned char next_proto_list[256];
static size_t next_proto_list_len; static size_t next_proto_list_len;
static int next_proto_cb(SSL *s _U_, const unsigned char **data, static int next_proto_cb(SSL *ssl, const unsigned char **data,
unsigned int *len, void *arg _U_) { unsigned int *len, void *arg) {
(void)ssl;
(void)arg;
*data = next_proto_list; *data = next_proto_list;
*len = (unsigned int)next_proto_list_len; *len = (unsigned int)next_proto_list_len;
return SSL_TLSEXT_ERR_OK; return SSL_TLSEXT_ERR_OK;
} }
#if OPENSSL_VERSION_NUMBER >= 0x10002000L #if OPENSSL_VERSION_NUMBER >= 0x10002000L
static int alpn_select_proto_cb(SSL *ssl _U_, const unsigned char **out, static int alpn_select_proto_cb(SSL *ssl, const unsigned char **out,
unsigned char *outlen, const unsigned char *in, unsigned char *outlen, const unsigned char *in,
unsigned int inlen, void *arg _U_) { unsigned int inlen, void *arg) {
int rv; int rv;
(void)ssl;
(void)arg;
rv = nghttp2_select_next_protocol((unsigned char **)out, outlen, in, inlen); rv = nghttp2_select_next_protocol((unsigned char **)out, outlen, in, inlen);
@ -197,8 +202,10 @@ static void add_stream(http2_session_data *session_data,
} }
} }
static void remove_stream(http2_session_data *session_data _U_, static void remove_stream(http2_session_data *session_data,
http2_stream_data *stream_data) { http2_stream_data *stream_data) {
(void)session_data;
stream_data->prev->next = stream_data->next; stream_data->prev->next = stream_data->next;
if (stream_data->next) { if (stream_data->next) {
stream_data->next->prev = stream_data->prev; stream_data->next->prev = stream_data->prev;
@ -309,10 +316,13 @@ static int session_recv(http2_session_data *session_data) {
return 0; return 0;
} }
static ssize_t send_callback(nghttp2_session *session _U_, const uint8_t *data, static ssize_t send_callback(nghttp2_session *session, const uint8_t *data,
size_t length, int flags _U_, void *user_data) { size_t length, int flags, void *user_data) {
http2_session_data *session_data = (http2_session_data *)user_data; http2_session_data *session_data = (http2_session_data *)user_data;
struct bufferevent *bev = session_data->bev; struct bufferevent *bev = session_data->bev;
(void)session;
(void)flags;
/* Avoid excessive buffering in server side. */ /* Avoid excessive buffering in server side. */
if (evbuffer_get_length(bufferevent_get_output(session_data->bev)) >= if (evbuffer_get_length(bufferevent_get_output(session_data->bev)) >=
OUTPUT_WOULDBLOCK_THRESHOLD) { OUTPUT_WOULDBLOCK_THRESHOLD) {
@ -375,13 +385,17 @@ static char *percent_decode(const uint8_t *value, size_t valuelen) {
return res; return res;
} }
static ssize_t file_read_callback(nghttp2_session *session _U_, static ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id,
int32_t stream_id _U_, uint8_t *buf, uint8_t *buf, size_t length,
size_t length, uint32_t *data_flags, uint32_t *data_flags,
nghttp2_data_source *source, nghttp2_data_source *source,
void *user_data _U_) { void *user_data) {
int fd = source->fd; int fd = source->fd;
ssize_t r; ssize_t r;
(void)session;
(void)stream_id;
(void)user_data;
while ((r = read(fd, buf, length)) == -1 && errno == EINTR) while ((r = read(fd, buf, length)) == -1 && errno == EINTR)
; ;
if (r == -1) { if (r == -1) {
@ -454,10 +468,12 @@ static int error_reply(nghttp2_session *session,
static int on_header_callback(nghttp2_session *session, static int on_header_callback(nghttp2_session *session,
const nghttp2_frame *frame, const uint8_t *name, const nghttp2_frame *frame, const uint8_t *name,
size_t namelen, const uint8_t *value, size_t namelen, const uint8_t *value,
size_t valuelen, uint8_t flags _U_, size_t valuelen, uint8_t flags, void *user_data) {
void *user_data _U_) {
http2_stream_data *stream_data; http2_stream_data *stream_data;
const char PATH[] = ":path"; const char PATH[] = ":path";
(void)flags;
(void)user_data;
switch (frame->hd.type) { switch (frame->hd.type) {
case NGHTTP2_HEADERS: case NGHTTP2_HEADERS:
if (frame->headers.cat != NGHTTP2_HCAT_REQUEST) { if (frame->headers.cat != NGHTTP2_HCAT_REQUEST) {
@ -570,9 +586,10 @@ static int on_frame_recv_callback(nghttp2_session *session,
} }
static int on_stream_close_callback(nghttp2_session *session, int32_t stream_id, static int on_stream_close_callback(nghttp2_session *session, int32_t stream_id,
uint32_t error_code _U_, void *user_data) { uint32_t error_code, void *user_data) {
http2_session_data *session_data = (http2_session_data *)user_data; http2_session_data *session_data = (http2_session_data *)user_data;
http2_stream_data *stream_data; http2_stream_data *stream_data;
(void)error_code;
stream_data = nghttp2_session_get_stream_user_data(session, stream_id); stream_data = nghttp2_session_get_stream_user_data(session, stream_id);
if (!stream_data) { if (!stream_data) {
@ -625,8 +642,10 @@ static int send_server_connection_header(http2_session_data *session_data) {
/* readcb for bufferevent after client connection header was /* readcb for bufferevent after client connection header was
checked. */ checked. */
static void readcb(struct bufferevent *bev _U_, void *ptr) { static void readcb(struct bufferevent *bev, void *ptr) {
http2_session_data *session_data = (http2_session_data *)ptr; http2_session_data *session_data = (http2_session_data *)ptr;
(void)bev;
if (session_recv(session_data) != 0) { if (session_recv(session_data) != 0) {
delete_http2_session_data(session_data); delete_http2_session_data(session_data);
return; return;
@ -658,12 +677,13 @@ static void writecb(struct bufferevent *bev, void *ptr) {
} }
/* eventcb for bufferevent */ /* eventcb for bufferevent */
static void eventcb(struct bufferevent *bev _U_, short events, void *ptr) { static void eventcb(struct bufferevent *bev, short events, void *ptr) {
http2_session_data *session_data = (http2_session_data *)ptr; http2_session_data *session_data = (http2_session_data *)ptr;
if (events & BEV_EVENT_CONNECTED) { if (events & BEV_EVENT_CONNECTED) {
const unsigned char *alpn = NULL; const unsigned char *alpn = NULL;
unsigned int alpnlen = 0; unsigned int alpnlen = 0;
SSL *ssl; SSL *ssl;
(void)bev;
fprintf(stderr, "%s connected\n", session_data->client_addr); fprintf(stderr, "%s connected\n", session_data->client_addr);
@ -703,10 +723,11 @@ static void eventcb(struct bufferevent *bev _U_, short events, void *ptr) {
} }
/* callback for evconnlistener */ /* callback for evconnlistener */
static void acceptcb(struct evconnlistener *listener _U_, int fd, static void acceptcb(struct evconnlistener *listener, int fd,
struct sockaddr *addr, int addrlen, void *arg) { struct sockaddr *addr, int addrlen, void *arg) {
app_context *app_ctx = (app_context *)arg; app_context *app_ctx = (app_context *)arg;
http2_session_data *session_data; http2_session_data *session_data;
(void)listener;
session_data = create_http2_session_data(app_ctx, fd, addr, addrlen); session_data = create_http2_session_data(app_ctx, fd, addr, addrlen);

View File

@ -62,7 +62,7 @@ AR := lib
#LD := xilink #LD := xilink
#AR := xilib #AR := xilib
RC := rc RC := rc
CFLAGS := -I./includes -Dssize_t=long -D_U_="" CFLAGS := -I./includes -Dssize_t=long
CFLAGS_R := -nologo -MD -W3 -Z7 -DBUILDING_NGHTTP2 CFLAGS_R := -nologo -MD -W3 -Z7 -DBUILDING_NGHTTP2
CFLAGS_D := -nologo -MDd -W3 -Z7 -DBUILDING_NGHTTP2 \ CFLAGS_D := -nologo -MDd -W3 -Z7 -DBUILDING_NGHTTP2 \

View File

@ -53,6 +53,8 @@ void nghttp2_set_debug_vprintf_callback(
#else /* !DEBUGBUILD */ #else /* !DEBUGBUILD */
void nghttp2_set_debug_vprintf_callback( void nghttp2_set_debug_vprintf_callback(
nghttp2_debug_vprintf_callback debug_vprintf_callback _U_) {} nghttp2_debug_vprintf_callback debug_vprintf_callback) {
(void)debug_vprintf_callback;
}
#endif /* !DEBUGBUILD */ #endif /* !DEBUGBUILD */

View File

@ -87,7 +87,7 @@ void nghttp2_frame_priority_init(nghttp2_priority *frame, int32_t stream_id,
frame->pri_spec = *pri_spec; frame->pri_spec = *pri_spec;
} }
void nghttp2_frame_priority_free(nghttp2_priority *frame _U_) {} void nghttp2_frame_priority_free(nghttp2_priority *frame) { (void)frame; }
void nghttp2_frame_rst_stream_init(nghttp2_rst_stream *frame, int32_t stream_id, void nghttp2_frame_rst_stream_init(nghttp2_rst_stream *frame, int32_t stream_id,
uint32_t error_code) { uint32_t error_code) {
@ -96,7 +96,7 @@ void nghttp2_frame_rst_stream_init(nghttp2_rst_stream *frame, int32_t stream_id,
frame->error_code = error_code; frame->error_code = error_code;
} }
void nghttp2_frame_rst_stream_free(nghttp2_rst_stream *frame _U_) {} void nghttp2_frame_rst_stream_free(nghttp2_rst_stream *frame) { (void)frame; }
void nghttp2_frame_settings_init(nghttp2_settings *frame, uint8_t flags, void nghttp2_frame_settings_init(nghttp2_settings *frame, uint8_t flags,
nghttp2_settings_entry *iv, size_t niv) { nghttp2_settings_entry *iv, size_t niv) {
@ -137,7 +137,7 @@ void nghttp2_frame_ping_init(nghttp2_ping *frame, uint8_t flags,
} }
} }
void nghttp2_frame_ping_free(nghttp2_ping *frame _U_) {} void nghttp2_frame_ping_free(nghttp2_ping *frame) { (void)frame; }
void nghttp2_frame_goaway_init(nghttp2_goaway *frame, int32_t last_stream_id, void nghttp2_frame_goaway_init(nghttp2_goaway *frame, int32_t last_stream_id,
uint32_t error_code, uint8_t *opaque_data, uint32_t error_code, uint8_t *opaque_data,
@ -163,7 +163,9 @@ void nghttp2_frame_window_update_init(nghttp2_window_update *frame,
frame->reserved = 0; frame->reserved = 0;
} }
void nghttp2_frame_window_update_free(nghttp2_window_update *frame _U_) {} void nghttp2_frame_window_update_free(nghttp2_window_update *frame) {
(void)frame;
}
size_t nghttp2_frame_trail_padlen(nghttp2_frame *frame, size_t padlen) { size_t nghttp2_frame_trail_padlen(nghttp2_frame *frame, size_t padlen) {
/* We have iframe->padlen == 0, but iframe->frame.hd.flags may have /* We have iframe->padlen == 0, but iframe->frame.hd.flags may have
@ -183,7 +185,7 @@ void nghttp2_frame_data_init(nghttp2_data *frame, uint8_t flags,
frame->padlen = 0; frame->padlen = 0;
} }
void nghttp2_frame_data_free(nghttp2_data *frame _U_) {} void nghttp2_frame_data_free(nghttp2_data *frame) { (void)frame; }
void nghttp2_frame_extension_init(nghttp2_extension *frame, uint8_t type, void nghttp2_frame_extension_init(nghttp2_extension *frame, uint8_t type,
uint8_t flags, int32_t stream_id, uint8_t flags, int32_t stream_id,
@ -192,7 +194,7 @@ void nghttp2_frame_extension_init(nghttp2_extension *frame, uint8_t type,
frame->payload = payload; frame->payload = payload;
} }
void nghttp2_frame_extension_free(nghttp2_extension *frame _U_) {} void nghttp2_frame_extension_free(nghttp2_extension *frame) { (void)frame; }
void nghttp2_frame_altsvc_init(nghttp2_extension *frame, int32_t stream_id, void nghttp2_frame_altsvc_init(nghttp2_extension *frame, int32_t stream_id,
uint8_t *origin, size_t origin_len, uint8_t *origin, size_t origin_len,
@ -346,9 +348,7 @@ void nghttp2_frame_pack_priority_spec(uint8_t *buf,
} }
void nghttp2_frame_unpack_priority_spec(nghttp2_priority_spec *pri_spec, void nghttp2_frame_unpack_priority_spec(nghttp2_priority_spec *pri_spec,
uint8_t flags _U_, const uint8_t *payload) {
const uint8_t *payload,
size_t payloadlen _U_) {
int32_t dep_stream_id; int32_t dep_stream_id;
uint8_t exclusive; uint8_t exclusive;
int32_t weight; int32_t weight;
@ -361,11 +361,9 @@ void nghttp2_frame_unpack_priority_spec(nghttp2_priority_spec *pri_spec,
} }
int nghttp2_frame_unpack_headers_payload(nghttp2_headers *frame, int nghttp2_frame_unpack_headers_payload(nghttp2_headers *frame,
const uint8_t *payload, const uint8_t *payload) {
size_t payloadlen) {
if (frame->hd.flags & NGHTTP2_FLAG_PRIORITY) { if (frame->hd.flags & NGHTTP2_FLAG_PRIORITY) {
nghttp2_frame_unpack_priority_spec(&frame->pri_spec, frame->hd.flags, nghttp2_frame_unpack_priority_spec(&frame->pri_spec, payload);
payload, payloadlen);
} else { } else {
nghttp2_priority_spec_default_init(&frame->pri_spec); nghttp2_priority_spec_default_init(&frame->pri_spec);
} }
@ -397,10 +395,8 @@ int nghttp2_frame_pack_priority(nghttp2_bufs *bufs, nghttp2_priority *frame) {
} }
void nghttp2_frame_unpack_priority_payload(nghttp2_priority *frame, void nghttp2_frame_unpack_priority_payload(nghttp2_priority *frame,
const uint8_t *payload, const uint8_t *payload) {
size_t payloadlen) { nghttp2_frame_unpack_priority_spec(&frame->pri_spec, payload);
nghttp2_frame_unpack_priority_spec(&frame->pri_spec, frame->hd.flags, payload,
payloadlen);
} }
int nghttp2_frame_pack_rst_stream(nghttp2_bufs *bufs, int nghttp2_frame_pack_rst_stream(nghttp2_bufs *bufs,
@ -424,8 +420,7 @@ int nghttp2_frame_pack_rst_stream(nghttp2_bufs *bufs,
} }
void nghttp2_frame_unpack_rst_stream_payload(nghttp2_rst_stream *frame, void nghttp2_frame_unpack_rst_stream_payload(nghttp2_rst_stream *frame,
const uint8_t *payload, const uint8_t *payload) {
size_t payloadlen _U_) {
frame->error_code = nghttp2_get_uint32(payload); frame->error_code = nghttp2_get_uint32(payload);
} }
@ -540,8 +535,7 @@ int nghttp2_frame_pack_push_promise(nghttp2_bufs *bufs,
} }
int nghttp2_frame_unpack_push_promise_payload(nghttp2_push_promise *frame, int nghttp2_frame_unpack_push_promise_payload(nghttp2_push_promise *frame,
const uint8_t *payload, const uint8_t *payload) {
size_t payloadlen _U_) {
frame->promised_stream_id = frame->promised_stream_id =
nghttp2_get_uint32(payload) & NGHTTP2_STREAM_ID_MASK; nghttp2_get_uint32(payload) & NGHTTP2_STREAM_ID_MASK;
frame->nva = NULL; frame->nva = NULL;
@ -569,8 +563,7 @@ int nghttp2_frame_pack_ping(nghttp2_bufs *bufs, nghttp2_ping *frame) {
} }
void nghttp2_frame_unpack_ping_payload(nghttp2_ping *frame, void nghttp2_frame_unpack_ping_payload(nghttp2_ping *frame,
const uint8_t *payload, const uint8_t *payload) {
size_t payloadlen _U_) {
memcpy(frame->opaque_data, payload, sizeof(frame->opaque_data)); memcpy(frame->opaque_data, payload, sizeof(frame->opaque_data));
} }
@ -607,7 +600,6 @@ int nghttp2_frame_pack_goaway(nghttp2_bufs *bufs, nghttp2_goaway *frame) {
void nghttp2_frame_unpack_goaway_payload(nghttp2_goaway *frame, void nghttp2_frame_unpack_goaway_payload(nghttp2_goaway *frame,
const uint8_t *payload, const uint8_t *payload,
size_t payloadlen _U_,
uint8_t *var_gift_payload, uint8_t *var_gift_payload,
size_t var_gift_payloadlen) { size_t var_gift_payloadlen) {
frame->last_stream_id = nghttp2_get_uint32(payload) & NGHTTP2_STREAM_ID_MASK; frame->last_stream_id = nghttp2_get_uint32(payload) & NGHTTP2_STREAM_ID_MASK;
@ -643,8 +635,8 @@ int nghttp2_frame_unpack_goaway_payload2(nghttp2_goaway *frame,
memcpy(var_gift_payload, payload + 8, var_gift_payloadlen); memcpy(var_gift_payload, payload + 8, var_gift_payloadlen);
} }
nghttp2_frame_unpack_goaway_payload(frame, payload, payloadlen, nghttp2_frame_unpack_goaway_payload(frame, payload, var_gift_payload,
var_gift_payload, var_gift_payloadlen); var_gift_payloadlen);
return 0; return 0;
} }
@ -670,8 +662,7 @@ int nghttp2_frame_pack_window_update(nghttp2_bufs *bufs,
} }
void nghttp2_frame_unpack_window_update_payload(nghttp2_window_update *frame, void nghttp2_frame_unpack_window_update_payload(nghttp2_window_update *frame,
const uint8_t *payload, const uint8_t *payload) {
size_t payloadlen _U_) {
frame->window_size_increment = frame->window_size_increment =
nghttp2_get_uint32(payload) & NGHTTP2_WINDOW_SIZE_INCREMENT_MASK; nghttp2_get_uint32(payload) & NGHTTP2_WINDOW_SIZE_INCREMENT_MASK;
} }

View File

@ -104,8 +104,7 @@ void nghttp2_frame_pack_priority_spec(uint8_t *buf,
* assumes the |payload| contains whole priority specification. * assumes the |payload| contains whole priority specification.
*/ */
void nghttp2_frame_unpack_priority_spec(nghttp2_priority_spec *pri_spec, void nghttp2_frame_unpack_priority_spec(nghttp2_priority_spec *pri_spec,
uint8_t flags, const uint8_t *payload, const uint8_t *payload);
size_t payloadlen);
/* /*
* Returns the offset from the HEADERS frame payload where the * Returns the offset from the HEADERS frame payload where the
@ -144,8 +143,7 @@ int nghttp2_frame_pack_headers(nghttp2_bufs *bufs, nghttp2_headers *frame,
* This function always succeeds and returns 0. * This function always succeeds and returns 0.
*/ */
int nghttp2_frame_unpack_headers_payload(nghttp2_headers *frame, int nghttp2_frame_unpack_headers_payload(nghttp2_headers *frame,
const uint8_t *payload, const uint8_t *payload);
size_t payloadlen);
/* /*
* Packs PRIORITY frame |frame| in wire format and store it in * Packs PRIORITY frame |frame| in wire format and store it in
@ -162,8 +160,7 @@ int nghttp2_frame_pack_priority(nghttp2_bufs *bufs, nghttp2_priority *frame);
* Unpacks PRIORITY wire format into |frame|. * Unpacks PRIORITY wire format into |frame|.
*/ */
void nghttp2_frame_unpack_priority_payload(nghttp2_priority *frame, void nghttp2_frame_unpack_priority_payload(nghttp2_priority *frame,
const uint8_t *payload, const uint8_t *payload);
size_t payloadlen);
/* /*
* Packs RST_STREAM frame |frame| in wire frame format and store it in * Packs RST_STREAM frame |frame| in wire frame format and store it in
@ -181,8 +178,7 @@ int nghttp2_frame_pack_rst_stream(nghttp2_bufs *bufs,
* Unpacks RST_STREAM frame byte sequence into |frame|. * Unpacks RST_STREAM frame byte sequence into |frame|.
*/ */
void nghttp2_frame_unpack_rst_stream_payload(nghttp2_rst_stream *frame, void nghttp2_frame_unpack_rst_stream_payload(nghttp2_rst_stream *frame,
const uint8_t *payload, const uint8_t *payload);
size_t payloadlen);
/* /*
* Packs SETTINGS frame |frame| in wire format and store it in * Packs SETTINGS frame |frame| in wire format and store it in
@ -273,8 +269,7 @@ int nghttp2_frame_pack_push_promise(nghttp2_bufs *bufs,
* TODO END_HEADERS flag is not set * TODO END_HEADERS flag is not set
*/ */
int nghttp2_frame_unpack_push_promise_payload(nghttp2_push_promise *frame, int nghttp2_frame_unpack_push_promise_payload(nghttp2_push_promise *frame,
const uint8_t *payload, const uint8_t *payload);
size_t payloadlen);
/* /*
* Packs PING frame |frame| in wire format and store it in * Packs PING frame |frame| in wire format and store it in
@ -291,8 +286,7 @@ int nghttp2_frame_pack_ping(nghttp2_bufs *bufs, nghttp2_ping *frame);
* Unpacks PING wire format into |frame|. * Unpacks PING wire format into |frame|.
*/ */
void nghttp2_frame_unpack_ping_payload(nghttp2_ping *frame, void nghttp2_frame_unpack_ping_payload(nghttp2_ping *frame,
const uint8_t *payload, const uint8_t *payload);
size_t payloadlen);
/* /*
* Packs GOAWAY frame |frame| in wire format and store it in |bufs|. * Packs GOAWAY frame |frame| in wire format and store it in |bufs|.
@ -321,7 +315,6 @@ int nghttp2_frame_pack_goaway(nghttp2_bufs *bufs, nghttp2_goaway *frame);
*/ */
void nghttp2_frame_unpack_goaway_payload(nghttp2_goaway *frame, void nghttp2_frame_unpack_goaway_payload(nghttp2_goaway *frame,
const uint8_t *payload, const uint8_t *payload,
size_t payloadlen,
uint8_t *var_gift_payload, uint8_t *var_gift_payload,
size_t var_gift_payloadlen); size_t var_gift_payloadlen);
@ -356,8 +349,7 @@ int nghttp2_frame_pack_window_update(nghttp2_bufs *bufs,
* Unpacks WINDOW_UPDATE frame byte sequence into |frame|. * Unpacks WINDOW_UPDATE frame byte sequence into |frame|.
*/ */
void nghttp2_frame_unpack_window_update_payload(nghttp2_window_update *frame, void nghttp2_frame_unpack_window_update_payload(nghttp2_window_update *frame,
const uint8_t *payload, const uint8_t *payload);
size_t payloadlen);
/* /*
* Packs ALTSVC frame |frame| in wire frame format and store it in * Packs ALTSVC frame |frame| in wire frame format and store it in

View File

@ -1537,10 +1537,11 @@ ssize_t nghttp2_hd_deflate_hd_vec(nghttp2_hd_deflater *deflater,
return (ssize_t)buflen; return (ssize_t)buflen;
} }
size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater _U_, size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater,
const nghttp2_nv *nva, size_t nvlen) { const nghttp2_nv *nva, size_t nvlen) {
size_t n = 0; size_t n = 0;
size_t i; size_t i;
(void)deflater;
/* Possible Maximum Header Table Size Change. Encoding (1u << 31) - /* Possible Maximum Header Table Size Change. Encoding (1u << 31) -
1 using 4 bit prefix requires 6 bytes. We may emit this at most 1 using 4 bit prefix requires 6 bytes. We may emit this at most

View File

@ -521,8 +521,10 @@ int nghttp2_http_on_response_headers(nghttp2_stream *stream) {
return 0; return 0;
} }
int nghttp2_http_on_trailer_headers(nghttp2_stream *stream _U_, int nghttp2_http_on_trailer_headers(nghttp2_stream *stream,
nghttp2_frame *frame) { nghttp2_frame *frame) {
(void)stream;
if ((frame->hd.flags & NGHTTP2_FLAG_END_STREAM) == 0) { if ((frame->hd.flags & NGHTTP2_FLAG_END_STREAM) == 0) {
return -1; return -1;
} }

View File

@ -24,18 +24,27 @@
*/ */
#include "nghttp2_mem.h" #include "nghttp2_mem.h"
static void *default_malloc(size_t size, void *mem_user_data _U_) { static void *default_malloc(size_t size, void *mem_user_data) {
(void)mem_user_data;
return malloc(size); return malloc(size);
} }
static void default_free(void *ptr, void *mem_user_data _U_) { free(ptr); } static void default_free(void *ptr, void *mem_user_data) {
(void)mem_user_data;
free(ptr);
}
static void *default_calloc(size_t nmemb, size_t size, void *mem_user_data) {
(void)mem_user_data;
static void *default_calloc(size_t nmemb, size_t size,
void *mem_user_data _U_) {
return calloc(nmemb, size); return calloc(nmemb, size);
} }
static void *default_realloc(void *ptr, size_t size, void *mem_user_data _U_) { static void *default_realloc(void *ptr, size_t size, void *mem_user_data) {
(void)mem_user_data;
return realloc(ptr, size); return realloc(ptr, size);
} }

View File

@ -3394,8 +3394,7 @@ static int session_call_unpack_extension_callback(nghttp2_session *session) {
* NGHTTP2_ERR_NOMEM * NGHTTP2_ERR_NOMEM
* Out of memory. * Out of memory.
*/ */
static int session_handle_frame_size_error(nghttp2_session *session, static int session_handle_frame_size_error(nghttp2_session *session) {
nghttp2_frame *frame _U_) {
/* TODO Currently no callback is called for this error, because we /* TODO Currently no callback is called for this error, because we
call this callback before reading any payload */ call this callback before reading any payload */
return nghttp2_session_terminate_session(session, NGHTTP2_FRAME_SIZE_ERROR); return nghttp2_session_terminate_session(session, NGHTTP2_FRAME_SIZE_ERROR);
@ -3991,8 +3990,7 @@ static int session_process_headers_frame(nghttp2_session *session) {
nghttp2_frame *frame = &iframe->frame; nghttp2_frame *frame = &iframe->frame;
nghttp2_stream *stream; nghttp2_stream *stream;
rv = nghttp2_frame_unpack_headers_payload(&frame->headers, iframe->sbuf.pos, rv = nghttp2_frame_unpack_headers_payload(&frame->headers, iframe->sbuf.pos);
nghttp2_buf_len(&iframe->sbuf));
if (rv != 0) { if (rv != 0) {
return nghttp2_session_terminate_session_with_reason( return nghttp2_session_terminate_session_with_reason(
@ -4082,8 +4080,7 @@ static int session_process_priority_frame(nghttp2_session *session) {
nghttp2_inbound_frame *iframe = &session->iframe; nghttp2_inbound_frame *iframe = &session->iframe;
nghttp2_frame *frame = &iframe->frame; nghttp2_frame *frame = &iframe->frame;
nghttp2_frame_unpack_priority_payload(&frame->priority, iframe->sbuf.pos, nghttp2_frame_unpack_priority_payload(&frame->priority, iframe->sbuf.pos);
nghttp2_buf_len(&iframe->sbuf));
return nghttp2_session_on_priority_received(session, frame); return nghttp2_session_on_priority_received(session, frame);
} }
@ -4124,8 +4121,7 @@ static int session_process_rst_stream_frame(nghttp2_session *session) {
nghttp2_inbound_frame *iframe = &session->iframe; nghttp2_inbound_frame *iframe = &session->iframe;
nghttp2_frame *frame = &iframe->frame; nghttp2_frame *frame = &iframe->frame;
nghttp2_frame_unpack_rst_stream_payload(&frame->rst_stream, iframe->sbuf.pos, nghttp2_frame_unpack_rst_stream_payload(&frame->rst_stream, iframe->sbuf.pos);
nghttp2_buf_len(&iframe->sbuf));
return nghttp2_session_on_rst_stream_received(session, frame); return nghttp2_session_on_rst_stream_received(session, frame);
} }
@ -4597,8 +4593,8 @@ static int session_process_push_promise_frame(nghttp2_session *session) {
nghttp2_inbound_frame *iframe = &session->iframe; nghttp2_inbound_frame *iframe = &session->iframe;
nghttp2_frame *frame = &iframe->frame; nghttp2_frame *frame = &iframe->frame;
rv = nghttp2_frame_unpack_push_promise_payload( rv = nghttp2_frame_unpack_push_promise_payload(&frame->push_promise,
&frame->push_promise, iframe->sbuf.pos, nghttp2_buf_len(&iframe->sbuf)); iframe->sbuf.pos);
if (rv != 0) { if (rv != 0) {
return nghttp2_session_terminate_session_with_reason( return nghttp2_session_terminate_session_with_reason(
@ -4632,8 +4628,7 @@ static int session_process_ping_frame(nghttp2_session *session) {
nghttp2_inbound_frame *iframe = &session->iframe; nghttp2_inbound_frame *iframe = &session->iframe;
nghttp2_frame *frame = &iframe->frame; nghttp2_frame *frame = &iframe->frame;
nghttp2_frame_unpack_ping_payload(&frame->ping, iframe->sbuf.pos, nghttp2_frame_unpack_ping_payload(&frame->ping, iframe->sbuf.pos);
nghttp2_buf_len(&iframe->sbuf));
return nghttp2_session_on_ping_received(session, frame); return nghttp2_session_on_ping_received(session, frame);
} }
@ -4674,9 +4669,9 @@ static int session_process_goaway_frame(nghttp2_session *session) {
nghttp2_inbound_frame *iframe = &session->iframe; nghttp2_inbound_frame *iframe = &session->iframe;
nghttp2_frame *frame = &iframe->frame; nghttp2_frame *frame = &iframe->frame;
nghttp2_frame_unpack_goaway_payload( nghttp2_frame_unpack_goaway_payload(&frame->goaway, iframe->sbuf.pos,
&frame->goaway, iframe->sbuf.pos, nghttp2_buf_len(&iframe->sbuf), iframe->lbuf.pos,
iframe->lbuf.pos, nghttp2_buf_len(&iframe->lbuf)); nghttp2_buf_len(&iframe->lbuf));
nghttp2_buf_wrap_init(&iframe->lbuf, NULL, 0); nghttp2_buf_wrap_init(&iframe->lbuf, NULL, 0);
@ -4759,8 +4754,8 @@ static int session_process_window_update_frame(nghttp2_session *session) {
nghttp2_inbound_frame *iframe = &session->iframe; nghttp2_inbound_frame *iframe = &session->iframe;
nghttp2_frame *frame = &iframe->frame; nghttp2_frame *frame = &iframe->frame;
nghttp2_frame_unpack_window_update_payload( nghttp2_frame_unpack_window_update_payload(&frame->window_update,
&frame->window_update, iframe->sbuf.pos, nghttp2_buf_len(&iframe->sbuf)); iframe->sbuf.pos);
return nghttp2_session_on_window_update_received(session, frame); return nghttp2_session_on_window_update_received(session, frame);
} }
@ -6128,7 +6123,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in,
case NGHTTP2_IB_FRAME_SIZE_ERROR: case NGHTTP2_IB_FRAME_SIZE_ERROR:
DEBUGF("recv: [IB_FRAME_SIZE_ERROR]\n"); DEBUGF("recv: [IB_FRAME_SIZE_ERROR]\n");
rv = session_handle_frame_size_error(session, &iframe->frame); rv = session_handle_frame_size_error(session);
if (nghttp2_is_fatal(rv)) { if (nghttp2_is_fatal(rv)) {
return rv; return rv;
} }

View File

@ -449,8 +449,8 @@ static void validate_tree(nghttp2_stream *stream) {
check_sum_dep(stream); check_sum_dep(stream);
check_dep_prev(stream); check_dep_prev(stream);
} }
#else /* !STREAM_DEP_DEBUG */ #else /* !STREAM_DEP_DEBUG */
static void validate_tree(nghttp2_stream *stream _U_) {} static void validate_tree(nghttp2_stream *stream) { (void)stream; }
#endif /* !STREAM_DEP_DEBUG*/ #endif /* !STREAM_DEP_DEBUG*/
static int stream_update_dep_on_attach_item(nghttp2_stream *stream) { static int stream_update_dep_on_attach_item(nghttp2_stream *stream) {

View File

@ -217,7 +217,7 @@ int nghttp2_submit_ping(nghttp2_session *session, uint8_t flags,
return nghttp2_session_add_ping(session, flags, opaque_data); return nghttp2_session_add_ping(session, flags, opaque_data);
} }
int nghttp2_submit_priority(nghttp2_session *session, uint8_t flags _U_, int nghttp2_submit_priority(nghttp2_session *session, uint8_t flags,
int32_t stream_id, int32_t stream_id,
const nghttp2_priority_spec *pri_spec) { const nghttp2_priority_spec *pri_spec) {
int rv; int rv;
@ -225,6 +225,7 @@ int nghttp2_submit_priority(nghttp2_session *session, uint8_t flags _U_,
nghttp2_frame *frame; nghttp2_frame *frame;
nghttp2_priority_spec copy_pri_spec; nghttp2_priority_spec copy_pri_spec;
nghttp2_mem *mem; nghttp2_mem *mem;
(void)flags;
mem = &session->mem; mem = &session->mem;
@ -264,8 +265,10 @@ int nghttp2_submit_priority(nghttp2_session *session, uint8_t flags _U_,
return 0; return 0;
} }
int nghttp2_submit_rst_stream(nghttp2_session *session, uint8_t flags _U_, int nghttp2_submit_rst_stream(nghttp2_session *session, uint8_t flags,
int32_t stream_id, uint32_t error_code) { int32_t stream_id, uint32_t error_code) {
(void)flags;
if (stream_id == 0) { if (stream_id == 0) {
return NGHTTP2_ERR_INVALID_ARGUMENT; return NGHTTP2_ERR_INVALID_ARGUMENT;
} }
@ -273,9 +276,11 @@ int nghttp2_submit_rst_stream(nghttp2_session *session, uint8_t flags _U_,
return nghttp2_session_add_rst_stream(session, stream_id, error_code); return nghttp2_session_add_rst_stream(session, stream_id, error_code);
} }
int nghttp2_submit_goaway(nghttp2_session *session, uint8_t flags _U_, int nghttp2_submit_goaway(nghttp2_session *session, uint8_t flags,
int32_t last_stream_id, uint32_t error_code, int32_t last_stream_id, uint32_t error_code,
const uint8_t *opaque_data, size_t opaque_data_len) { const uint8_t *opaque_data, size_t opaque_data_len) {
(void)flags;
if (session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND) { if (session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND) {
return 0; return 0;
} }
@ -296,12 +301,13 @@ int nghttp2_submit_shutdown_notice(nghttp2_session *session) {
NGHTTP2_GOAWAY_AUX_SHUTDOWN_NOTICE); NGHTTP2_GOAWAY_AUX_SHUTDOWN_NOTICE);
} }
int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags _U_, int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags,
const nghttp2_settings_entry *iv, size_t niv) { const nghttp2_settings_entry *iv, size_t niv) {
(void)flags;
return nghttp2_session_add_settings(session, NGHTTP2_FLAG_NONE, iv, niv); return nghttp2_session_add_settings(session, NGHTTP2_FLAG_NONE, iv, niv);
} }
int32_t nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags _U_, int32_t nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags,
int32_t stream_id, const nghttp2_nv *nva, int32_t stream_id, const nghttp2_nv *nva,
size_t nvlen, size_t nvlen,
void *promised_stream_user_data) { void *promised_stream_user_data) {
@ -312,6 +318,7 @@ int32_t nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags _U_,
int32_t promised_stream_id; int32_t promised_stream_id;
int rv; int rv;
nghttp2_mem *mem; nghttp2_mem *mem;
(void)flags;
mem = &session->mem; mem = &session->mem;
@ -365,11 +372,13 @@ int32_t nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags _U_,
return promised_stream_id; return promised_stream_id;
} }
int nghttp2_submit_window_update(nghttp2_session *session, uint8_t flags _U_, int nghttp2_submit_window_update(nghttp2_session *session, uint8_t flags,
int32_t stream_id, int32_t stream_id,
int32_t window_size_increment) { int32_t window_size_increment) {
int rv; int rv;
nghttp2_stream *stream = 0; nghttp2_stream *stream = 0;
(void)flags;
if (window_size_increment == 0) { if (window_size_increment == 0) {
return 0; return 0;
} }
@ -410,11 +419,12 @@ int nghttp2_submit_window_update(nghttp2_session *session, uint8_t flags _U_,
} }
int nghttp2_session_set_local_window_size(nghttp2_session *session, int nghttp2_session_set_local_window_size(nghttp2_session *session,
uint8_t flags _U_, int32_t stream_id, uint8_t flags, int32_t stream_id,
int32_t window_size) { int32_t window_size) {
int32_t window_size_increment; int32_t window_size_increment;
nghttp2_stream *stream; nghttp2_stream *stream;
int rv; int rv;
(void)flags;
if (window_size < 0) { if (window_size < 0) {
return NGHTTP2_ERR_INVALID_ARGUMENT; return NGHTTP2_ERR_INVALID_ARGUMENT;
@ -476,7 +486,7 @@ int nghttp2_session_set_local_window_size(nghttp2_session *session,
return 0; return 0;
} }
int nghttp2_submit_altsvc(nghttp2_session *session, uint8_t flags _U_, int nghttp2_submit_altsvc(nghttp2_session *session, uint8_t flags,
int32_t stream_id, const uint8_t *origin, int32_t stream_id, const uint8_t *origin,
size_t origin_len, const uint8_t *field_value, size_t origin_len, const uint8_t *field_value,
size_t field_value_len) { size_t field_value_len) {
@ -488,6 +498,7 @@ int nghttp2_submit_altsvc(nghttp2_session *session, uint8_t flags _U_,
nghttp2_frame *frame; nghttp2_frame *frame;
nghttp2_ext_altsvc *altsvc; nghttp2_ext_altsvc *altsvc;
int rv; int rv;
(void)flags;
mem = &session->mem; mem = &session->mem;

View File

@ -37,7 +37,7 @@ static int init_suite1(void) { return 0; }
static int clean_suite1(void) { return 0; } static int clean_suite1(void) { return 0; }
int main(int argc _U_, char *argv[] _U_) { int main() {
CU_pSuite pSuite = NULL; CU_pSuite pSuite = NULL;
unsigned int num_tests_failed; unsigned int num_tests_failed;

View File

@ -59,29 +59,39 @@ static void data_feed_init(data_feed *df, nghttp2_bufs *bufs) {
df->datalimit = df->data + data_length; df->datalimit = df->data + data_length;
} }
static ssize_t null_send_callback(nghttp2_session *session _U_, static ssize_t null_send_callback(nghttp2_session *session, const uint8_t *data,
const uint8_t *data _U_, size_t len, size_t len, int flags, void *user_data) {
int flags _U_, void *user_data _U_) { (void)session;
(void)data;
(void)flags;
(void)user_data;
return (ssize_t)len; return (ssize_t)len;
} }
static ssize_t data_feed_recv_callback(nghttp2_session *session _U_, static ssize_t data_feed_recv_callback(nghttp2_session *session, uint8_t *data,
uint8_t *data, size_t len, int flags _U_, size_t len, int flags, void *user_data) {
void *user_data) {
data_feed *df = ((my_user_data *)user_data)->df; data_feed *df = ((my_user_data *)user_data)->df;
size_t avail = (size_t)(df->datalimit - df->datamark); size_t avail = (size_t)(df->datalimit - df->datamark);
size_t wlen = nghttp2_min(avail, len); size_t wlen = nghttp2_min(avail, len);
(void)session;
(void)flags;
memcpy(data, df->datamark, wlen); memcpy(data, df->datamark, wlen);
df->datamark += wlen; df->datamark += wlen;
return (ssize_t)wlen; return (ssize_t)wlen;
} }
static ssize_t fixed_length_data_source_read_callback( static ssize_t fixed_length_data_source_read_callback(
nghttp2_session *session _U_, int32_t stream_id _U_, uint8_t *buf _U_, nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len,
size_t len, uint32_t *data_flags, nghttp2_data_source *source _U_, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) {
void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
size_t wlen; size_t wlen;
(void)session;
(void)stream_id;
(void)buf;
(void)source;
if (len < ud->data_source_length) { if (len < ud->data_source_length) {
wlen = len; wlen = len;
} else { } else {

View File

@ -47,7 +47,7 @@ static int init_suite1(void) { return 0; }
static int clean_suite1(void) { return 0; } static int clean_suite1(void) { return 0; }
int main(int argc _U_, char *argv[] _U_) { int main() {
CU_pSuite pSuite = NULL; CU_pSuite pSuite = NULL;
unsigned int num_tests_failed; unsigned int num_tests_failed;

View File

@ -39,19 +39,29 @@ int nghttp2_nmalloc = 0;
} \ } \
} while (0) } while (0)
static void *my_malloc(size_t size, void *mud _U_) { static void *my_malloc(size_t size, void *mud) {
(void)mud;
CHECK_PREREQ; CHECK_PREREQ;
return malloc(size); return malloc(size);
} }
static void my_free(void *ptr, void *mud _U_) { free(ptr); } static void my_free(void *ptr, void *mud) {
(void)mud;
free(ptr);
}
static void *my_calloc(size_t nmemb, size_t size, void *mud) {
(void)mud;
static void *my_calloc(size_t nmemb, size_t size, void *mud _U_) {
CHECK_PREREQ; CHECK_PREREQ;
return calloc(nmemb, size); return calloc(nmemb, size);
} }
static void *my_realloc(void *ptr, size_t size, void *mud _U_) { static void *my_realloc(void *ptr, size_t size, void *mud) {
(void)mud;
CHECK_PREREQ; CHECK_PREREQ;
return realloc(ptr, size); return realloc(ptr, size);
} }

View File

@ -100,7 +100,12 @@ static void shuffle(int *a, int n) {
} }
} }
static int eachfun(nghttp2_map_entry *entry _U_, void *ptr _U_) { return 0; } static int eachfun(nghttp2_map_entry *entry, void *ptr) {
(void)entry;
(void)ptr;
return 0;
}
#define NUM_ENT 6000 #define NUM_ENT 6000
static strentry arr[NUM_ENT]; static strentry arr[NUM_ENT];

View File

@ -127,8 +127,10 @@ static int node_less(const void *lhs, const void *rhs) {
return ln->key < rn->key; return ln->key < rn->key;
} }
static int node_update(nghttp2_pq_entry *item, void *arg _U_) { static int node_update(nghttp2_pq_entry *item, void *arg) {
node *nd = (node *)item; node *nd = (node *)item;
(void)arg;
if ((nd->key % 2) == 0) { if ((nd->key % 2) == 0) {
nd->key *= -1; nd->key *= -1;
return 1; return 1;

View File

@ -118,30 +118,45 @@ static void scripted_data_feed_init2(scripted_data_feed *df,
df->feedseq[0] = len; df->feedseq[0] = len;
} }
static ssize_t null_send_callback(nghttp2_session *session _U_, static ssize_t null_send_callback(nghttp2_session *session, const uint8_t *data,
const uint8_t *data _U_, size_t len, size_t len, int flags, void *user_data) {
int flags _U_, void *user_data _U_) { (void)session;
(void)data;
(void)flags;
(void)user_data;
return (ssize_t)len; return (ssize_t)len;
} }
static ssize_t fail_send_callback(nghttp2_session *session _U_, static ssize_t fail_send_callback(nghttp2_session *session, const uint8_t *data,
const uint8_t *data _U_, size_t len _U_, size_t len, int flags, void *user_data) {
int flags _U_, void *user_data _U_) { (void)session;
(void)data;
(void)len;
(void)flags;
(void)user_data;
return NGHTTP2_ERR_CALLBACK_FAILURE; return NGHTTP2_ERR_CALLBACK_FAILURE;
} }
static ssize_t fixed_bytes_send_callback(nghttp2_session *session _U_, static ssize_t fixed_bytes_send_callback(nghttp2_session *session,
const uint8_t *data _U_, size_t len, const uint8_t *data, size_t len,
int flags _U_, void *user_data) { int flags, void *user_data) {
size_t fixed_sendlen = ((my_user_data *)user_data)->fixed_sendlen; size_t fixed_sendlen = ((my_user_data *)user_data)->fixed_sendlen;
(void)session;
(void)data;
(void)flags;
return (ssize_t)(fixed_sendlen < len ? fixed_sendlen : len); return (ssize_t)(fixed_sendlen < len ? fixed_sendlen : len);
} }
static ssize_t scripted_recv_callback(nghttp2_session *session _U_, static ssize_t scripted_recv_callback(nghttp2_session *session, uint8_t *data,
uint8_t *data, size_t len, int flags _U_, size_t len, int flags, void *user_data) {
void *user_data) {
scripted_data_feed *df = ((my_user_data *)user_data)->df; scripted_data_feed *df = ((my_user_data *)user_data)->df;
size_t wlen = df->feedseq[df->seqidx] > len ? len : df->feedseq[df->seqidx]; size_t wlen = df->feedseq[df->seqidx] > len ? len : df->feedseq[df->seqidx];
(void)session;
(void)flags;
memcpy(data, df->datamark, wlen); memcpy(data, df->datamark, wlen);
df->datamark += wlen; df->datamark += wlen;
df->feedseq[df->seqidx] -= wlen; df->feedseq[df->seqidx] -= wlen;
@ -151,33 +166,46 @@ static ssize_t scripted_recv_callback(nghttp2_session *session _U_,
return (ssize_t)wlen; return (ssize_t)wlen;
} }
static ssize_t eof_recv_callback(nghttp2_session *session _U_, static ssize_t eof_recv_callback(nghttp2_session *session, uint8_t *data,
uint8_t *data _U_, size_t len _U_, size_t len, int flags, void *user_data) {
int flags _U_, void *user_data _U_) { (void)session;
(void)data;
(void)len;
(void)flags;
(void)user_data;
return NGHTTP2_ERR_EOF; return NGHTTP2_ERR_EOF;
} }
static ssize_t accumulator_send_callback(nghttp2_session *session _U_, static ssize_t accumulator_send_callback(nghttp2_session *session,
const uint8_t *buf, size_t len, const uint8_t *buf, size_t len,
int flags _U_, void *user_data) { int flags, void *user_data) {
accumulator *acc = ((my_user_data *)user_data)->acc; accumulator *acc = ((my_user_data *)user_data)->acc;
(void)session;
(void)flags;
assert(acc->length + len < sizeof(acc->buf)); assert(acc->length + len < sizeof(acc->buf));
memcpy(acc->buf + acc->length, buf, len); memcpy(acc->buf + acc->length, buf, len);
acc->length += len; acc->length += len;
return (ssize_t)len; return (ssize_t)len;
} }
static int on_begin_frame_callback(nghttp2_session *session _U_, static int on_begin_frame_callback(nghttp2_session *session,
const nghttp2_frame_hd *hd _U_, const nghttp2_frame_hd *hd,
void *user_data) { void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
(void)session;
(void)hd;
++ud->begin_frame_cb_called; ++ud->begin_frame_cb_called;
return 0; return 0;
} }
static int on_frame_recv_callback(nghttp2_session *session _U_, static int on_frame_recv_callback(nghttp2_session *session,
const nghttp2_frame *frame, void *user_data) { const nghttp2_frame *frame, void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
(void)session;
++ud->frame_recv_cb_called; ++ud->frame_recv_cb_called;
ud->recv_frame_type = frame->hd.type; ud->recv_frame_type = frame->hd.type;
ud->recv_frame_hd = frame->hd; ud->recv_frame_hd = frame->hd;
@ -185,90 +213,129 @@ static int on_frame_recv_callback(nghttp2_session *session _U_,
return 0; return 0;
} }
static int on_invalid_frame_recv_callback(nghttp2_session *session _U_, static int on_invalid_frame_recv_callback(nghttp2_session *session,
const nghttp2_frame *frame _U_, const nghttp2_frame *frame,
int lib_error_code _U_, int lib_error_code, void *user_data) {
void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
(void)session;
(void)frame;
(void)lib_error_code;
++ud->invalid_frame_recv_cb_called; ++ud->invalid_frame_recv_cb_called;
return 0; return 0;
} }
static int on_frame_send_callback(nghttp2_session *session _U_, static int on_frame_send_callback(nghttp2_session *session,
const nghttp2_frame *frame, void *user_data) { const nghttp2_frame *frame, void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
(void)session;
++ud->frame_send_cb_called; ++ud->frame_send_cb_called;
ud->sent_frame_type = frame->hd.type; ud->sent_frame_type = frame->hd.type;
return 0; return 0;
} }
static int on_frame_not_send_callback(nghttp2_session *session _U_, static int on_frame_not_send_callback(nghttp2_session *session,
const nghttp2_frame *frame, int lib_error, const nghttp2_frame *frame, int lib_error,
void *user_data) { void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
(void)session;
++ud->frame_not_send_cb_called; ++ud->frame_not_send_cb_called;
ud->not_sent_frame_type = frame->hd.type; ud->not_sent_frame_type = frame->hd.type;
ud->not_sent_error = lib_error; ud->not_sent_error = lib_error;
return 0; return 0;
} }
static int cancel_before_frame_send_callback(nghttp2_session *session _U_, static int cancel_before_frame_send_callback(nghttp2_session *session,
const nghttp2_frame *frame _U_, const nghttp2_frame *frame,
void *user_data) { void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
(void)session;
(void)frame;
++ud->before_frame_send_cb_called; ++ud->before_frame_send_cb_called;
return NGHTTP2_ERR_CANCEL; return NGHTTP2_ERR_CANCEL;
} }
static int on_data_chunk_recv_callback(nghttp2_session *session _U_, static int on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags,
uint8_t flags _U_, int32_t stream_id _U_, int32_t stream_id, const uint8_t *data,
const uint8_t *data _U_, size_t len, size_t len, void *user_data) {
void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
(void)session;
(void)flags;
(void)stream_id;
(void)data;
++ud->data_chunk_recv_cb_called; ++ud->data_chunk_recv_cb_called;
ud->data_chunk_len = len; ud->data_chunk_len = len;
return 0; return 0;
} }
static int pause_on_data_chunk_recv_callback(nghttp2_session *session _U_, static int pause_on_data_chunk_recv_callback(nghttp2_session *session,
uint8_t flags _U_, uint8_t flags, int32_t stream_id,
int32_t stream_id _U_, const uint8_t *data, size_t len,
const uint8_t *data _U_, void *user_data) {
size_t len _U_, void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
(void)session;
(void)flags;
(void)stream_id;
(void)data;
(void)len;
++ud->data_chunk_recv_cb_called; ++ud->data_chunk_recv_cb_called;
return NGHTTP2_ERR_PAUSE; return NGHTTP2_ERR_PAUSE;
} }
static ssize_t select_padding_callback(nghttp2_session *session _U_, static ssize_t select_padding_callback(nghttp2_session *session,
const nghttp2_frame *frame, const nghttp2_frame *frame,
size_t max_payloadlen, void *user_data) { size_t max_payloadlen, void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
(void)session;
return (ssize_t)nghttp2_min(max_payloadlen, frame->hd.length + ud->padlen); return (ssize_t)nghttp2_min(max_payloadlen, frame->hd.length + ud->padlen);
} }
static ssize_t too_large_data_source_length_callback( static ssize_t too_large_data_source_length_callback(
nghttp2_session *session _U_, uint8_t frame_type _U_, int32_t stream_id _U_, nghttp2_session *session, uint8_t frame_type, int32_t stream_id,
int32_t session_remote_window_size _U_, int32_t session_remote_window_size, int32_t stream_remote_window_size,
int32_t stream_remote_window_size _U_, uint32_t remote_max_frame_size _U_, uint32_t remote_max_frame_size, void *user_data) {
void *user_data _U_) { (void)session;
(void)frame_type;
(void)stream_id;
(void)session_remote_window_size;
(void)stream_remote_window_size;
(void)remote_max_frame_size;
(void)user_data;
return NGHTTP2_MAX_FRAME_SIZE_MAX + 1; return NGHTTP2_MAX_FRAME_SIZE_MAX + 1;
} }
static ssize_t smallest_length_data_source_length_callback( static ssize_t smallest_length_data_source_length_callback(
nghttp2_session *session _U_, uint8_t frame_type _U_, int32_t stream_id _U_, nghttp2_session *session, uint8_t frame_type, int32_t stream_id,
int32_t session_remote_window_size _U_, int32_t session_remote_window_size, int32_t stream_remote_window_size,
int32_t stream_remote_window_size _U_, uint32_t remote_max_frame_size _U_, uint32_t remote_max_frame_size, void *user_data) {
void *user_data _U_) { (void)session;
(void)frame_type;
(void)stream_id;
(void)session_remote_window_size;
(void)stream_remote_window_size;
(void)remote_max_frame_size;
(void)user_data;
return 1; return 1;
} }
static ssize_t fixed_length_data_source_read_callback( static ssize_t fixed_length_data_source_read_callback(
nghttp2_session *session _U_, int32_t stream_id _U_, uint8_t *buf _U_, nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len,
size_t len, uint32_t *data_flags, nghttp2_data_source *source _U_, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) {
void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
size_t wlen; size_t wlen;
(void)session;
(void)stream_id;
(void)buf;
(void)source;
if (len < ud->data_source_length) { if (len < ud->data_source_length) {
wlen = len; wlen = len;
} else { } else {
@ -282,35 +349,59 @@ static ssize_t fixed_length_data_source_read_callback(
} }
static ssize_t temporal_failure_data_source_read_callback( static ssize_t temporal_failure_data_source_read_callback(
nghttp2_session *session _U_, int32_t stream_id _U_, uint8_t *buf _U_, nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len,
size_t len _U_, uint32_t *data_flags _U_, nghttp2_data_source *source _U_, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) {
void *user_data _U_) { (void)session;
(void)stream_id;
(void)buf;
(void)len;
(void)data_flags;
(void)source;
(void)user_data;
return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
} }
static ssize_t fail_data_source_read_callback(nghttp2_session *session _U_, static ssize_t fail_data_source_read_callback(nghttp2_session *session,
int32_t stream_id _U_, int32_t stream_id, uint8_t *buf,
uint8_t *buf _U_, size_t len _U_, size_t len, uint32_t *data_flags,
uint32_t *data_flags _U_, nghttp2_data_source *source,
nghttp2_data_source *source _U_, void *user_data) {
void *user_data _U_) { (void)session;
(void)stream_id;
(void)buf;
(void)len;
(void)data_flags;
(void)source;
(void)user_data;
return NGHTTP2_ERR_CALLBACK_FAILURE; return NGHTTP2_ERR_CALLBACK_FAILURE;
} }
static ssize_t no_end_stream_data_source_read_callback( static ssize_t no_end_stream_data_source_read_callback(
nghttp2_session *session _U_, int32_t stream_id _U_, uint8_t *buf _U_, nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len,
size_t len _U_, uint32_t *data_flags, nghttp2_data_source *source _U_, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) {
void *user_data _U_) { (void)session;
(void)stream_id;
(void)buf;
(void)len;
(void)source;
(void)user_data;
*data_flags |= NGHTTP2_DATA_FLAG_EOF | NGHTTP2_DATA_FLAG_NO_END_STREAM; *data_flags |= NGHTTP2_DATA_FLAG_EOF | NGHTTP2_DATA_FLAG_NO_END_STREAM;
return 0; return 0;
} }
static ssize_t no_copy_data_source_read_callback( static ssize_t no_copy_data_source_read_callback(
nghttp2_session *session _U_, int32_t stream_id _U_, uint8_t *buf _U_, nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len,
size_t len, uint32_t *data_flags, nghttp2_data_source *source _U_, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) {
void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
size_t wlen; size_t wlen;
(void)session;
(void)stream_id;
(void)buf;
(void)source;
if (len < ud->data_source_length) { if (len < ud->data_source_length) {
wlen = len; wlen = len;
} else { } else {
@ -327,11 +418,12 @@ static ssize_t no_copy_data_source_read_callback(
return (ssize_t)wlen; return (ssize_t)wlen;
} }
static int send_data_callback(nghttp2_session *session _U_, static int send_data_callback(nghttp2_session *session, nghttp2_frame *frame,
nghttp2_frame *frame, const uint8_t *framehd, const uint8_t *framehd, size_t length,
size_t length, nghttp2_data_source *source _U_, nghttp2_data_source *source, void *user_data) {
void *user_data) {
accumulator *acc = ((my_user_data *)user_data)->acc; accumulator *acc = ((my_user_data *)user_data)->acc;
(void)session;
(void)source;
memcpy(acc->buf + acc->length, framehd, NGHTTP2_FRAME_HDLEN); memcpy(acc->buf + acc->length, framehd, NGHTTP2_FRAME_HDLEN);
acc->length += NGHTTP2_FRAME_HDLEN; acc->length += NGHTTP2_FRAME_HDLEN;
@ -349,10 +441,13 @@ static int send_data_callback(nghttp2_session *session _U_,
return 0; return 0;
} }
static ssize_t block_count_send_callback(nghttp2_session *session _U_, static ssize_t block_count_send_callback(nghttp2_session *session,
const uint8_t *data _U_, size_t len, const uint8_t *data, size_t len,
int flags _U_, void *user_data) { int flags, void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
(void)session;
(void)data;
(void)flags;
if (ud->block_count == 0) { if (ud->block_count == 0) {
return NGHTTP2_ERR_WOULDBLOCK; return NGHTTP2_ERR_WOULDBLOCK;
@ -362,12 +457,14 @@ static ssize_t block_count_send_callback(nghttp2_session *session _U_,
return (ssize_t)len; return (ssize_t)len;
} }
static int on_header_callback(nghttp2_session *session _U_, static int on_header_callback(nghttp2_session *session,
const nghttp2_frame *frame, const uint8_t *name, const nghttp2_frame *frame, const uint8_t *name,
size_t namelen, const uint8_t *value, size_t namelen, const uint8_t *value,
size_t valuelen, uint8_t flags _U_, size_t valuelen, uint8_t flags, void *user_data) {
void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
(void)session;
(void)flags;
++ud->header_cb_called; ++ud->header_cb_called;
ud->nv.name = (uint8_t *)name; ud->nv.name = (uint8_t *)name;
ud->nv.namelen = namelen; ud->nv.namelen = namelen;
@ -397,12 +494,15 @@ static int temporal_failure_on_header_callback(
return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
} }
static int on_invalid_header_callback(nghttp2_session *session _U_, static int on_invalid_header_callback(nghttp2_session *session,
const nghttp2_frame *frame, const nghttp2_frame *frame,
const uint8_t *name, size_t namelen, const uint8_t *name, size_t namelen,
const uint8_t *value, size_t valuelen, const uint8_t *value, size_t valuelen,
uint8_t flags _U_, void *user_data) { uint8_t flags, void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
(void)session;
(void)flags;
++ud->invalid_header_cb_called; ++ud->invalid_header_cb_called;
ud->nv.name = (uint8_t *)name; ud->nv.name = (uint8_t *)name;
ud->nv.namelen = namelen; ud->nv.namelen = namelen;
@ -435,10 +535,13 @@ static int reset_on_invalid_header_callback(nghttp2_session *session,
return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
} }
static int on_begin_headers_callback(nghttp2_session *session _U_, static int on_begin_headers_callback(nghttp2_session *session,
const nghttp2_frame *frame _U_, const nghttp2_frame *frame,
void *user_data) { void *user_data) {
my_user_data *ud = (my_user_data *)user_data; my_user_data *ud = (my_user_data *)user_data;
(void)session;
(void)frame;
++ud->begin_headers_cb_called; ++ud->begin_headers_cb_called;
return 0; return 0;
} }
@ -449,71 +552,99 @@ static int temporal_failure_on_begin_headers_callback(
return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
} }
static ssize_t defer_data_source_read_callback(nghttp2_session *session _U_, static ssize_t defer_data_source_read_callback(nghttp2_session *session,
int32_t stream_id _U_, int32_t stream_id, uint8_t *buf,
uint8_t *buf _U_, size_t len _U_, size_t len, uint32_t *data_flags,
uint32_t *data_flags _U_, nghttp2_data_source *source,
nghttp2_data_source *source _U_, void *user_data) {
void *user_data _U_) { (void)session;
(void)stream_id;
(void)buf;
(void)len;
(void)data_flags;
(void)source;
(void)user_data;
return NGHTTP2_ERR_DEFERRED; return NGHTTP2_ERR_DEFERRED;
} }
static int on_stream_close_callback(nghttp2_session *session _U_, static int on_stream_close_callback(nghttp2_session *session, int32_t stream_id,
int32_t stream_id _U_, nghttp2_error_code error_code,
nghttp2_error_code error_code _U_,
void *user_data) { void *user_data) {
my_user_data *my_data = (my_user_data *)user_data; my_user_data *my_data = (my_user_data *)user_data;
(void)session;
(void)stream_id;
(void)error_code;
++my_data->stream_close_cb_called; ++my_data->stream_close_cb_called;
my_data->stream_close_error_code = error_code; my_data->stream_close_error_code = error_code;
return 0; return 0;
} }
static ssize_t pack_extension_callback(nghttp2_session *session _U_, static ssize_t pack_extension_callback(nghttp2_session *session, uint8_t *buf,
uint8_t *buf, size_t len _U_, size_t len, const nghttp2_frame *frame,
const nghttp2_frame *frame, void *user_data) {
void *user_data _U_) {
nghttp2_buf *p = frame->ext.payload; nghttp2_buf *p = frame->ext.payload;
(void)session;
(void)len;
(void)user_data;
memcpy(buf, p->pos, nghttp2_buf_len(p)); memcpy(buf, p->pos, nghttp2_buf_len(p));
return (ssize_t)nghttp2_buf_len(p); return (ssize_t)nghttp2_buf_len(p);
} }
static int on_extension_chunk_recv_callback(nghttp2_session *session _U_, static int on_extension_chunk_recv_callback(nghttp2_session *session,
const nghttp2_frame_hd *hd _U_, const nghttp2_frame_hd *hd,
const uint8_t *data, size_t len, const uint8_t *data, size_t len,
void *user_data) { void *user_data) {
my_user_data *my_data = (my_user_data *)user_data; my_user_data *my_data = (my_user_data *)user_data;
nghttp2_buf *buf = &my_data->scratchbuf; nghttp2_buf *buf = &my_data->scratchbuf;
(void)session;
(void)hd;
buf->last = nghttp2_cpymem(buf->last, data, len); buf->last = nghttp2_cpymem(buf->last, data, len);
return 0; return 0;
} }
static int cancel_on_extension_chunk_recv_callback( static int cancel_on_extension_chunk_recv_callback(nghttp2_session *session,
nghttp2_session *session _U_, const nghttp2_frame_hd *hd _U_, const nghttp2_frame_hd *hd,
const uint8_t *data _U_, size_t len _U_, void *user_data _U_) { const uint8_t *data,
size_t len,
void *user_data) {
(void)session;
(void)hd;
(void)data;
(void)len;
(void)user_data;
return NGHTTP2_ERR_CANCEL; return NGHTTP2_ERR_CANCEL;
} }
static int unpack_extension_callback(nghttp2_session *session _U_, static int unpack_extension_callback(nghttp2_session *session, void **payload,
void **payload, const nghttp2_frame_hd *hd,
const nghttp2_frame_hd *hd _U_,
void *user_data) { void *user_data) {
my_user_data *my_data = (my_user_data *)user_data; my_user_data *my_data = (my_user_data *)user_data;
nghttp2_buf *buf = &my_data->scratchbuf; nghttp2_buf *buf = &my_data->scratchbuf;
(void)session;
(void)hd;
*payload = buf; *payload = buf;
return 0; return 0;
} }
static int cancel_unpack_extension_callback(nghttp2_session *session _U_, static int cancel_unpack_extension_callback(nghttp2_session *session,
void **payload _U_, void **payload,
const nghttp2_frame_hd *hd _U_, const nghttp2_frame_hd *hd,
void *user_data _U_) { void *user_data) {
(void)session;
(void)payload;
(void)hd;
(void)user_data;
return NGHTTP2_ERR_CANCEL; return NGHTTP2_ERR_CANCEL;
} }
@ -1444,8 +1575,9 @@ void test_nghttp2_session_recv_headers_with_priority(void) {
static int response_on_begin_frame_callback(nghttp2_session *session, static int response_on_begin_frame_callback(nghttp2_session *session,
const nghttp2_frame_hd *hd, const nghttp2_frame_hd *hd,
void *user_data _U_) { void *user_data) {
int rv; int rv;
(void)user_data;
if (hd->type != NGHTTP2_HEADERS) { if (hd->type != NGHTTP2_HEADERS) {
return 0; return 0;
@ -4380,19 +4512,25 @@ void test_nghttp2_submit_data_read_length_smallest(void) {
} }
static ssize_t submit_data_twice_data_source_read_callback( static ssize_t submit_data_twice_data_source_read_callback(
nghttp2_session *session _U_, int32_t stream_id _U_, uint8_t *buf _U_, nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len,
size_t len, uint32_t *data_flags, nghttp2_data_source *source _U_, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) {
void *user_data _U_) { (void)session;
(void)stream_id;
(void)buf;
(void)source;
(void)user_data;
*data_flags |= NGHTTP2_DATA_FLAG_EOF; *data_flags |= NGHTTP2_DATA_FLAG_EOF;
return (ssize_t)nghttp2_min(len, 16); return (ssize_t)nghttp2_min(len, 16);
} }
static int submit_data_twice_on_frame_send_callback(nghttp2_session *session, static int submit_data_twice_on_frame_send_callback(nghttp2_session *session,
const nghttp2_frame *frame, const nghttp2_frame *frame,
void *user_data _U_) { void *user_data) {
static int called = 0; static int called = 0;
int rv; int rv;
nghttp2_data_provider data_prd; nghttp2_data_provider data_prd;
(void)user_data;
if (called == 0) { if (called == 0) {
called = 1; called = 1;
@ -9252,9 +9390,12 @@ void test_nghttp2_session_defer_then_close(void) {
static int submit_response_on_stream_close(nghttp2_session *session, static int submit_response_on_stream_close(nghttp2_session *session,
int32_t stream_id, int32_t stream_id,
uint32_t error_code _U_, uint32_t error_code,
void *user_data _U_) { void *user_data) {
nghttp2_data_provider data_prd; nghttp2_data_provider data_prd;
(void)error_code;
(void)user_data;
data_prd.read_callback = temporal_failure_data_source_read_callback; data_prd.read_callback = temporal_failure_data_source_read_callback;
// Attempt to submit response or data to the stream being closed // Attempt to submit response or data to the stream being closed

View File

@ -53,16 +53,14 @@ int unpack_frame(nghttp2_frame *frame, const uint8_t *in, size_t len) {
switch (frame->hd.type) { switch (frame->hd.type) {
case NGHTTP2_HEADERS: case NGHTTP2_HEADERS:
payloadoff = ((frame->hd.flags & NGHTTP2_FLAG_PADDED) > 0); payloadoff = ((frame->hd.flags & NGHTTP2_FLAG_PADDED) > 0);
rv = nghttp2_frame_unpack_headers_payload( rv = nghttp2_frame_unpack_headers_payload(&frame->headers,
&frame->headers, payload + payloadoff, payloadlen - payloadoff); payload + payloadoff);
break; break;
case NGHTTP2_PRIORITY: case NGHTTP2_PRIORITY:
nghttp2_frame_unpack_priority_payload(&frame->priority, payload, nghttp2_frame_unpack_priority_payload(&frame->priority, payload);
payloadlen);
break; break;
case NGHTTP2_RST_STREAM: case NGHTTP2_RST_STREAM:
nghttp2_frame_unpack_rst_stream_payload(&frame->rst_stream, payload, nghttp2_frame_unpack_rst_stream_payload(&frame->rst_stream, payload);
payloadlen);
break; break;
case NGHTTP2_SETTINGS: case NGHTTP2_SETTINGS:
rv = nghttp2_frame_unpack_settings_payload2( rv = nghttp2_frame_unpack_settings_payload2(
@ -70,18 +68,17 @@ int unpack_frame(nghttp2_frame *frame, const uint8_t *in, size_t len) {
break; break;
case NGHTTP2_PUSH_PROMISE: case NGHTTP2_PUSH_PROMISE:
rv = nghttp2_frame_unpack_push_promise_payload(&frame->push_promise, rv = nghttp2_frame_unpack_push_promise_payload(&frame->push_promise,
payload, payloadlen); payload);
break; break;
case NGHTTP2_PING: case NGHTTP2_PING:
nghttp2_frame_unpack_ping_payload(&frame->ping, payload, payloadlen); nghttp2_frame_unpack_ping_payload(&frame->ping, payload);
break; break;
case NGHTTP2_GOAWAY: case NGHTTP2_GOAWAY:
nghttp2_frame_unpack_goaway_payload2(&frame->goaway, payload, payloadlen, nghttp2_frame_unpack_goaway_payload2(&frame->goaway, payload, payloadlen,
mem); mem);
break; break;
case NGHTTP2_WINDOW_UPDATE: case NGHTTP2_WINDOW_UPDATE:
nghttp2_frame_unpack_window_update_payload(&frame->window_update, payload, nghttp2_frame_unpack_window_update_payload(&frame->window_update, payload);
payloadlen);
break; break;
case NGHTTP2_ALTSVC: case NGHTTP2_ALTSVC:
assert(payloadlen > 2); assert(payloadlen > 2);