Commit f0ef6e98 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Refactor nghttp2_hd_inflate_hd

parent 400615ca
......@@ -900,11 +900,10 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
goto fail;
}
}
} else if(c == 0x60u || c == 0x40u) {
/* Literal Header without Indexing - new name or Literal Header
with incremental indexing - new name */
} else if(c == 0x40u || c == 0x60u || c == 0) {
/* Literal Header Repr - New Name */
nghttp2_nv nv;
ssize_t namelen, valuelen;
ssize_t namelen, valuelen, subindex;
if(++in == last) {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
......@@ -920,6 +919,13 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
}
nv.name = in;
in += namelen;
if(c == 0) {
in = decode_length(&subindex, in, last, 8);
if(subindex < 0) {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
}
}
in = decode_length(&valuelen, in, last, 8);
if(valuelen < 0 || in + valuelen > last) {
rv = NGHTTP2_ERR_HEADER_COMP;
......@@ -934,25 +940,26 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
rv = emit_newname_header(inflater, &nva_out, &nv);
} else {
nghttp2_hd_entry *new_ent;
new_ent = add_hd_table_incremental(inflater, &nv);
if(c == 0) {
new_ent = add_hd_table_subst(inflater, &nv, subindex);
} else {
new_ent = add_hd_table_incremental(inflater, &nv);
}
if(new_ent) {
rv = emit_indexed_header(inflater, &nva_out, new_ent);
} else {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
}
}
if(rv < 0) {
if(rv != 0) {
goto fail;
}
} else if((c & 0x60u) == 0x60u || (c & 0x40) == 0x40u) {
/* Literal Header without Indexing - indexed name or Literal
Header with incremental indexing - indexed name */
} else {
/* Literal Header Repr - Indexed Name */
nghttp2_hd_entry *ent;
uint8_t *value;
ssize_t valuelen;
ssize_t index;
in = decode_length(&index, in, last, 5);
ssize_t valuelen, index, subindex;
in = decode_length(&index, in, last, (c & 0x40u) ? 5 : 6);
if(index < 0) {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
......@@ -963,6 +970,13 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
goto fail;
}
ent = inflater->hd_table[index];
if((c & 0x40u) == 0) {
in = decode_length(&subindex, in, last, 8);
if(subindex < 0) {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
}
}
in = decode_length(&valuelen, in , last, 8);
if(valuelen < 0 || in + valuelen > last) {
rv = NGHTTP2_ERR_HEADER_COMP;
......@@ -980,7 +994,11 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
nv.namelen = ent->nv.namelen;
nv.value = value;
nv.valuelen = valuelen;
new_ent = add_hd_table_incremental(inflater, &nv);
if((c & 0x40u) == 0) {
new_ent = add_hd_table_subst(inflater, &nv, subindex);
} else {
new_ent = add_hd_table_incremental(inflater, &nv);
}
if(--ent->ref == 0) {
nghttp2_hd_entry_free(ent);
free(ent);
......@@ -989,102 +1007,9 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
rv = emit_indexed_header(inflater, &nva_out, new_ent);
} else {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
}
}
if(rv < 0) {
goto fail;
}
} else if(c == 0) {
/* Literal Header with substitution indexing - new name */
nghttp2_hd_entry *new_ent;
nghttp2_nv nv;
ssize_t namelen, valuelen, subindex;
if(++in == last) {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
}
in = decode_length(&namelen, in, last, 8);
if(namelen < 0 || in + namelen > last) {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
}
if(!nghttp2_check_header_name(in, namelen)) {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
}
nv.name = in;
in += namelen;
in = decode_length(&subindex, in, last, 8);
if(subindex < 0) {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
}
in = decode_length(&valuelen, in, last, 8);
if(valuelen < 0 || in + valuelen > last) {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
}
nv.value = in;
nv.namelen = namelen;
nv.valuelen = valuelen;
in += valuelen;
nghttp2_downcase(nv.name, nv.namelen);
new_ent = add_hd_table_subst(inflater, &nv, subindex);
if(new_ent) {
rv = emit_indexed_header(inflater, &nva_out, new_ent);
if(rv < 0) {
goto fail;
}
} else {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
}
} else {
/* Literal Header with substitution indexing - indexed name */
nghttp2_hd_entry *ent, *new_ent;
ssize_t valuelen;
ssize_t index, subindex;
nghttp2_nv nv;
in = decode_length(&index, in, last, 6);
if(index < 0) {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
}
--index;
if(inflater->hd_tablelen <= index) {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
}
ent = inflater->hd_table[index];
in = decode_length(&subindex, in, last, 8);
if(subindex < 0) {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
}
in = decode_length(&valuelen, in, last, 8);
if(valuelen < 0 || in + valuelen > last) {
rv = NGHTTP2_ERR_HEADER_COMP;
goto fail;
}
++ent->ref;
nv.name = ent->nv.name;
nv.namelen = ent->nv.namelen;
nv.value = in;
nv.valuelen = valuelen;
in += valuelen;
new_ent = add_hd_table_subst(inflater, &nv, subindex);
if(--ent->ref == 0) {
nghttp2_hd_entry_free(ent);
free(ent);
}
if(new_ent) {
rv = emit_indexed_header(inflater, &nva_out, new_ent);
if(rv < 0) {
goto fail;
}
} else {
rv = NGHTTP2_ERR_HEADER_COMP;
if(rv != 0) {
goto fail;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment