]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: htx: Add function to iterate on an HTX message using HTX blocks
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 22 Nov 2018 10:23:23 +0000 (11:23 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 1 Dec 2018 16:37:27 +0000 (17:37 +0100)
the functions htx_get_next() and htx_get_prev() are used to iterate on an HTX
message using blocks position. With htx_get_next_blk() and htx_get_prev_blk(),
it is possible to do the same, but with HTX blocks. Of course, internally, we
rely on position's versions to do so. But it is handy for callers to not take
care of the blocks position.

include/proto/htx.h

index 7db2059c272cd4a5d4f3b2e37bdadb510795ce38..77d077f75b14ec5c88743e855f1de74d2517843c 100644 (file)
@@ -211,6 +211,18 @@ static inline int32_t htx_get_prev(const struct htx *htx, uint32_t pos)
         return (pos - 1);
 }
 
+/* Returns the HTX block before <blk> in the HTX message <htx>. If <blk> is the
+ * head, NULL returned.
+*/
+static inline struct htx_blk *htx_get_prev_blk(const struct htx *htx,
+                                              const struct htx_blk *blk)
+{
+       int32_t pos;
+
+       pos = htx_get_prev(htx, htx_get_blk_pos(htx, blk));
+       return ((pos == -1) ? NULL : htx_get_blk(htx, pos));
+}
+
 /* Returns the position of block immediatly after the one pointed by <pos>. If
  * the message is empty or if <pos> is the position of the tail, -1 returned.
  *
@@ -231,6 +243,19 @@ static inline int32_t htx_get_next(const struct htx *htx, uint32_t pos)
         return pos;
 
 }
+
+/* Returns the HTX block after <blk> in the HTX message <htx>. If <blk> is the
+ * tail, NULL returned.
+*/
+static inline struct htx_blk *htx_get_next_blk(const struct htx *htx,
+                                              const struct htx_blk *blk)
+{
+       int32_t pos;
+
+       pos = htx_get_next(htx, htx_get_blk_pos(htx, blk));
+       return ((pos == -1) ? NULL : htx_get_blk(htx, pos));
+}
+
 static inline int32_t htx_find_front(const struct htx *htx)
 {
         int32_t  front, pos;