Skip to content

Commit

Permalink
MINOR: htx: Add the function htx_change_blk_value_len()
Browse files Browse the repository at this point in the history
As its name suggest, this function change the value length of a block. But it
also update the HTX message accordingly. It simplifies the HTX API. The function
htx_set_blk_value_len() is still available and must be used with caution because
this one does not update the HTX message. It just updates the HTX block. It
should be considered as an internal function. When possible,
htx_change_blk_value_len() should be used instead.

This function is used to fix a bug affecting the 2.0. So, this patch must be
backported to 2.0.
  • Loading branch information
capflam committed Jun 18, 2019
1 parent 721d686 commit bb0efcd
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion include/common/htx.h
Expand Up @@ -470,7 +470,41 @@ static inline struct htx_blk *htx_get_next_blk(const struct htx *htx,
}

/* Changes the size of the value. It is the caller responsibility to change the
* value itself, make sure there is enough space and update allocated value.
* value itself, make sure there is enough space and update allocated
* value. This function updates the HTX message accordingly.
*/
static inline void htx_change_blk_value_len(struct htx *htx, struct htx_blk *blk, uint32_t newlen)
{
enum htx_blk_type type = htx_get_blk_type(blk);
uint32_t oldlen, sz;
int32_t delta;

sz = htx_get_blksz(blk);
switch (type) {
case HTX_BLK_HDR:
case HTX_BLK_TLR:
oldlen = (blk->info >> 8) & 0xfffff;
blk->info = (type << 28) + (newlen << 8) + (blk->info & 0xff);
break;
default:
oldlen = blk->info & 0xfffffff;
blk->info = (type << 28) + newlen;
break;
}

/* Update HTTP message */
delta = (newlen - oldlen);
htx->data += delta;
if (blk->addr+sz == htx->tail_addr)
htx->tail_addr += delta;
else if (blk->addr+sz == htx->head_addr)
htx->head_addr += delta;
}

/* Changes the size of the value. It is the caller responsibility to change the
* value itself, make sure there is enough space and update allocated
* value. Unlike the function htx_change_blk_value_len(), this one does not
* update the HTX message. So it should be used with caution.
*/
static inline void htx_set_blk_value_len(struct htx_blk *blk, uint32_t vlen)
{
Expand Down

0 comments on commit bb0efcd

Please sign in to comment.