Remove nghttp2_frame_unpack_* functions
This commit is contained in:
parent
dba2406aba
commit
45a9f0b637
|
@ -246,30 +246,6 @@ ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr,
|
|||
return framelen;
|
||||
}
|
||||
|
||||
int nghttp2_frame_unpack_headers_without_nv(nghttp2_headers *frame,
|
||||
const uint8_t *head,
|
||||
size_t headlen,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen)
|
||||
{
|
||||
nghttp2_frame_unpack_frame_hd(&frame->hd, head);
|
||||
/* TODO Return error if header continuation is used for now */
|
||||
if((head[3] & NGHTTP2_FLAG_END_HEADERS) == 0) {
|
||||
return NGHTTP2_ERR_PROTO;
|
||||
}
|
||||
if(head[3] & NGHTTP2_FLAG_PRIORITY) {
|
||||
if(payloadlen < 4) {
|
||||
return NGHTTP2_ERR_FRAME_SIZE_ERROR;
|
||||
}
|
||||
frame->pri = nghttp2_get_uint32(payload) & NGHTTP2_PRIORITY_MASK;
|
||||
} else {
|
||||
frame->pri = NGHTTP2_PRI_DEFAULT;
|
||||
}
|
||||
frame->nva = NULL;
|
||||
frame->nvlen = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nghttp2_frame_unpack_headers_payload(nghttp2_headers *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen)
|
||||
|
@ -304,18 +280,6 @@ ssize_t nghttp2_frame_pack_priority(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|||
return framelen;
|
||||
}
|
||||
|
||||
int nghttp2_frame_unpack_priority(nghttp2_priority *frame,
|
||||
const uint8_t *head, size_t headlen,
|
||||
const uint8_t *payload, size_t payloadlen)
|
||||
{
|
||||
if(payloadlen != 4) {
|
||||
return NGHTTP2_ERR_FRAME_SIZE_ERROR;
|
||||
}
|
||||
nghttp2_frame_unpack_frame_hd(&frame->hd, head);
|
||||
frame->pri = nghttp2_get_uint32(payload) & NGHTTP2_PRIORITY_MASK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nghttp2_frame_unpack_priority_payload(nghttp2_priority *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen)
|
||||
|
@ -338,18 +302,6 @@ ssize_t nghttp2_frame_pack_rst_stream(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|||
return framelen;
|
||||
}
|
||||
|
||||
int nghttp2_frame_unpack_rst_stream(nghttp2_rst_stream *frame,
|
||||
const uint8_t *head, size_t headlen,
|
||||
const uint8_t *payload, size_t payloadlen)
|
||||
{
|
||||
if(payloadlen != 4) {
|
||||
return NGHTTP2_ERR_FRAME_SIZE_ERROR;
|
||||
}
|
||||
nghttp2_frame_unpack_frame_hd(&frame->hd, head);
|
||||
frame->error_code = nghttp2_get_uint32(payload);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nghttp2_frame_unpack_rst_stream_payload(nghttp2_rst_stream *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen)
|
||||
|
@ -384,28 +336,9 @@ size_t nghttp2_frame_pack_settings_payload(uint8_t *buf,
|
|||
return 8 * niv;
|
||||
}
|
||||
|
||||
int nghttp2_frame_unpack_settings(nghttp2_settings *frame,
|
||||
const uint8_t *head, size_t headlen,
|
||||
const uint8_t *payload, size_t payloadlen)
|
||||
{
|
||||
int rv;
|
||||
nghttp2_frame_unpack_frame_hd(&frame->hd, head);
|
||||
if((payloadlen & 0x7) ||
|
||||
((frame->hd.flags & NGHTTP2_FLAG_ACK) && payloadlen > 0)) {
|
||||
return NGHTTP2_ERR_FRAME_SIZE_ERROR;
|
||||
}
|
||||
|
||||
rv = nghttp2_frame_unpack_settings_payload(&frame->iv, &frame->niv,
|
||||
payload, payloadlen);
|
||||
if(rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nghttp2_frame_unpack_settings_payload2(nghttp2_settings *frame,
|
||||
nghttp2_settings_entry *iv,
|
||||
size_t niv)
|
||||
int nghttp2_frame_unpack_settings_payload(nghttp2_settings *frame,
|
||||
nghttp2_settings_entry *iv,
|
||||
size_t niv)
|
||||
{
|
||||
size_t payloadlen = niv * sizeof(nghttp2_settings_entry);
|
||||
|
||||
|
@ -426,10 +359,10 @@ void nghttp2_frame_unpack_settings_entry(nghttp2_settings_entry *iv,
|
|||
iv->value = nghttp2_get_uint32(&payload[4]);
|
||||
}
|
||||
|
||||
int nghttp2_frame_unpack_settings_payload(nghttp2_settings_entry **iv_ptr,
|
||||
size_t *niv_ptr,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen)
|
||||
int nghttp2_frame_unpack_settings_payload2(nghttp2_settings_entry **iv_ptr,
|
||||
size_t *niv_ptr,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen)
|
||||
{
|
||||
size_t i;
|
||||
*niv_ptr = payloadlen / 8;
|
||||
|
@ -472,27 +405,6 @@ ssize_t nghttp2_frame_pack_push_promise(uint8_t **buf_ptr,
|
|||
return framelen;
|
||||
}
|
||||
|
||||
int nghttp2_frame_unpack_push_promise_without_nv(nghttp2_push_promise *frame,
|
||||
const uint8_t *head,
|
||||
size_t headlen,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen)
|
||||
{
|
||||
nghttp2_frame_unpack_frame_hd(&frame->hd, head);
|
||||
/* TODO Return error if header continuation is used for now */
|
||||
if((head[3] & NGHTTP2_FLAG_END_PUSH_PROMISE) == 0) {
|
||||
return NGHTTP2_ERR_PROTO;
|
||||
}
|
||||
if(payloadlen < 4) {
|
||||
return NGHTTP2_ERR_FRAME_SIZE_ERROR;
|
||||
}
|
||||
frame->promised_stream_id = nghttp2_get_uint32(payload) &
|
||||
NGHTTP2_STREAM_ID_MASK;
|
||||
frame->nva = NULL;
|
||||
frame->nvlen = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nghttp2_frame_unpack_push_promise_payload(nghttp2_push_promise *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen)
|
||||
|
@ -523,18 +435,6 @@ ssize_t nghttp2_frame_pack_ping(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|||
return framelen;
|
||||
}
|
||||
|
||||
int nghttp2_frame_unpack_ping(nghttp2_ping *frame,
|
||||
const uint8_t *head, size_t headlen,
|
||||
const uint8_t *payload, size_t payloadlen)
|
||||
{
|
||||
if(payloadlen != 8) {
|
||||
return NGHTTP2_ERR_FRAME_SIZE_ERROR;
|
||||
}
|
||||
nghttp2_frame_unpack_frame_hd(&frame->hd, head);
|
||||
memcpy(frame->opaque_data, payload, sizeof(frame->opaque_data));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nghttp2_frame_unpack_ping_payload(nghttp2_ping *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen)
|
||||
|
@ -559,29 +459,6 @@ ssize_t nghttp2_frame_pack_goaway(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|||
return framelen;
|
||||
}
|
||||
|
||||
int nghttp2_frame_unpack_goaway(nghttp2_goaway *frame,
|
||||
const uint8_t *head, size_t headlen,
|
||||
const uint8_t *payload, size_t payloadlen)
|
||||
{
|
||||
nghttp2_frame_unpack_frame_hd(&frame->hd, head);
|
||||
if(payloadlen < 8) {
|
||||
return NGHTTP2_ERR_FRAME_SIZE_ERROR;
|
||||
}
|
||||
frame->last_stream_id = nghttp2_get_uint32(payload) & NGHTTP2_STREAM_ID_MASK;
|
||||
frame->error_code = nghttp2_get_uint32(payload+4);
|
||||
frame->opaque_data_len = payloadlen - 8;
|
||||
if(frame->opaque_data_len == 0) {
|
||||
frame->opaque_data = NULL;
|
||||
} else {
|
||||
frame->opaque_data = malloc(frame->opaque_data_len);
|
||||
if(frame->opaque_data == NULL) {
|
||||
return NGHTTP2_ERR_NOMEM;
|
||||
}
|
||||
memcpy(frame->opaque_data, &payload[8], frame->opaque_data_len);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nghttp2_frame_unpack_goaway_payload(nghttp2_goaway *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen)
|
||||
|
@ -608,20 +485,6 @@ ssize_t nghttp2_frame_pack_window_update(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|||
return framelen;
|
||||
}
|
||||
|
||||
int nghttp2_frame_unpack_window_update(nghttp2_window_update *frame,
|
||||
const uint8_t *head, size_t headlen,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen)
|
||||
{
|
||||
if(payloadlen != 4) {
|
||||
return NGHTTP2_ERR_FRAME_SIZE_ERROR;
|
||||
}
|
||||
nghttp2_frame_unpack_frame_hd(&frame->hd, head);
|
||||
frame->window_size_increment = nghttp2_get_uint32(payload) &
|
||||
NGHTTP2_WINDOW_SIZE_INCREMENT_MASK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nghttp2_frame_unpack_window_update_payload(nghttp2_window_update *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen)
|
||||
|
|
|
@ -116,35 +116,6 @@ ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr,
|
|||
nghttp2_headers *frame,
|
||||
nghttp2_hd_context *deflater);
|
||||
|
||||
/*
|
||||
* Unpacks HEADERS frame byte sequence into |frame|. The control
|
||||
* frame header is given in |head| with |headlen| length. In the spec,
|
||||
* headlen is 8 bytes. |payload| is the data after frame header and
|
||||
* just before name/value header block.
|
||||
*
|
||||
* The |inflater| inflates name/value header block.
|
||||
*
|
||||
* This function also validates the name/value pairs. If unpacking
|
||||
* succeeds but validation fails, it is indicated by returning
|
||||
* NGHTTP2_ERR_INVALID_HEADER_BLOCK.
|
||||
*
|
||||
* This function returns 0 if it succeeds or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_HEADER_COMP
|
||||
* The inflate operation failed.
|
||||
* NGHTTP2_ERR_INVALID_HEADER_BLOCK
|
||||
* Unpacking succeeds but the header block is invalid.
|
||||
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
||||
* The input length is invalid
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_frame_unpack_headers(nghttp2_headers *frame,
|
||||
const uint8_t *head, size_t headlen,
|
||||
const uint8_t *payload, size_t payloadlen,
|
||||
nghttp2_hd_context *inflater);
|
||||
|
||||
/*
|
||||
* Unpacks HEADERS frame byte sequence into |frame|. This function
|
||||
* only unapcks bytes that come before name/value header block.
|
||||
|
@ -152,15 +123,9 @@ int nghttp2_frame_unpack_headers(nghttp2_headers *frame,
|
|||
* This function returns 0 if it succeeds or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
||||
* The input length is invalid
|
||||
* NGHTTP2_ERR_PROTO
|
||||
* TODO END_HEADERS flag is not set
|
||||
*/
|
||||
int nghttp2_frame_unpack_headers_without_nv(nghttp2_headers *frame,
|
||||
const uint8_t *head,
|
||||
size_t headlen,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
||||
int nghttp2_frame_unpack_headers_payload(nghttp2_headers *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
@ -182,17 +147,7 @@ ssize_t nghttp2_frame_pack_priority(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|||
|
||||
/*
|
||||
* Unpacks PRIORITY wire format into |frame|.
|
||||
*
|
||||
* This function returns 0 if it succeeds or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
||||
* The input length is invalid
|
||||
*/
|
||||
int nghttp2_frame_unpack_priority(nghttp2_priority *frame,
|
||||
const uint8_t *head, size_t headlen,
|
||||
const uint8_t *payload, size_t payloadlen);
|
||||
|
||||
void nghttp2_frame_unpack_priority_payload(nghttp2_priority *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
@ -215,17 +170,7 @@ ssize_t nghttp2_frame_pack_rst_stream(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|||
|
||||
/*
|
||||
* Unpacks RST_STREAM frame byte sequence into |frame|.
|
||||
*
|
||||
* This function returns 0 if it succeeds or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
||||
* The input length is invalid
|
||||
*/
|
||||
int nghttp2_frame_unpack_rst_stream(nghttp2_rst_stream *frame,
|
||||
const uint8_t *head, size_t headlen,
|
||||
const uint8_t *payload, size_t payloadlen);
|
||||
|
||||
void nghttp2_frame_unpack_rst_stream_payload(nghttp2_rst_stream *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
@ -255,28 +200,22 @@ size_t nghttp2_frame_pack_settings_payload(uint8_t *buf,
|
|||
const nghttp2_settings_entry *iv,
|
||||
size_t niv);
|
||||
|
||||
void nghttp2_frame_unpack_settings_entry(nghttp2_settings_entry *iv,
|
||||
const uint8_t *payload);
|
||||
|
||||
/*
|
||||
* Unpacks SETTINGS wire format into |frame|.
|
||||
* Makes a copy of |iv| in frame->settings.iv. The |niv| is assigned
|
||||
* to frame->settings.niv.
|
||||
*
|
||||
* This function returns 0 if it succeeds or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
||||
* The input length is invalid
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_frame_unpack_settings(nghttp2_settings *frame,
|
||||
const uint8_t *head, size_t headlen,
|
||||
const uint8_t *payload, size_t payloadlen);
|
||||
|
||||
|
||||
void nghttp2_frame_unpack_settings_entry(nghttp2_settings_entry *iv,
|
||||
const uint8_t *payload);
|
||||
|
||||
int nghttp2_frame_unpack_settings_payload2(nghttp2_settings *frame,
|
||||
nghttp2_settings_entry *iv,
|
||||
size_t niv);
|
||||
int nghttp2_frame_unpack_settings_payload(nghttp2_settings *frame,
|
||||
nghttp2_settings_entry *iv,
|
||||
size_t niv);
|
||||
|
||||
/*
|
||||
* Unpacks SETTINGS payload into |*iv_ptr|. The number of entries are
|
||||
|
@ -290,10 +229,10 @@ int nghttp2_frame_unpack_settings_payload2(nghttp2_settings *frame,
|
|||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_frame_unpack_settings_payload(nghttp2_settings_entry **iv_ptr,
|
||||
size_t *niv_ptr,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
int nghttp2_frame_unpack_settings_payload2(nghttp2_settings_entry **iv_ptr,
|
||||
size_t *niv_ptr,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
||||
/*
|
||||
* Packs PUSH_PROMISE frame |frame| in wire format and store it in
|
||||
|
@ -320,36 +259,6 @@ ssize_t nghttp2_frame_pack_push_promise(uint8_t **buf_ptr,
|
|||
nghttp2_push_promise *frame,
|
||||
nghttp2_hd_context *deflater);
|
||||
|
||||
/*
|
||||
* Unpacks PUSH_PROMISE frame byte sequence into |frame|. The control
|
||||
* frame header is given in |head| with |headlen| length. In the spec,
|
||||
* headlen is 8 bytes. |payload| is the data after frame header and
|
||||
* just before name/value header block.
|
||||
*
|
||||
* The |inflater| inflates name/value header block.
|
||||
*
|
||||
* This function also validates the name/value pairs. If unpacking
|
||||
* succeeds but validation fails, it is indicated by returning
|
||||
* NGHTTP2_ERR_INVALID_HEADER_BLOCK.
|
||||
*
|
||||
* This function returns 0 if it succeeds or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_HEADER_COMP
|
||||
* The inflate operation failed.
|
||||
* NGHTTP2_ERR_INVALID_HEADER_BLOCK
|
||||
* Unpacking succeeds but the header block is invalid.
|
||||
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
||||
* The input length is invalid
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_frame_unpack_push_promise(nghttp2_push_promise *frame,
|
||||
const uint8_t *head, size_t headlen,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen,
|
||||
nghttp2_hd_context *inflater);
|
||||
|
||||
/*
|
||||
* Unpacks PUSH_PROMISE frame byte sequence into |frame|. This function
|
||||
* only unapcks bytes that come before name/value header block.
|
||||
|
@ -357,15 +266,9 @@ int nghttp2_frame_unpack_push_promise(nghttp2_push_promise *frame,
|
|||
* This function returns 0 if it succeeds or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
||||
* The input length is invalid
|
||||
* NGHTTP2_ERR_PROTO
|
||||
* TODO END_HEADERS flag is not set
|
||||
*/
|
||||
int nghttp2_frame_unpack_push_promise_without_nv(nghttp2_push_promise *frame,
|
||||
const uint8_t *head,
|
||||
size_t headlen,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
||||
int nghttp2_frame_unpack_push_promise_payload(nghttp2_push_promise *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
@ -387,17 +290,7 @@ ssize_t nghttp2_frame_pack_ping(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|||
|
||||
/*
|
||||
* Unpacks PING wire format into |frame|.
|
||||
*
|
||||
* This function returns 0 if it succeeds or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
||||
* The input length is invalid
|
||||
*/
|
||||
int nghttp2_frame_unpack_ping(nghttp2_ping *frame,
|
||||
const uint8_t *head, size_t headlen,
|
||||
const uint8_t *payload, size_t payloadlen);
|
||||
|
||||
void nghttp2_frame_unpack_ping_payload(nghttp2_ping *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
@ -419,19 +312,7 @@ ssize_t nghttp2_frame_pack_goaway(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|||
|
||||
/*
|
||||
* Unpacks GOAWAY wire format into |frame|.
|
||||
*
|
||||
* This function returns 0 if it succeeds or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
||||
* The input length is invalid
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_frame_unpack_goaway(nghttp2_goaway *frame,
|
||||
const uint8_t *head, size_t headlen,
|
||||
const uint8_t *payload, size_t payloadlen);
|
||||
|
||||
void nghttp2_frame_unpack_goaway_payload(nghttp2_goaway *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
@ -453,18 +334,7 @@ ssize_t nghttp2_frame_pack_window_update(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|||
|
||||
/*
|
||||
* Unpacks WINDOW_UPDATE frame byte sequence into |frame|.
|
||||
*
|
||||
* This function returns 0 if it succeeds or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
||||
* The input length is invalid
|
||||
*/
|
||||
int nghttp2_frame_unpack_window_update(nghttp2_window_update *frame,
|
||||
const uint8_t *head, size_t headlen,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
||||
void nghttp2_frame_unpack_window_update_payload(nghttp2_window_update *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
|
|
@ -2828,8 +2828,8 @@ static int session_process_settings_frame(nghttp2_session *session)
|
|||
nghttp2_inbound_frame *iframe = &session->iframe;
|
||||
nghttp2_frame *frame = &iframe->frame;
|
||||
|
||||
rv = nghttp2_frame_unpack_settings_payload2(&frame->settings,
|
||||
iframe->iv, iframe->niv);
|
||||
rv = nghttp2_frame_unpack_settings_payload(&frame->settings,
|
||||
iframe->iv, iframe->niv);
|
||||
if(rv != 0) {
|
||||
assert(nghttp2_is_fatal(rv));
|
||||
return rv;
|
||||
|
@ -4074,8 +4074,8 @@ int nghttp2_session_upgrade(nghttp2_session *session,
|
|||
if(settings_payloadlen % 8) {
|
||||
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
rv = nghttp2_frame_unpack_settings_payload(&iv, &niv, settings_payload,
|
||||
settings_payloadlen);
|
||||
rv = nghttp2_frame_unpack_settings_payload2(&iv, &niv, settings_payload,
|
||||
settings_payloadlen);
|
||||
if(rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -90,8 +90,7 @@ void test_nghttp2_frame_pack_headers()
|
|||
1 << 20, nva, nvlen);
|
||||
framelen = nghttp2_frame_pack_headers(&buf, &buflen, &frame, &deflater);
|
||||
|
||||
CU_ASSERT(0 == unpack_frame((nghttp2_frame*)&oframe, NGHTTP2_HEADERS,
|
||||
buf, framelen));
|
||||
CU_ASSERT(0 == unpack_frame((nghttp2_frame*)&oframe, buf, framelen));
|
||||
check_frame_header(framelen - NGHTTP2_FRAME_HEAD_LENGTH, NGHTTP2_HEADERS,
|
||||
NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS,
|
||||
1000000007, &oframe.hd);
|
||||
|
@ -113,8 +112,7 @@ void test_nghttp2_frame_pack_headers()
|
|||
frame.hd.flags |= NGHTTP2_FLAG_PRIORITY;
|
||||
framelen = nghttp2_frame_pack_headers(&buf, &buflen, &frame, &deflater);
|
||||
|
||||
CU_ASSERT(0 == unpack_frame((nghttp2_frame*)&oframe, NGHTTP2_HEADERS,
|
||||
buf, framelen));
|
||||
CU_ASSERT(0 == unpack_frame((nghttp2_frame*)&oframe, buf, framelen));
|
||||
check_frame_header(framelen - NGHTTP2_FRAME_HEAD_LENGTH, NGHTTP2_HEADERS,
|
||||
NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS |
|
||||
NGHTTP2_FLAG_PRIORITY,
|
||||
|
@ -183,11 +181,7 @@ void test_nghttp2_frame_pack_priority(void)
|
|||
ssize_t framelen;
|
||||
nghttp2_frame_priority_init(&frame, 1000000007, 1 << 30);
|
||||
framelen = nghttp2_frame_pack_priority(&buf, &buflen, &frame);
|
||||
CU_ASSERT(0 == nghttp2_frame_unpack_priority
|
||||
(&oframe,
|
||||
&buf[0], NGHTTP2_FRAME_HEAD_LENGTH,
|
||||
&buf[NGHTTP2_FRAME_HEAD_LENGTH],
|
||||
framelen - NGHTTP2_FRAME_HEAD_LENGTH));
|
||||
CU_ASSERT(0 == unpack_frame((nghttp2_frame*)&oframe, buf, framelen));
|
||||
check_frame_header(4, NGHTTP2_PRIORITY, NGHTTP2_FLAG_NONE, 1000000007,
|
||||
&oframe.hd);
|
||||
CU_ASSERT(1 << 30 == oframe.pri);
|
||||
|
@ -204,11 +198,7 @@ void test_nghttp2_frame_pack_rst_stream(void)
|
|||
ssize_t framelen;
|
||||
nghttp2_frame_rst_stream_init(&frame, 1000000007, NGHTTP2_PROTOCOL_ERROR);
|
||||
framelen = nghttp2_frame_pack_rst_stream(&buf, &buflen, &frame);
|
||||
CU_ASSERT(0 == nghttp2_frame_unpack_rst_stream
|
||||
(&oframe,
|
||||
&buf[0], NGHTTP2_FRAME_HEAD_LENGTH,
|
||||
&buf[NGHTTP2_FRAME_HEAD_LENGTH],
|
||||
framelen - NGHTTP2_FRAME_HEAD_LENGTH));
|
||||
CU_ASSERT(0 == unpack_frame((nghttp2_frame*)&oframe, buf, framelen));
|
||||
check_frame_header(4, NGHTTP2_RST_STREAM, NGHTTP2_FLAG_NONE, 1000000007,
|
||||
&oframe.hd);
|
||||
CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == oframe.error_code);
|
||||
|
@ -236,13 +226,7 @@ void test_nghttp2_frame_pack_settings()
|
|||
nghttp2_frame_iv_copy(iv, 3), 3);
|
||||
framelen = nghttp2_frame_pack_settings(&buf, &buflen, &frame);
|
||||
CU_ASSERT(NGHTTP2_FRAME_HEAD_LENGTH+3*8 == framelen);
|
||||
|
||||
CU_ASSERT(0 == nghttp2_frame_unpack_settings
|
||||
(&oframe,
|
||||
&buf[0], NGHTTP2_FRAME_HEAD_LENGTH,
|
||||
&buf[NGHTTP2_FRAME_HEAD_LENGTH],
|
||||
framelen - NGHTTP2_FRAME_HEAD_LENGTH));
|
||||
|
||||
CU_ASSERT(0 == unpack_frame((nghttp2_frame*)&oframe, buf, framelen));
|
||||
check_frame_header(3*8, NGHTTP2_SETTINGS, NGHTTP2_FLAG_NONE, 0, &oframe.hd);
|
||||
CU_ASSERT(3 == oframe.niv);
|
||||
for(i = 0; i < 3; ++i) {
|
||||
|
@ -276,8 +260,7 @@ void test_nghttp2_frame_pack_push_promise()
|
|||
1000000007, (1U << 31) - 1, nva, nvlen);
|
||||
framelen = nghttp2_frame_pack_push_promise(&buf, &buflen, &frame, &deflater);
|
||||
|
||||
CU_ASSERT(0 == unpack_frame((nghttp2_frame*)&oframe, NGHTTP2_PUSH_PROMISE,
|
||||
buf, framelen));
|
||||
CU_ASSERT(0 == unpack_frame((nghttp2_frame*)&oframe, buf, framelen));
|
||||
check_frame_header(framelen - NGHTTP2_FRAME_HEAD_LENGTH,
|
||||
NGHTTP2_PUSH_PROMISE,
|
||||
NGHTTP2_FLAG_END_PUSH_PROMISE, 1000000007, &oframe.hd);
|
||||
|
@ -307,11 +290,7 @@ void test_nghttp2_frame_pack_ping(void)
|
|||
const uint8_t opaque_data[] = "01234567";
|
||||
nghttp2_frame_ping_init(&frame, NGHTTP2_FLAG_ACK, opaque_data);
|
||||
framelen = nghttp2_frame_pack_ping(&buf, &buflen, &frame);
|
||||
CU_ASSERT(0 == nghttp2_frame_unpack_ping
|
||||
(&oframe,
|
||||
&buf[0], NGHTTP2_FRAME_HEAD_LENGTH,
|
||||
&buf[NGHTTP2_FRAME_HEAD_LENGTH],
|
||||
framelen - NGHTTP2_FRAME_HEAD_LENGTH));
|
||||
CU_ASSERT(0 == unpack_frame((nghttp2_frame*)&oframe, buf, framelen));
|
||||
check_frame_header(8, NGHTTP2_PING, NGHTTP2_FLAG_ACK, 0, &oframe.hd);
|
||||
CU_ASSERT(memcmp(opaque_data, oframe.opaque_data, sizeof(opaque_data) - 1)
|
||||
== 0);
|
||||
|
@ -328,20 +307,20 @@ void test_nghttp2_frame_pack_goaway()
|
|||
ssize_t framelen;
|
||||
size_t opaque_data_len = 16;
|
||||
uint8_t *opaque_data = malloc(opaque_data_len);
|
||||
|
||||
memcpy(opaque_data, "0123456789abcdef", opaque_data_len);
|
||||
nghttp2_frame_goaway_init(&frame, 1000000007, NGHTTP2_PROTOCOL_ERROR,
|
||||
opaque_data, opaque_data_len);
|
||||
framelen = nghttp2_frame_pack_goaway(&buf, &buflen, &frame);
|
||||
CU_ASSERT(0 == nghttp2_frame_unpack_goaway
|
||||
(&oframe,
|
||||
&buf[0], NGHTTP2_FRAME_HEAD_LENGTH,
|
||||
&buf[NGHTTP2_FRAME_HEAD_LENGTH],
|
||||
framelen-NGHTTP2_FRAME_HEAD_LENGTH));
|
||||
CU_ASSERT(0 == unpack_frame((nghttp2_frame*)&oframe, buf, framelen));
|
||||
check_frame_header(24, NGHTTP2_GOAWAY, NGHTTP2_FLAG_NONE, 0, &oframe.hd);
|
||||
CU_ASSERT(1000000007 == oframe.last_stream_id);
|
||||
CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == oframe.error_code);
|
||||
CU_ASSERT(opaque_data_len == oframe.opaque_data_len);
|
||||
CU_ASSERT(memcmp(opaque_data, oframe.opaque_data, opaque_data_len) == 0);
|
||||
/* TODO Currently, opaque data is discarded */
|
||||
CU_ASSERT(0 == oframe.opaque_data_len);
|
||||
CU_ASSERT(NULL == oframe.opaque_data);
|
||||
/* CU_ASSERT(opaque_data_len == oframe.opaque_data_len); */
|
||||
/* CU_ASSERT(memcmp(opaque_data, oframe.opaque_data, opaque_data_len) == 0); */
|
||||
free(buf);
|
||||
nghttp2_frame_goaway_free(&oframe);
|
||||
nghttp2_frame_goaway_free(&frame);
|
||||
|
@ -353,15 +332,12 @@ void test_nghttp2_frame_pack_window_update(void)
|
|||
uint8_t *buf = NULL;
|
||||
size_t buflen = 0;
|
||||
ssize_t framelen;
|
||||
|
||||
nghttp2_frame_window_update_init(&frame, NGHTTP2_FLAG_NONE,
|
||||
1000000007, 4096);
|
||||
framelen = nghttp2_frame_pack_window_update(&buf, &buflen,
|
||||
&frame);
|
||||
CU_ASSERT(0 == nghttp2_frame_unpack_window_update
|
||||
(&oframe,
|
||||
&buf[0], NGHTTP2_FRAME_HEAD_LENGTH,
|
||||
&buf[NGHTTP2_FRAME_HEAD_LENGTH],
|
||||
framelen - NGHTTP2_FRAME_HEAD_LENGTH));
|
||||
CU_ASSERT(0 == unpack_frame((nghttp2_frame*)&oframe, buf, framelen));
|
||||
check_frame_header(4, NGHTTP2_WINDOW_UPDATE, NGHTTP2_FLAG_NONE,
|
||||
1000000007, &oframe.hd);
|
||||
CU_ASSERT(4096 == oframe.window_size_increment);
|
||||
|
|
|
@ -2062,7 +2062,7 @@ void test_nghttp2_submit_request_without_data(void)
|
|||
CU_ASSERT(OB_CTRL(item)->hd.flags & NGHTTP2_FLAG_END_STREAM);
|
||||
|
||||
CU_ASSERT(0 == nghttp2_session_send(session));
|
||||
CU_ASSERT(0 == unpack_frame(&frame, NGHTTP2_HEADERS, acc.buf, acc.length));
|
||||
CU_ASSERT(0 == unpack_frame(&frame, acc.buf, acc.length));
|
||||
|
||||
inflate_hd(&inflater, &out, acc.buf + 8, acc.length - 8);
|
||||
|
||||
|
@ -2136,7 +2136,7 @@ void test_nghttp2_submit_response_without_data(void)
|
|||
CU_ASSERT(OB_CTRL(item)->hd.flags & NGHTTP2_FLAG_END_STREAM);
|
||||
|
||||
CU_ASSERT(0 == nghttp2_session_send(session));
|
||||
CU_ASSERT(0 == unpack_frame(&frame, NGHTTP2_HEADERS, acc.buf, acc.length));
|
||||
CU_ASSERT(0 == unpack_frame(&frame, acc.buf, acc.length));
|
||||
|
||||
inflate_hd(&inflater, &out, acc.buf + 8, acc.length - 8);
|
||||
|
||||
|
@ -2326,7 +2326,7 @@ void test_nghttp2_submit_headers(void)
|
|||
CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type);
|
||||
CU_ASSERT(stream->shut_flags & NGHTTP2_SHUT_WR);
|
||||
|
||||
CU_ASSERT(0 == unpack_frame(&frame, NGHTTP2_HEADERS, acc.buf, acc.length));
|
||||
CU_ASSERT(0 == unpack_frame(&frame, acc.buf, acc.length));
|
||||
|
||||
inflate_hd(&inflater, &out, acc.buf + 8, acc.length - 8);
|
||||
|
||||
|
@ -3824,8 +3824,8 @@ void test_nghttp2_pack_settings_payload(void)
|
|||
|
||||
len = nghttp2_pack_settings_payload(buf, sizeof(buf), iv, 2);
|
||||
CU_ASSERT(16 == len);
|
||||
CU_ASSERT(0 == nghttp2_frame_unpack_settings_payload(&resiv, &resniv,
|
||||
buf, len));
|
||||
CU_ASSERT(0 == nghttp2_frame_unpack_settings_payload2(&resiv, &resniv,
|
||||
buf, len));
|
||||
CU_ASSERT(2 == resniv);
|
||||
CU_ASSERT(NGHTTP2_SETTINGS_FLOW_CONTROL_OPTIONS == resiv[0].settings_id);
|
||||
CU_ASSERT(1 == resiv[0].value);
|
||||
|
|
|
@ -28,27 +28,45 @@
|
|||
|
||||
#include <CUnit/CUnit.h>
|
||||
|
||||
/* #include "nghttp2_session.h" */
|
||||
|
||||
ssize_t unpack_frame(nghttp2_frame *frame,
|
||||
nghttp2_frame_type type,
|
||||
const uint8_t *in, size_t len)
|
||||
int unpack_frame(nghttp2_frame *frame, const uint8_t *in, size_t len)
|
||||
{
|
||||
ssize_t rv;
|
||||
switch(type) {
|
||||
ssize_t rv = 0;
|
||||
const uint8_t *payload = in + NGHTTP2_FRAME_HEAD_LENGTH;
|
||||
size_t payloadlen = len - NGHTTP2_FRAME_HEAD_LENGTH;
|
||||
nghttp2_frame_unpack_frame_hd(&frame->hd, in);
|
||||
switch(frame->hd.type) {
|
||||
case NGHTTP2_HEADERS:
|
||||
rv = nghttp2_frame_unpack_headers_without_nv
|
||||
((nghttp2_headers*)frame,
|
||||
&in[0], NGHTTP2_FRAME_HEAD_LENGTH,
|
||||
&in[NGHTTP2_FRAME_HEAD_LENGTH],
|
||||
len - NGHTTP2_FRAME_HEAD_LENGTH);
|
||||
rv = nghttp2_frame_unpack_headers_payload
|
||||
(&frame->headers, payload, payloadlen);
|
||||
break;
|
||||
case NGHTTP2_PRIORITY:
|
||||
nghttp2_frame_unpack_priority_payload
|
||||
(&frame->priority, payload, payloadlen);
|
||||
break;
|
||||
case NGHTTP2_RST_STREAM:
|
||||
nghttp2_frame_unpack_rst_stream_payload
|
||||
(&frame->rst_stream, payload, payloadlen);
|
||||
break;
|
||||
case NGHTTP2_SETTINGS:
|
||||
rv = nghttp2_frame_unpack_settings_payload2(&frame->settings.iv,
|
||||
&frame->settings.niv,
|
||||
payload, payloadlen);
|
||||
break;
|
||||
case NGHTTP2_PUSH_PROMISE:
|
||||
rv = nghttp2_frame_unpack_push_promise_without_nv
|
||||
((nghttp2_push_promise*)frame,
|
||||
&in[0], NGHTTP2_FRAME_HEAD_LENGTH,
|
||||
&in[NGHTTP2_FRAME_HEAD_LENGTH],
|
||||
len - NGHTTP2_FRAME_HEAD_LENGTH);
|
||||
rv = nghttp2_frame_unpack_push_promise_payload
|
||||
(&frame->push_promise, payload, payloadlen);
|
||||
break;
|
||||
case NGHTTP2_PING:
|
||||
nghttp2_frame_unpack_ping_payload
|
||||
(&frame->ping, payload, payloadlen);
|
||||
break;
|
||||
case NGHTTP2_GOAWAY:
|
||||
nghttp2_frame_unpack_goaway_payload
|
||||
(&frame->goaway, payload, payloadlen);
|
||||
break;
|
||||
case NGHTTP2_WINDOW_UPDATE:
|
||||
nghttp2_frame_unpack_window_update_payload
|
||||
(&frame->window_update, payload, payloadlen);
|
||||
break;
|
||||
default:
|
||||
/* Must not be reachable */
|
||||
|
|
|
@ -36,9 +36,7 @@
|
|||
{ (uint8_t*)NAME, (uint8_t*)VALUE, strlen(NAME), strlen(VALUE) }
|
||||
#define ARRLEN(ARR) (sizeof(ARR)/sizeof(ARR[0]))
|
||||
|
||||
ssize_t unpack_frame(nghttp2_frame *frame,
|
||||
nghttp2_frame_type type,
|
||||
const uint8_t *in, size_t len);
|
||||
int unpack_frame(nghttp2_frame *frame, const uint8_t *in, size_t len);
|
||||
|
||||
int strmemeq(const char *a, const uint8_t *b, size_t bn);
|
||||
|
||||
|
|
Loading…
Reference in New Issue