REORG: mux-quic: export HTTP related function in a dedicated file

Extract function dealing with HTX outside of MUX QUIC. For the moment,
only rcv_buf stream operation is concerned.

The main objective is to be able to support both TCP and HTTP proxy mode
with a common base and add specialized modules on top of it.

This should be backported up to 2.6.
diff --git a/Makefile b/Makefile
index 08d0804..12a3c14 100644
--- a/Makefile
+++ b/Makefile
@@ -646,7 +646,7 @@
                 src/cbuf.o src/qpack-dec.o src/qpack-tbl.o src/h3.o src/qpack-enc.o \
                 src/hq_interop.o src/cfgparse-quic.o src/quic_loss.o \
                 src/quic_tp.o src/quic_stream.o src/quic_stats.o src/h3_stats.o \
-                src/quic_cc_cubic.o src/qmux_trace.o
+                src/quic_cc_cubic.o src/qmux_trace.o src/qmux_http.o
 endif
 
 ifneq ($(USE_LUA),)
diff --git a/include/haproxy/qmux_http.h b/include/haproxy/qmux_http.h
new file mode 100644
index 0000000..776725d
--- /dev/null
+++ b/include/haproxy/qmux_http.h
@@ -0,0 +1,14 @@
+#ifndef _HAPROXY_MUX_QUIC_HTTP_H
+#define _HAPROXY_MUX_QUIC_HTTP_H
+
+#ifdef USE_QUIC
+
+#include <haproxy/buf.h>
+#include <haproxy/mux_quic.h>
+
+size_t qcs_http_rcv_buf(struct qcs *qcs, struct buffer *buf, size_t count,
+                        char *fin);
+
+#endif /* USE_QUIC */
+
+#endif /* _HAPROXY_MUX_QUIC_HTTP_H */
diff --git a/src/mux_quic.c b/src/mux_quic.c
index 44f449a..ef11347 100644
--- a/src/mux_quic.c
+++ b/src/mux_quic.c
@@ -5,10 +5,10 @@
 #include <haproxy/api.h>
 #include <haproxy/connection.h>
 #include <haproxy/dynbuf.h>
-#include <haproxy/htx.h>
 #include <haproxy/list.h>
 #include <haproxy/ncbuf.h>
 #include <haproxy/pool.h>
+#include <haproxy/qmux_http.h>
 #include <haproxy/qmux_trace.h>
 #include <haproxy/quic_stream.h>
 #include <haproxy/quic_tp-t.h>
@@ -2062,49 +2062,13 @@
                          size_t count, int flags)
 {
 	struct qcs *qcs = __sc_mux_strm(sc);
-	struct htx *qcs_htx = NULL;
-	struct htx *cs_htx = NULL;
 	size_t ret = 0;
 	char fin = 0;
 
 	TRACE_ENTER(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs);
 
-	qcs_htx = htx_from_buf(&qcs->rx.app_buf);
-	if (htx_is_empty(qcs_htx)) {
-		/* Set buffer data to 0 as HTX is empty. */
-		htx_to_buf(qcs_htx, &qcs->rx.app_buf);
-		goto end;
-	}
-
-	ret = qcs_htx->data;
-
-	cs_htx = htx_from_buf(buf);
-	if (htx_is_empty(cs_htx) && htx_used_space(qcs_htx) <= count) {
-		/* EOM will be copied to cs_htx via b_xfer(). */
-		if (qcs_htx->flags & HTX_FL_EOM)
-			fin = 1;
-
-		htx_to_buf(cs_htx, buf);
-		htx_to_buf(qcs_htx, &qcs->rx.app_buf);
-		b_xfer(buf, &qcs->rx.app_buf, b_data(&qcs->rx.app_buf));
-		goto end;
-	}
-
-	htx_xfer_blks(cs_htx, qcs_htx, count, HTX_BLK_UNUSED);
-	BUG_ON(qcs_htx->flags & HTX_FL_PARSING_ERROR);
+	ret = qcs_http_rcv_buf(qcs, buf, count, &fin);
 
-	/* Copy EOM from src to dst buffer if all data copied. */
-	if (htx_is_empty(qcs_htx) && (qcs_htx->flags & HTX_FL_EOM)) {
-		cs_htx->flags |= HTX_FL_EOM;
-		fin = 1;
-	}
-
-	cs_htx->extra = qcs_htx->extra ? (qcs_htx->data + qcs_htx->extra) : 0;
-	htx_to_buf(cs_htx, buf);
-	htx_to_buf(qcs_htx, &qcs->rx.app_buf);
-	ret -= qcs_htx->data;
-
- end:
 	if (b_data(&qcs->rx.app_buf)) {
 		se_fl_set(qcs->sd, SE_FL_RCV_MORE | SE_FL_WANT_ROOM);
 	}
diff --git a/src/qmux_http.c b/src/qmux_http.c
new file mode 100644
index 0000000..bf53df0
--- /dev/null
+++ b/src/qmux_http.c
@@ -0,0 +1,63 @@
+#include <haproxy/qmux_http.h>
+
+#include <haproxy/api-t.h>
+#include <haproxy/htx.h>
+#include <haproxy/qmux_trace.h>
+
+/* QUIC MUX rcv_buf operation using HTX data. Received data from stream <qcs>
+ * will be transferred as HTX in <buf>. Output buffer is expected to be of
+ * length <count>. <fin> will be set to signal the last data to receive on this
+ * stream.
+ *
+ * Return the size in bytes of transferred data.
+ */
+size_t qcs_http_rcv_buf(struct qcs *qcs, struct buffer *buf, size_t count,
+                        char *fin)
+{
+	struct htx *qcs_htx = NULL;
+	struct htx *cs_htx = NULL;
+	size_t ret = 0;
+
+	TRACE_ENTER(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs);
+
+	*fin = 0;
+	qcs_htx = htx_from_buf(&qcs->rx.app_buf);
+	if (htx_is_empty(qcs_htx)) {
+		/* Set buffer data to 0 as HTX is empty. */
+		htx_to_buf(qcs_htx, &qcs->rx.app_buf);
+		goto end;
+	}
+
+	ret = qcs_htx->data;
+
+	cs_htx = htx_from_buf(buf);
+	if (htx_is_empty(cs_htx) && htx_used_space(qcs_htx) <= count) {
+		/* EOM will be copied to cs_htx via b_xfer(). */
+		if (qcs_htx->flags & HTX_FL_EOM)
+			*fin = 1;
+
+		htx_to_buf(cs_htx, buf);
+		htx_to_buf(qcs_htx, &qcs->rx.app_buf);
+		b_xfer(buf, &qcs->rx.app_buf, b_data(&qcs->rx.app_buf));
+		goto end;
+	}
+
+	htx_xfer_blks(cs_htx, qcs_htx, count, HTX_BLK_UNUSED);
+	BUG_ON(qcs_htx->flags & HTX_FL_PARSING_ERROR);
+
+	/* Copy EOM from src to dst buffer if all data copied. */
+	if (htx_is_empty(qcs_htx) && (qcs_htx->flags & HTX_FL_EOM)) {
+		cs_htx->flags |= HTX_FL_EOM;
+		*fin = 1;
+	}
+
+	cs_htx->extra = qcs_htx->extra ? (qcs_htx->data + qcs_htx->extra) : 0;
+	htx_to_buf(cs_htx, buf);
+	htx_to_buf(qcs_htx, &qcs->rx.app_buf);
+	ret -= qcs_htx->data;
+
+ end:
+	TRACE_LEAVE(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs);
+
+	return ret;
+}