Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/recover #6

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions inc/hpack.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ enum hpack_result_e hpack_trim(struct hpack **);

/* hpack_error */

extern const char *hpack_unknown_name;
extern const char *hpack_unknown_value;

typedef void hpack_dump_f(void *, const char *, ...);

const char * hpack_strerror(enum hpack_result_e);
Expand Down
2 changes: 2 additions & 0 deletions lib/cashpack.map
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ CASHPACK_0.4 {

# variables
hpack_default_alloc;
hpack_unknown_name;
hpack_unknown_value;

local:
*;
Expand Down
4 changes: 3 additions & 1 deletion lib/hpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,9 @@ hpack_decode_field(HPACK_CTX)
else
CALL(HPT_decode_name, ctx);
assert(ctx->buf > ctx->fld.nam);
ctx->fld.nam_sz = (size_t)(ctx->buf - ctx->fld.nam - 1);
if(ctx->fld.nam != hpack_unknown_name) {
ctx->fld.nam_sz = (size_t)(ctx->buf - ctx->fld.nam - 1);
}
CALL(HPV_token, ctx, ctx->fld.nam, ctx->fld.nam_sz);
ctx->fld.val = ctx->buf;
ctx->hp->state.stp = HPACK_STP_VAL_LEN;
Expand Down
33 changes: 29 additions & 4 deletions lib/hpack_tbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ static const struct hpt_field hpt_static[] = {
* Tables lookups
*/

const char *hpack_unknown_name = "unknown_name";
const char *hpack_unknown_value = "unknown_value";

static size_t HPT_index_silent(HPACK_CTX);

static struct hpt_entry *
hpt_dynamic(struct hpack *hp, size_t idx)
{
Expand Down Expand Up @@ -99,6 +104,18 @@ HPT_field(HPACK_CTX, size_t idx, struct hpt_field *hf)
}

idx -= HPACK_STATIC;
if(HPC_DEGRADED() && idx > ctx->hp->cnt) {
ctx->fld.nam = hpack_unknown_name;
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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this loop, but don't know how to get rid of it.
Comments welcome!

HPT_index_silent(ctx);
}
while(idx >= ctx->hp->cnt) {
HPT_index(ctx);
}
}
EXPECT(ctx, IDX, idx <= ctx->hp->cnt);

he = hpt_dynamic(ctx->hp, idx);
Expand Down Expand Up @@ -366,8 +383,8 @@ hpt_move_evicted(HPACK_CTX, const char *nam, size_t nam_sz, size_t len)
(void)memmove(MOVE(tbl_ptr, len), tbl_ptr, hp->sz.len);
}

void
HPT_index(HPACK_CTX)
static size_t
HPT_index_silent(HPACK_CTX)
{
struct hpack *hp;
void *nam_ptr, *val_ptr;
Expand All @@ -391,7 +408,7 @@ HPT_index(HPACK_CTX)

len = HPACK_OVERHEAD + nam_sz + val_sz;
if (!hpt_fit(ctx, len))
return;
return 0;

nam_ptr = JUMP(hp->tbl, 0);
val_ptr = JUMP(hp->tbl, nam_sz + 1);
Expand All @@ -412,8 +429,16 @@ HPT_index(HPACK_CTX)
hp->tbl->val_sz = (uint16_t)val_sz;
hp->sz.len += len;
hp->cnt++;
return len;
}

HPC_notify(ctx, HPACK_EVT_INDEX, NULL, len);
void
HPT_index(HPACK_CTX)
{
size_t len = HPT_index_silent(ctx);
if(len > 0) {
HPC_notify(ctx, HPACK_EVT_INDEX, NULL, len);
}
}

/**********************************************************************
Expand Down