]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: htx: merge types+proto into common/htx.h
authorWilly Tarreau <w@1wt.eu>
Tue, 11 Dec 2018 09:22:41 +0000 (10:22 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 11 Dec 2018 16:15:04 +0000 (17:15 +0100)
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.

17 files changed:
include/common/h2.h
include/common/htx.h [moved from include/proto/htx.h with 79% similarity]
include/proto/channel.h
include/types/http_htx.h
include/types/htx.h [deleted file]
src/cache.c
src/filters.c
src/flt_http_comp.c
src/flt_trace.c
src/http_fetch.c
src/http_htx.c
src/htx.c
src/mux_h1.c
src/mux_h2.c
src/proto_htx.c
src/stats.c
src/stream.c

index 6c1475bd94efbd5259cc4d6583da7c053ccc64f2..e0684270ca4ee686bc305c2a5a02e2606fce21a6 100644 (file)
@@ -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
similarity index 79%
rename from include/proto/htx.h
rename to include/common/htx.h
index 3fd8fbab19dc0224b999180bbd47e6817aade435..93031cd1fec3dcd4875954354e778b541635414e 100644 (file)
@@ -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>
  * 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 @@ int htx_trailer_to_h1(const struct ist tlr, struct buffer *chk);
 #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 @@ static inline const struct ist htx_sl_p3(const struct htx_sl *sl)
        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 @@ static inline void htx_dump(struct htx *htx)
        fprintf(stderr, "\n");
 }
 
-#endif /* _PROTO_HTX_H */
+#endif /* _COMMON_HTX_H */
 
 /*
  * Local variables:
index dd9b1afa21e951a502707692fd654fde4852e87b..5d9c7a8aa339e1b30d5500c6c169ea96643a7fb6 100644 (file)
@@ -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>
 
index c8f4197d02b7ee9aa0dafaf5e483e0039233a827..3f9a7f4b0787abdad7418e0d132116be152c3af6 100644 (file)
@@ -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 (file)
index 1146b9a..0000000
+++ /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:
- */
index 407d150f9dcd9f9656df3ff3fd0df5867a79c40b..9cfb5350ba761d87936bf589fe90d3e5d752b34c 100644 (file)
@@ -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 */
index d082261b58c053c9a80cc79d40f2618356353c14..4f3fae7e3832d467111b4854275e4d3ade47fc0f 100644 (file)
@@ -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>
index 2d1a7fd42b4e373be4c3d1600e3bb28b9c5ff6a7..aaab32e7266b52dbc81056d1ea17057f75cb424b 100644 (file)
@@ -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>
index 0ccf1fc3f5ca288fd3da25de3ebd0e806b78857f..1daeb22b97d7e5e5cfda18722aab07127c19cea2 100644 (file)
@@ -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>
index 5f579d1f1a79f1ac1e4012f91f056f98f6b9635f..995622b068fe548f8bf8564b6e1790bc551a5a5e 100644 (file)
@@ -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>
index 83768f6fbb211c4839f6b21d6189d722f2b2465d..401e7f1b5576051b3443f48e1f5dbf1c2d86e2cc 100644 (file)
 #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];
 
index 78bfd577273ca8916e206d1daf3035c1b701194a..bda293b43a9fdfe708f10133bf6b41b48f9b0114 100644 (file)
--- 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 };
 
index fa3ffa8d06c77cbaaad1be68ed6b3fd669da487d..037b239e0777bd95f6e55a8747a62356c6863a6a 100644 (file)
@@ -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>
index 15fd304cf1242e869c939e37f7b590479121f7f3..8962be8c8da0f12f9c7f076042932368264c1d8a 100644 (file)
 #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>
index 2ba383e3b7b4a41ad7234c069d3e5309e1b9595f..6c637cb834a8e102c48efdaa903c27ceca431902 100644 (file)
@@ -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>
index c85d411d490eb40e83322de1979f8d173c4d9c7e..be70dde3aa3b7205f781d0a513911dc4064a30aa 100644 (file)
@@ -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>
index d79f86c72784a52637d28007b0a4845c1d5fc3e8..7add3dcc954e65c2c204bf27540787763d5e8b73 100644 (file)
@@ -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>