]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: htx: Add functions to get the first block of an HTX message
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 13 May 2019 09:36:27 +0000 (11:36 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 28 May 2019 05:42:12 +0000 (07:42 +0200)
It is the first block relatively to the start-line. So it is the start-line if
its position is set (sl_pos != -1), otherwise it is the head. The functions
htx_get_first() and htx_get_first_blk() can be used to get it.  This change is
mandatory to consider 1xx informational messages as part of a response.

include/common/htx.h

index ea7361cfc882c4a3b58f05655ce52c99d9e87562..3a9215fac3f484574bba35f8ff9e91313f0b9d66 100644 (file)
@@ -410,6 +410,41 @@ static inline enum htx_blk_type htx_get_tail_type(const struct htx *htx)
        return (blk ? htx_get_blk_type(blk) : HTX_BLK_UNUSED);
 }
 
+/* Returns the position of the first block in the HTX message <htx>. It is the
+ * sl_pos if set, otherwise it is the head.
+ *
+ * An signed 32-bits integer is returned to handle -1 case. Blocks position are
+ * store on unsigned 32-bits integer, but it is impossible to have so much
+ * blocks to overflow a 32-bits signed integer !
+ */
+static inline int32_t htx_get_first(const struct htx *htx)
+{
+       if (htx->sl_pos != -1)
+               return htx->sl_pos;
+       return htx->head;
+}
+
+/* Returns the first HTX block in the HTX message <htx>. If <blk> is the head,
+ * NULL returned.
+ */
+static inline struct htx_blk *htx_get_first_blk(const struct htx *htx)
+{
+       int32_t pos;
+
+       pos = htx_get_first(htx);
+       return ((pos == -1) ? NULL : htx_get_blk(htx, pos));
+}
+
+/* Returns the type of the first block in the HTX message <htx>. If unset or if
+ * <htx> is empty, HTX_BLK_UNUSED is returned.
+ */
+static inline enum htx_blk_type htx_get_first_type(const struct htx *htx)
+{
+       struct htx_blk *blk = htx_get_first_blk(htx);
+
+       return (blk ? htx_get_blk_type(blk) : HTX_BLK_UNUSED);
+}
+
 /* Returns the position of block immediately before the one pointed by <pos>. If
  * the message is empty or if <pos> is the position of the head, -1 returned.
  *