Skip to content

Commit

Permalink
Avoid dynamic table field creation in degraded mode
Browse files Browse the repository at this point in the history
Also avoid copy of sentinel values to be able to use them in event callback.
  • Loading branch information
dguerizec committed Jul 29, 2020
1 parent 720ad9d commit 15e3b63
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions lib/hpack_tbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ hpt_dynamic(struct hpack *hp, size_t idx)
off = 0;

assert(idx > 0);
assert(idx <= hp->cnt);
if(idx > hp->cnt) {
return NULL;
}

while (1) {
(void)memcpy(&tmp, he, HPT_HEADERSZ);
Expand Down Expand Up @@ -109,18 +111,16 @@ HPT_field(HPACK_CTX, size_t idx, struct hpt_field *hf)
ctx->fld.val = hpack_unknown_value;
ctx->fld.nam_sz = strlen(ctx->fld.nam);
ctx->fld.val_sz = strlen(ctx->fld.val);
while(idx > ctx->hp->cnt) {
HPT_index_silent(ctx);
}
while(idx >= ctx->hp->cnt) {
HPT_index(ctx);
}
if(ctx->hp->flags & HPACK_CFG_SEND_ERR)
HPC_notify(ctx, HPACK_EVT_RECERR, ctx->ptr.blk, idx);
} else {
EXPECT(ctx, IDX, idx <= ctx->hp->cnt);
}
EXPECT(ctx, IDX, idx <= ctx->hp->cnt);

he = hpt_dynamic(ctx->hp, idx);
if(HPC_DEGRADED() && he == NULL) {
return (0);
}
assert(he != NULL);
assert(hf != NULL);
(void)memcpy(&tmp, he, HPT_HEADERSZ);
Expand Down Expand Up @@ -455,17 +455,24 @@ HPT_decode(HPACK_CTX, size_t idx)
EXPECT(ctx, IDX, idx > 0);
(void)memset(&hf, 0, sizeof hf);
CALL(HPT_field, ctx, idx, &hf);
assert(hf.nam != NULL);
assert(hf.val != NULL);
assert(hf.nam_sz > 0);

ctx->fld.nam = ctx->buf;
ctx->fld.nam_sz = hf.nam_sz;
CALL(HPD_puts, ctx, hf.nam, hf.nam_sz);

ctx->fld.val = ctx->buf;
ctx->fld.val_sz = hf.val_sz;
CALL(HPD_puts, ctx, hf.val, hf.val_sz);
if(HPC_DEGRADED() && hf.nam == NULL) {
ctx->fld.nam = hpack_unknown_name;
ctx->fld.nam_sz = strlen(hpack_unknown_name);
ctx->fld.val = hpack_unknown_value;
ctx->fld.val_sz = strlen(hpack_unknown_value);
} else {
assert(hf.nam != NULL);
assert(hf.val != NULL);
assert(hf.nam_sz > 0);

ctx->fld.nam = ctx->buf;
ctx->fld.nam_sz = hf.nam_sz;
CALL(HPD_puts, ctx, hf.nam, hf.nam_sz);

ctx->fld.val = ctx->buf;
ctx->fld.val_sz = hf.val_sz;
CALL(HPD_puts, ctx, hf.val, hf.val_sz);
}

HPD_notify(ctx);
return (0);
Expand All @@ -480,6 +487,9 @@ HPT_decode_name(HPACK_CTX)
assert(ctx->hp->state.idx != 0);
(void)memset(&hf, 0, sizeof hf);
CALL(HPT_field, ctx, ctx->hp->state.idx, &hf);
if(HPC_DEGRADED() && hf.nam == NULL) {
return (0);
}
assert(hf.nam != NULL);
assert(hf.nam_sz > 0);

Expand Down

0 comments on commit 15e3b63

Please sign in to comment.