]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: htx: Add function to truncate all blocks after a specific block
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 12 Mar 2026 13:54:20 +0000 (14:54 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 17 Mar 2026 06:48:02 +0000 (07:48 +0100)
htx_truncated_blk() function does the same than htx_trunctate(), except data
are truncated relatively to a block in the message instead of an offset.

include/haproxy/htx.h
src/htx.c

index 6a905a731aca94a501b36d05f699ffd9081cff25..aad49c2dad95f86ce6ce93ddbc36331c62f86bf2 100644 (file)
@@ -37,6 +37,7 @@ struct htx_blk *htx_add_blk(struct htx *htx, enum htx_blk_type type, uint32_t bl
 struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk);
 struct htx_ret htx_find_offset(struct htx *htx, uint32_t offset);
 void htx_truncate(struct htx *htx, uint32_t offset);
+void htx_truncate_blk(struct htx *htx, struct htx_blk *blk);
 struct htx_ret htx_drain(struct htx *htx, uint32_t max);
 
 struct htx_blk *htx_replace_blk_value(struct htx *htx, struct htx_blk *blk,
index 5b64a8db41370275001d64cbc3353ca54ed04466..cb8fd3770871c962da2a21133b898ab425ac00ae 100644 (file)
--- a/src/htx.c
+++ b/src/htx.c
@@ -469,6 +469,18 @@ void htx_truncate(struct htx *htx, uint32_t offset)
                blk = htx_remove_blk(htx, blk);
 }
 
+/* Removes all blocks after <blk>, excluding it. if <blk> is NULL, all blocks
+ * are removed.
+ */
+void htx_truncate_blk(struct htx *htx, struct htx_blk *blk)
+{
+       if (!blk) {
+               htx_drain(htx, htx->data);
+               return;
+       }
+       for (blk = htx_get_next_blk(htx, blk); blk; blk = htx_remove_blk(htx, blk));
+}
+
 /* Drains <count> bytes from the HTX message <htx>. If the last block is a DATA
  * block, it will be cut if necessary. Others blocks will be removed at once if
  * <count> is large enough. The function returns an htx_ret with the first block