You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.5 KiB

  1. commit 8d09dc21dc913d1540d07d1019a51c430317eae1
  2. Author: Christopher Faulet <cfaulet@haproxy.com>
  3. Date: Tue Jun 18 09:37:00 2019 +0200
  4. MINOR: htx: Add the function htx_change_blk_value_len()
  5. As its name suggest, this function change the value length of a block. But it
  6. also update the HTX message accordingly. It simplifies the HTX API. The function
  7. htx_set_blk_value_len() is still available and must be used with caution because
  8. this one does not update the HTX message. It just updates the HTX block. It
  9. should be considered as an internal function. When possible,
  10. htx_change_blk_value_len() should be used instead.
  11. This function is used to fix a bug affecting the 2.0. So, this patch must be
  12. backported to 2.0.
  13. (cherry picked from commit bb0efcdd293de33607a6eba075971b49857375e2)
  14. Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
  15. diff --git a/include/common/htx.h b/include/common/htx.h
  16. index 9631c618..7d15365a 100644
  17. --- a/include/common/htx.h
  18. +++ b/include/common/htx.h
  19. @@ -470,7 +470,41 @@ static inline struct htx_blk *htx_get_next_blk(const struct htx *htx,
  20. }
  21. /* Changes the size of the value. It is the caller responsibility to change the
  22. - * value itself, make sure there is enough space and update allocated value.
  23. + * value itself, make sure there is enough space and update allocated
  24. + * value. This function updates the HTX message accordingly.
  25. + */
  26. +static inline void htx_change_blk_value_len(struct htx *htx, struct htx_blk *blk, uint32_t newlen)
  27. +{
  28. + enum htx_blk_type type = htx_get_blk_type(blk);
  29. + uint32_t oldlen, sz;
  30. + int32_t delta;
  31. +
  32. + sz = htx_get_blksz(blk);
  33. + switch (type) {
  34. + case HTX_BLK_HDR:
  35. + case HTX_BLK_TLR:
  36. + oldlen = (blk->info >> 8) & 0xfffff;
  37. + blk->info = (type << 28) + (newlen << 8) + (blk->info & 0xff);
  38. + break;
  39. + default:
  40. + oldlen = blk->info & 0xfffffff;
  41. + blk->info = (type << 28) + newlen;
  42. + break;
  43. + }
  44. +
  45. + /* Update HTTP message */
  46. + delta = (newlen - oldlen);
  47. + htx->data += delta;
  48. + if (blk->addr+sz == htx->tail_addr)
  49. + htx->tail_addr += delta;
  50. + else if (blk->addr+sz == htx->head_addr)
  51. + htx->head_addr += delta;
  52. +}
  53. +
  54. +/* Changes the size of the value. It is the caller responsibility to change the
  55. + * value itself, make sure there is enough space and update allocated
  56. + * value. Unlike the function htx_change_blk_value_len(), this one does not
  57. + * update the HTX message. So it should be used with caution.
  58. */
  59. static inline void htx_set_blk_value_len(struct htx_blk *blk, uint32_t vlen)
  60. {