From: Christopher Faulet Date: Thu, 22 Nov 2018 10:28:18 +0000 (+0100) Subject: MINOR: htx: Add a function to find the HTX block corresponding to a data offset X-Git-Tag: v1.9-dev9~73 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=14e88252f22d5064c4d4a13dc8d62aff98816c83;p=thirdparty%2Fhaproxy.git MINOR: htx: Add a function to find the HTX block corresponding to a data offset The function htx_find_blk() returns the HTX block containing data with a given offset, relatively to the beginning of the HTX message. It is a good way to skip outgoing data and find the first HTX block not already processed. --- diff --git a/include/proto/htx.h b/include/proto/htx.h index 77d077f75b..3c5c0fa01e 100644 --- a/include/proto/htx.h +++ b/include/proto/htx.h @@ -278,6 +278,26 @@ static inline int32_t htx_find_front(const struct htx *htx) return front; } +/* Returns the HTX block containing data with the , relatively to the + * beginning of the HTX message . It returns an htx_ret. if the HTX block is + * not found, htx_ret.blk is set to NULL. Otherwise, it points to the right HTX + * block and htx_ret.ret is set to the remaining offset inside the block. + */ +static inline struct htx_ret htx_find_blk(const struct htx *htx, uint32_t offset) +{ + int32_t pos; + + for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) { + struct htx_blk *blk = htx_get_blk(htx, pos); + uint32_t sz = htx_get_blksz(blk); + + if (offset < sz) + return (struct htx_ret){ .blk = blk, .ret = offset }; + offset -= sz; + } + + return (struct htx_ret){ .blk = NULL }; +} /* 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. */