From 2aa84019c7044b1cbd5493e516a09df33d1a230a Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 22 May 2014 21:36:12 +0900 Subject: [PATCH] Define constants for ALTSVC frame parsing --- lib/nghttp2_frame.c | 3 +-- lib/nghttp2_frame.h | 10 ++++++++++ lib/nghttp2_session.c | 6 +++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/nghttp2_frame.c b/lib/nghttp2_frame.c index 59f78115..1595c49a 100644 --- a/lib/nghttp2_frame.c +++ b/lib/nghttp2_frame.c @@ -196,8 +196,7 @@ void nghttp2_frame_altsvc_init(nghttp2_altsvc *frame, int32_t stream_id, { size_t payloadlen; - /* 8 for Max-Age, Port, Reserved and PID_LEN. 1 for HOST_LEN. */ - payloadlen = 8 + protocol_id_len + 1 + host_len + origin_len; + payloadlen = NGHTTP2_ALTSVC_MINLEN + protocol_id_len + host_len + origin_len; frame_set_hd(&frame->hd, payloadlen, NGHTTP2_ALTSVC, NGHTTP2_FLAG_NONE, stream_id); diff --git a/lib/nghttp2_frame.h b/lib/nghttp2_frame.h index ca5ca7b6..a9f9abb2 100644 --- a/lib/nghttp2_frame.h +++ b/lib/nghttp2_frame.h @@ -60,6 +60,16 @@ /* The maximum header table size in SETTINGS_HEADER_TABLE_SIZE */ #define NGHTTP2_MAX_HEADER_TABLE_SIZE ((1u << 31) - 1) + +/* Length of fixed part in ALTSVC frame, that is the sum of fields of + Max-Age, Port, Reserved and PID_LEN. */ +#define NGHTTP2_ALTSVC_FIXED_PARTLEN 8 + +/* Minimum length of ALTSVC frame. NGHTTP2_ALTSVC_FIXED_PARTLEN + + HOST_LEN. */ +#define NGHTTP2_ALTSVC_MINLEN 9 + + /* Category of frames. */ typedef enum { /* non-DATA frame */ diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 8bf399e0..6c309dbf 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -4490,7 +4490,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, break; } - if(iframe->payloadleft < 9) { + if(iframe->payloadleft < NGHTTP2_ALTSVC_MINLEN) { busy = 1; iframe->state = NGHTTP2_IB_FRAME_SIZE_ERROR; @@ -4499,7 +4499,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, } iframe->state = NGHTTP2_IB_READ_NBYTE; - inbound_frame_set_mark(iframe, 8); + inbound_frame_set_mark(iframe, NGHTTP2_ALTSVC_FIXED_PARTLEN); break; case NGHTTP2_BLOCKED: @@ -4711,7 +4711,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, case NGHTTP2_ALTSVC: { size_t varlen; - varlen = iframe->frame.hd.length - 8; + varlen = iframe->frame.hd.length - NGHTTP2_ALTSVC_FIXED_PARTLEN; if(varlen > 0) { iframe->raw_lbuf = malloc(varlen);