REORG: htx: merge types+proto into common/htx.h
All the HTX definition is self-contained and doesn't really depend on
anything external since it's a mostly protocol. In addition, some
external similar files (like h2) also placed in common used to rely
on it, making it a bit awkward.
This patch moves the two htx.h files into a single self-contained one.
The historical dependency on sample.h could be also removed since it
used to be there only for http_meth_t which is now in http.h.
diff --git a/include/common/h2.h b/include/common/h2.h
index 6c1475b..e068427 100644
--- a/include/common/h2.h
+++ b/include/common/h2.h
@@ -31,8 +31,8 @@
#include <common/config.h>
#include <common/http-hdr.h>
+#include <common/htx.h>
#include <common/ist.h>
-#include <proto/htx.h>
/* indexes of most important pseudo headers can be simplified to an almost
diff --git a/include/proto/htx.h b/include/common/htx.h
similarity index 79%
rename from include/proto/htx.h
rename to include/common/htx.h
index 3fd8fba..93031cd 100644
--- a/include/proto/htx.h
+++ b/include/common/htx.h
@@ -1,5 +1,5 @@
/*
- * include/proto/hx.h
+ * include/common/htx.h
* This file defines everything related to the internal HTTP messages.
*
* Copyright (C) 2018 HAProxy Technologies, Christopher Faulet <cfaulet@haproxy.com>
@@ -19,14 +19,151 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef _PROTO_HTX_H
-#define _PROTO_HTX_H
+#ifndef _COMMON_HTX_H
+#define _COMMON_HTX_H
+#include <stdio.h>
#include <common/buf.h>
#include <common/config.h>
-#include <common/standard.h>
+#include <common/ist.h>
+#include <common/http.h>
#include <common/http-hdr.h>
-#include <types/htx.h>
+#include <common/standard.h>
+
+/*
+ * The internal representation of an HTTP message is a contiguous array
+ * containing both the blocks (htx_blk) and their contents. Blocks are stored
+ * starting from the end of the array while their contents are stored at the
+ * beginning.
+ *
+ * As data are sent to the peer, blocks and contents are released at the
+ * edges. This free space is reused when no more space left. So blocks and
+ * contents may wrap, not necessarily the same time.
+ *
+ * An HTTP block is as well a header as a body part or a trailer part. For all
+ * these types of block, a content is attached to the block. It can also be a
+ * mark, like the end-of-headers or end-of-message. For these blocks, there is
+ * no content but it count for a byte. It is important to not skip it when data
+ * are forwarded. An HTTP block is composed of 2 fields:
+ *
+ * - .info : It a 32 bits field containing the block's type on 4 bits
+ * followed by content' length. See below for details.
+ *
+ * - .addr : The content's address, if any, relatively to the beginning the
+ * array used to store the HTTP message itself.
+ *
+ * htx_blk.info representation:
+ *
+ * 0b 0000 0000 0000 0000 0000 0000 0000 0000
+ * ---- ------------------------ ---------
+ * type value (1 MB max) name length (header)
+ * ----------------------------------
+ * data length (256 MB max)
+ * (body, method, path, version, status, reason, trailers)
+ *
+ * types:
+ * - 0000 = request start-line
+ * - 0001 = response start-line
+ * - 0010 = header
+ * - 0011 = pseudo-header ou "special" header
+ * - 0100 = end-of-headers
+ * - 0101 = data
+ * - 0110 = end-of-data
+ * - 0111 = trailer
+ * - 1000 = end-of-message
+ * ...
+ * - 1101 = out-of-band
+ * - 1110 = error
+ * - 1111 = unused
+ *
+ */
+
+/*HTX start-line flags */
+#define HTX_SL_F_NONE 0x00000000
+#define HTX_SL_F_IS_RESP 0x00000001 /* It is the response start-line (unset means the request one) */
+#define HTX_SL_F_XFER_LEN 0x00000002 /* The message xfer size can be dertermined */
+#define HTX_SL_F_XFER_ENC 0x00000004 /* The transfer-encoding header was found in message */
+#define HTX_SL_F_CLEN 0x00000008 /* The content-length header was found in message */
+#define HTX_SL_F_CHNK 0x00000010 /* The message payload is chunked */
+#define HTX_SL_F_VER_11 0x00000020 /* The message indicates version 1.1 or above */
+#define HTX_SL_F_BODYLESS 0x00000040 /* The message has no body (content-length = 0) */
+
+/* HTX flags */
+#define HTX_FL_NONE 0x00000000
+#define HTX_FL_PARSING_ERROR 0x00000001
+
+
+/* Pseudo header types (max 255). */
+enum htx_phdr_type {
+ HTX_PHDR_UNKNOWN = 0,
+ HTX_PHDR_SIZE,
+};
+
+/* HTTP block's type (max 15). */
+enum htx_blk_type {
+ HTX_BLK_REQ_SL = 0, /* Request start-line */
+ HTX_BLK_RES_SL = 1, /* Response start-line */
+ HTX_BLK_HDR = 2, /* header name/value block */
+ HTX_BLK_PHDR = 3, /* pseudo header block */
+ HTX_BLK_EOH = 4, /* end-of-headers block */
+ HTX_BLK_DATA = 5, /* data block */
+ HTX_BLK_EOD = 6, /* end-of-data block */
+ HTX_BLK_TLR = 7, /* trailer name/value block */
+ HTX_BLK_EOM = 8, /* end-of-message block */
+ /* 9 .. 13 unused */
+ HTX_BLK_OOB = 14, /* Out of band block, don't alter the parser */
+ HTX_BLK_UNUSED = 15, /* unused/removed block */
+};
+
+/* One HTTP block descriptor */
+struct htx_blk {
+ uint32_t addr; /* relative storage address of a data block */
+ uint32_t info; /* information about data stored */
+};
+
+struct htx_ret {
+ int32_t ret;
+ struct htx_blk *blk;
+};
+
+struct htx_sl {
+ unsigned int flags; /* HTX_SL_F_* */
+ union {
+ struct {
+ enum http_meth_t meth; /* method */
+ } req;
+ struct {
+ uint16_t status; /* status code */
+ } res;
+ } info;
+
+ /* XXX 2 bytes unused */
+
+ unsigned int len[3]; /* length of differnt parts of the start-line */
+ char l[0];
+};
+
+/* Internal representation of an HTTP message */
+struct htx {
+ uint32_t size; /* the array size, in bytes, used to store the HTTP message itself */
+ uint32_t data; /* the data size, in bytes. To known to total size used by all allocated
+ * blocks (blocks and their contents), you need to add size used by blocks,
+ * i.e. [ used * sizeof(struct htx_blk *) ] */
+
+ uint32_t used; /* number of blocks in use */
+ uint32_t tail; /* last inserted block */
+ uint32_t front; /* block's position of the first content before the blocks table */
+ uint32_t wrap; /* the position were the blocks table wraps, if any */
+
+ uint64_t extra; /* known bytes amount remaining to receive */
+ uint32_t flags; /* HTX_FL_* */
+
+ int32_t sl_off; /* Offset of the start-line of the HTTP message relatively to the beginning the
+ data block. -1 if unset */
+
+ struct htx_blk blocks[0]; /* Blocks representing the HTTP message itself */
+};
+
extern struct htx htx_empty;
@@ -88,10 +225,10 @@
#define HTX_SL_RES_CPTR(sl) HTX_SL_P2_PTR(sl)
#define HTX_SL_RES_RPTR(sl) HTX_SL_P3_PTR(sl)
- static inline const struct ist htx_sl_p1(const struct htx_sl *sl)
- {
- return ist2(HTX_SL_P1_PTR(sl), HTX_SL_P1_LEN(sl));
- }
+static inline const struct ist htx_sl_p1(const struct htx_sl *sl)
+{
+ return ist2(HTX_SL_P1_PTR(sl), HTX_SL_P1_LEN(sl));
+}
static inline const struct ist htx_sl_p2(const struct htx_sl *sl)
{
@@ -103,7 +240,6 @@
return ist2(HTX_SL_P3_PTR(sl), HTX_SL_P3_LEN(sl));
}
-
static inline const struct ist htx_sl_req_meth(const struct htx_sl *sl)
{
return htx_sl_p1(sl);
@@ -671,7 +807,7 @@
fprintf(stderr, "\n");
}
-#endif /* _PROTO_HTX_H */
+#endif /* _COMMON_HTX_H */
/*
* Local variables:
diff --git a/include/proto/channel.h b/include/proto/channel.h
index dd9b1af..5d9c7a8 100644
--- a/include/proto/channel.h
+++ b/include/proto/channel.h
@@ -29,6 +29,7 @@
#include <common/config.h>
#include <common/chunk.h>
+#include <common/htx.h>
#include <common/ticks.h>
#include <common/time.h>
@@ -36,7 +37,6 @@
#include <types/global.h>
#include <types/stream.h>
#include <types/stream_interface.h>
-#include <types/htx.h>
#include <proto/task.h>
diff --git a/include/types/http_htx.h b/include/types/http_htx.h
index c8f4197..3f9a7f4 100644
--- a/include/types/http_htx.h
+++ b/include/types/http_htx.h
@@ -23,8 +23,8 @@
#ifndef _TYPES_HTTP_HTX_H
#define _TYPES_HTTP_HTX_H
+#include <common/htx.h>
#include <common/ist.h>
-#include <types/htx.h>
/* Context used to find/remove an HTTP header. */
struct http_hdr_ctx {
diff --git a/include/types/htx.h b/include/types/htx.h
deleted file mode 100644
index 1146b9a..0000000
--- a/include/types/htx.h
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * include/types/htx.h
- * This file contains the internal HTTP definitions.
- *
- * Copyright (C) 2018 HAProxy Technologies, Christopher Faulet <cfaulet@haproxy.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation, version 2.1
- * exclusively.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef _TYPES_HTX_H
-#define _TYPES_HTX_H
-
-#include <common/ist.h>
-#include <types/sample.h>
-
-/*
- * The internal representation of an HTTP message is a contiguous array
- * containing both the blocks (htx_blk) and their contents. Blocks are stored
- * starting from the end of the array while their contents are stored at the
- * beginning.
- *
- * As data are sent to the peer, blocks and contents are released at the
- * edges. This free space is reused when no more space left. So blocks and
- * contents may wrap, not necessarily the same time.
- *
- * An HTTP block is as well a header as a body part or a trailer part. For all
- * these types of block, a content is attached to the block. It can also be a
- * mark, like the end-of-headers or end-of-message. For these blocks, there is
- * no content but it count for a byte. It is important to not skip it when data
- * are forwarded. An HTTP block is composed of 2 fields:
- *
- * - .info : It a 32 bits field containing the block's type on 4 bits
- * followed by content' length. See below for details.
- *
- * - .addr : The content's address, if any, relatively to the beginning the
- * array used to store the HTTP message itself.
- *
- * htx_blk.info representation:
- *
- * 0b 0000 0000 0000 0000 0000 0000 0000 0000
- * ---- ------------------------ ---------
- * type value (1 MB max) name length (header)
- * ----------------------------------
- * data length (256 MB max)
- * (body, method, path, version, status, reason, trailers)
- *
- * types:
- * - 0000 = request start-line
- * - 0001 = response start-line
- * - 0010 = header
- * - 0011 = pseudo-header ou "special" header
- * - 0100 = end-of-headers
- * - 0101 = data
- * - 0110 = end-of-data
- * - 0111 = trailer
- * - 1000 = end-of-message
- * ...
- * - 1101 = out-of-band
- * - 1110 = error
- * - 1111 = unused
- *
- */
-
-/*HTX start-line flags */
-#define HTX_SL_F_NONE 0x00000000
-#define HTX_SL_F_IS_RESP 0x00000001 /* It is the response start-line (unset means the request one) */
-#define HTX_SL_F_XFER_LEN 0x00000002 /* The message xfer size can be dertermined */
-#define HTX_SL_F_XFER_ENC 0x00000004 /* The transfer-encoding header was found in message */
-#define HTX_SL_F_CLEN 0x00000008 /* The content-length header was found in message */
-#define HTX_SL_F_CHNK 0x00000010 /* The message payload is chunked */
-#define HTX_SL_F_VER_11 0x00000020 /* The message indicates version 1.1 or above */
-#define HTX_SL_F_BODYLESS 0x00000040 /* The message has no body (content-length = 0) */
-
-/* HTX flags */
-#define HTX_FL_NONE 0x00000000
-#define HTX_FL_PARSING_ERROR 0x00000001
-
-
-/* Pseudo header types (max 255). */
-enum htx_phdr_type {
- HTX_PHDR_UNKNOWN = 0,
- HTX_PHDR_SIZE,
-};
-
-/* HTTP block's type (max 15). */
-enum htx_blk_type {
- HTX_BLK_REQ_SL = 0, /* Request start-line */
- HTX_BLK_RES_SL = 1, /* Response start-line */
- HTX_BLK_HDR = 2, /* header name/value block */
- HTX_BLK_PHDR = 3, /* pseudo header block */
- HTX_BLK_EOH = 4, /* end-of-headers block */
- HTX_BLK_DATA = 5, /* data block */
- HTX_BLK_EOD = 6, /* end-of-data block */
- HTX_BLK_TLR = 7, /* trailer name/value block */
- HTX_BLK_EOM = 8, /* end-of-message block */
- /* 9 .. 13 unused */
- HTX_BLK_OOB = 14, /* Out of band block, don't alter the parser */
- HTX_BLK_UNUSED = 15, /* unused/removed block */
-};
-
-/* One HTTP block descriptor */
-struct htx_blk {
- uint32_t addr; /* relative storage address of a data block */
- uint32_t info; /* information about data stored */
-};
-
-struct htx_ret {
- int32_t ret;
- struct htx_blk *blk;
-};
-
-struct htx_sl {
- unsigned int flags; /* HTX_SL_F_* */
- union {
- struct {
- enum http_meth_t meth; /* method */
- } req;
- struct {
- uint16_t status; /* status code */
- } res;
- } info;
-
- /* XXX 2 bytes unused */
-
- unsigned int len[3]; /* length of differnt parts of the start-line */
- char l[0];
-};
-
-/* Internal representation of an HTTP message */
-struct htx {
- uint32_t size; /* the array size, in bytes, used to store the HTTP message itself */
- uint32_t data; /* the data size, in bytes. To known to total size used by all allocated
- * blocks (blocks and their contents), you need to add size used by blocks,
- * i.e. [ used * sizeof(struct htx_blk *) ] */
-
- uint32_t used; /* number of blocks in use */
- uint32_t tail; /* last inserted block */
- uint32_t front; /* block's position of the first content before the blocks table */
- uint32_t wrap; /* the position were the blocks table wraps, if any */
-
- uint64_t extra; /* known bytes amount remaining to receive */
- uint32_t flags; /* HTX_FL_* */
-
- int32_t sl_off; /* Offset of the start-line of the HTTP message relatively to the beginning the
- data block. -1 if unset */
-
- struct htx_blk blocks[0]; /* Blocks representing the HTTP message itself */
-};
-
-#endif /* _TYPES_HTX_H */
-
-/*
- * Local variables:
- * c-indent-level: 8
- * c-basic-offset: 8
- * End:
- */
diff --git a/src/cache.c b/src/cache.c
index 407d150..9cfb535 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -24,7 +24,6 @@
#include <proto/proxy.h>
#include <proto/hdr_idx.h>
#include <proto/http_htx.h>
-#include <proto/htx.h>
#include <proto/filters.h>
#include <proto/http_rules.h>
#include <proto/proto_http.h>
@@ -36,6 +35,7 @@
#include <common/cfgparse.h>
#include <common/hash.h>
+#include <common/htx.h>
#include <common/initcall.h>
/* flt_cache_store */
diff --git a/src/filters.c b/src/filters.c
index d082261..4f3fae7 100644
--- a/src/filters.c
+++ b/src/filters.c
@@ -16,6 +16,7 @@
#include <common/compat.h>
#include <common/config.h>
#include <common/errors.h>
+#include <common/htx.h>
#include <common/initcall.h>
#include <common/namespace.h>
#include <common/standard.h>
@@ -28,7 +29,6 @@
#include <proto/filters.h>
#include <proto/flt_http_comp.h>
#include <proto/http_htx.h>
-#include <proto/htx.h>
#include <proto/proto_http.h>
#include <proto/stream.h>
#include <proto/stream_interface.h>
diff --git a/src/flt_http_comp.c b/src/flt_http_comp.c
index 2d1a7fd..aaab32e 100644
--- a/src/flt_http_comp.c
+++ b/src/flt_http_comp.c
@@ -12,6 +12,7 @@
#include <common/buffer.h>
#include <common/cfgparse.h>
+#include <common/htx.h>
#include <common/initcall.h>
#include <common/mini-clist.h>
#include <common/standard.h>
@@ -26,7 +27,6 @@
#include <proto/filters.h>
#include <proto/hdr_idx.h>
#include <proto/http_htx.h>
-#include <proto/htx.h>
#include <proto/proto_http.h>
#include <proto/sample.h>
#include <proto/stream.h>
diff --git a/src/flt_trace.c b/src/flt_trace.c
index 0ccf1fc..1daeb22 100644
--- a/src/flt_trace.c
+++ b/src/flt_trace.c
@@ -13,6 +13,7 @@
#include <ctype.h>
#include <common/hathreads.h>
+#include <common/htx.h>
#include <common/initcall.h>
#include <common/standard.h>
#include <common/time.h>
@@ -28,7 +29,6 @@
#include <proto/filters.h>
#include <proto/hdr_idx.h>
#include <proto/http_htx.h>
-#include <proto/htx.h>
#include <proto/log.h>
#include <proto/proto_http.h>
#include <proto/stream.h>
diff --git a/src/http_fetch.c b/src/http_fetch.c
index 5f579d1..995622b 100644
--- a/src/http_fetch.c
+++ b/src/http_fetch.c
@@ -22,6 +22,7 @@
#include <common/config.h>
#include <common/debug.h>
#include <common/http.h>
+#include <common/htx.h>
#include <common/initcall.h>
#include <common/memory.h>
#include <common/standard.h>
@@ -33,7 +34,6 @@
#include <proto/auth.h>
#include <proto/http_fetch.h>
#include <proto/http_htx.h>
-#include <proto/htx.h>
#include <proto/log.h>
#include <proto/obj_type.h>
#include <proto/proto_http.h>
diff --git a/src/http_htx.c b/src/http_htx.c
index 83768f6..401e7f1 100644
--- a/src/http_htx.c
+++ b/src/http_htx.c
@@ -13,10 +13,10 @@
#include <common/config.h>
#include <common/cfgparse.h>
#include <common/http.h>
+#include <common/htx.h>
#include <proto/h1.h>
#include <proto/http_htx.h>
-#include <proto/htx.h>
struct buffer htx_err_chunks[HTTP_ERR_SIZE];
diff --git a/src/htx.c b/src/htx.c
index 78bfd57..bda293b 100644
--- a/src/htx.c
+++ b/src/htx.c
@@ -11,7 +11,7 @@
*/
#include <common/chunk.h>
-#include <proto/htx.h>
+#include <common/htx.h>
struct htx htx_empty = { .size = 0, .data = 0, .used = 0 };
diff --git a/src/mux_h1.c b/src/mux_h1.c
index fa3ffa8..037b239 100644
--- a/src/mux_h1.c
+++ b/src/mux_h1.c
@@ -11,6 +11,7 @@
*/
#include <common/cfgparse.h>
#include <common/config.h>
+#include <common/htx.h>
#include <common/initcall.h>
#include <types/pipe.h>
@@ -20,7 +21,6 @@
#include <proto/connection.h>
#include <proto/h1.h>
#include <proto/http_htx.h>
-#include <proto/htx.h>
#include <proto/log.h>
#include <proto/stream.h>
#include <proto/stream_interface.h>
diff --git a/src/mux_h2.c b/src/mux_h2.c
index 15fd304..8962be8 100644
--- a/src/mux_h2.c
+++ b/src/mux_h2.c
@@ -16,12 +16,12 @@
#include <common/hpack-dec.h>
#include <common/hpack-enc.h>
#include <common/hpack-tbl.h>
+#include <common/htx.h>
#include <common/initcall.h>
#include <common/net_helper.h>
#include <proto/connection.h>
#include <proto/h1.h>
#include <proto/http_htx.h>
-#include <proto/htx.h>
#include <proto/stream.h>
#include <types/session.h>
#include <eb32tree.h>
diff --git a/src/proto_htx.c b/src/proto_htx.c
index 2ba383e..6c637cb 100644
--- a/src/proto_htx.c
+++ b/src/proto_htx.c
@@ -13,6 +13,7 @@
#include <common/base64.h>
#include <common/config.h>
#include <common/debug.h>
+#include <common/htx.h>
#include <common/uri_auth.h>
#include <types/cache.h>
@@ -26,7 +27,6 @@
#include <proto/filters.h>
#include <proto/hdr_idx.h>
#include <proto/http_htx.h>
-#include <proto/htx.h>
#include <proto/log.h>
#include <proto/pattern.h>
#include <proto/proto_http.h>
diff --git a/src/stats.c b/src/stats.c
index c85d411..be70dde 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -29,6 +29,7 @@
#include <common/config.h>
#include <common/debug.h>
#include <common/http.h>
+#include <common/htx.h>
#include <common/initcall.h>
#include <common/memory.h>
#include <common/mini-clist.h>
@@ -54,7 +55,6 @@
#include <proto/fd.h>
#include <proto/freq_ctr.h>
#include <proto/frontend.h>
-#include <proto/htx.h>
#include <proto/log.h>
#include <proto/pattern.h>
#include <proto/pipe.h>
diff --git a/src/stream.c b/src/stream.c
index d79f86c..7add3dc 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -19,6 +19,7 @@
#include <common/buffer.h>
#include <common/debug.h>
#include <common/hathreads.h>
+#include <common/htx.h>
#include <common/initcall.h>
#include <common/memory.h>
@@ -46,7 +47,6 @@
#include <proto/hdr_idx.h>
#include <proto/hlua.h>
#include <proto/http_rules.h>
-#include <proto/htx.h>
#include <proto/listener.h>
#include <proto/log.h>
#include <proto/raw_sock.h>