]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: Make some applet functions HTX aware
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 29 Jul 2025 06:42:26 +0000 (08:42 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 25 Aug 2025 09:11:05 +0000 (11:11 +0200)
applet_output_room() and applet_input_data() are now HTX aware. These
functions automatically rely on htx versions if APPLET_FL_HTX flag is set
for the applet.

include/haproxy/applet.h

index 8ea9e857bf26a7e19d12a538cf76d1b50416d6ce..018290d62bc82a673a54c654c997721cd30b7262 100644 (file)
@@ -319,20 +319,23 @@ static inline struct buffer *applet_get_outbuf(struct appctx *appctx)
                return sc_ib(appctx_sc(appctx));
 }
 
-/* Returns the amount of data in the input buffer (see applet_get_inbuf) */
-static inline size_t applet_input_data(const struct appctx *appctx)
+/* Returns the amount of HTX data in the input buffer (see applet_get_inbuf) */
+static inline size_t applet_htx_input_data(const struct appctx *appctx)
 {
        if (appctx_app_test(appctx, APPLET_FL_NEW_API))
-               return b_data(&appctx->inbuf);
+               return htx_used_space(htxbuf(&appctx->inbuf));
        else
                return co_data(sc_oc(appctx_sc(appctx)));
 }
 
-/* Returns the amount of HTX data in the input buffer (see applet_get_inbuf) */
-static inline size_t applet_htx_input_data(const struct appctx *appctx)
+/* Returns the amount of data in the input buffer (see applet_get_inbuf) */
+static inline size_t applet_input_data(const struct appctx *appctx)
 {
+       if (appctx_app_test(appctx, APPLET_FL_HTX))
+               return applet_htx_input_data(appctx);
+
        if (appctx_app_test(appctx, APPLET_FL_NEW_API))
-               return htx_used_space(htxbuf(&appctx->inbuf));
+               return b_data(&appctx->inbuf);
        else
                return co_data(sc_oc(appctx_sc(appctx)));
 }
@@ -343,6 +346,8 @@ static inline size_t applet_htx_input_data(const struct appctx *appctx)
  * illegal to call this function with <len> causing a wrapping at the end of the
  * buffer. It's the caller's responsibility to ensure that <len> is never larger
  * than available ouput data.
+ *
+ * This function is not HTX aware.
  */
 static inline void applet_skip_input(struct appctx *appctx, size_t len)
 {
@@ -366,22 +371,25 @@ static inline void applet_reset_input(struct appctx *appctx)
                co_skip(sc_oc(appctx_sc(appctx)), co_data(sc_oc(appctx_sc(appctx))));
 }
 
-/* Returns the amout of space available at the output buffer (see applet_get_outbuf).
+/* Returns the amout of space available at the HTX output buffer (see applet_get_outbuf).
  */
-static inline size_t applet_output_room(const struct appctx *appctx)
+static inline size_t applet_htx_output_room(const struct appctx *appctx)
 {
        if (appctx_app_test(appctx, APPLET_FL_NEW_API))
-               return b_room(&appctx->outbuf);
+               return htx_free_data_space(htxbuf(&appctx->outbuf));
        else
                return channel_recv_max(sc_ic(appctx_sc(appctx)));
 }
 
-/* Returns the amout of space available at the HTX output buffer (see applet_get_outbuf).
+/* Returns the amout of space available at the output buffer (see applet_get_outbuf).
  */
-static inline size_t applet_htx_output_room(const struct appctx *appctx)
+static inline size_t applet_output_room(const struct appctx *appctx)
 {
+       if (appctx_app_test(appctx, APPLET_FL_HTX))
+               return applet_htx_output_room(appctx);
+
        if (appctx_app_test(appctx, APPLET_FL_NEW_API))
-               return htx_free_data_space(htxbuf(&appctx->outbuf));
+               return b_room(&appctx->outbuf);
        else
                return channel_recv_max(sc_ic(appctx_sc(appctx)));
 }