Handle incoming PAD_HIGH and PAD_LOW in inbound_frame_handle_padding

This commit is contained in:
Tatsuhiro Tsujikawa 2014-02-08 18:02:57 +09:00
parent 2ff3d97b2e
commit e9d1ba2539
1 changed files with 32 additions and 15 deletions

View File

@ -3313,6 +3313,29 @@ static int inbound_frame_set_settings_entry(nghttp2_inbound_frame *iframe)
return 0; return 0;
} }
/*
* Checks PAD_HIGH and PAD_LOW flags and set next state
* accordingly. If padding is set, this function returns 1. If no
* padding is set, this function returns 0. On error, returns -1.
*/
static int inbound_frame_handle_pad(nghttp2_inbound_frame *iframe)
{
if(iframe->frame.hd.flags & NGHTTP2_FLAG_PAD_HIGH) {
if((iframe->frame.hd.flags & NGHTTP2_FLAG_PAD_LOW) == 0) {
return -1;
}
iframe->state = NGHTTP2_IB_READ_NBYTE;
iframe->left = 2;
return 1;
}
if(iframe->frame.hd.flags & NGHTTP2_FLAG_PAD_LOW) {
iframe->state = NGHTTP2_IB_READ_NBYTE;
iframe->left = 1;
return 1;
}
return 0;
}
ssize_t nghttp2_session_mem_recv(nghttp2_session *session, ssize_t nghttp2_session_mem_recv(nghttp2_session *session,
const uint8_t *in, size_t inlen) const uint8_t *in, size_t inlen)
{ {
@ -3354,26 +3377,20 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session,
if(nghttp2_is_fatal(rv)) { if(nghttp2_is_fatal(rv)) {
return rv; return rv;
} }
if(iframe->frame.hd.flags & NGHTTP2_FLAG_PAD_HIGH) { rv = inbound_frame_handle_pad(iframe);
if((iframe->frame.hd.flags & NGHTTP2_FLAG_PAD_LOW) == 0) { if(rv < 0) {
iframe->state = NGHTTP2_IB_IGN_DATA; iframe->state = NGHTTP2_IB_IGN_DATA;
rv = nghttp2_session_terminate_session(session, rv = nghttp2_session_terminate_session(session,
NGHTTP2_PROTOCOL_ERROR); NGHTTP2_PROTOCOL_ERROR);
if(nghttp2_is_fatal(rv)) { if(nghttp2_is_fatal(rv)) {
return rv; return rv;
}
break;
} }
iframe->state = NGHTTP2_IB_READ_NBYTE;
iframe->left = 2;
break; break;
} }
if(iframe->frame.hd.flags & NGHTTP2_FLAG_PAD_LOW) { if(rv == 0) {
iframe->state = NGHTTP2_IB_READ_NBYTE; iframe->state = NGHTTP2_IB_READ_DATA;
iframe->left = 1;
break; break;
} }
iframe->state = NGHTTP2_IB_READ_DATA;
break; break;
} }
case NGHTTP2_HEADERS: case NGHTTP2_HEADERS: