Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/types/htx.h |
| 3 | * This file contains the internal HTTP definitions. |
| 4 | * |
| 5 | * Copyright (C) 2018 HAProxy Technologies, Christopher Faulet <cfaulet@haproxy.com> |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #ifndef _TYPES_HTX_H |
| 23 | #define _TYPES_HTX_H |
| 24 | |
| 25 | #include <common/ist.h> |
| 26 | #include <types/sample.h> |
| 27 | |
| 28 | /* |
| 29 | * The internal representation of an HTTP message is a contiguous array |
| 30 | * containing both the blocks (htx_blk) and their contents. Blocks are stored |
| 31 | * starting from the end of the array while their contents are stored at the |
| 32 | * beginning. |
| 33 | * |
| 34 | * As data are sent to the peer, blocks and contents are released at the |
| 35 | * edges. This free space is reused when no more space left. So blocks and |
| 36 | * contents may wrap, not necessarily the same time. |
| 37 | * |
| 38 | * An HTTP block is as well a header as a body part or a trailer part. For all |
| 39 | * these types of block, a content is attached to the block. It can also be a |
| 40 | * mark, like the end-of-headers or end-of-message. For these blocks, there is |
| 41 | * no content but it count for a byte. It is important to not skip it when data |
| 42 | * are forwarded. An HTTP block is composed of 2 fields: |
| 43 | * |
| 44 | * - .info : It a 32 bits field containing the block's type on 4 bits |
| 45 | * followed by content' length. See below for details. |
| 46 | * |
| 47 | * - .addr : The content's address, if any, relatively to the beginning the |
| 48 | * array used to store the HTTP message itself. |
| 49 | * |
| 50 | * htx_blk.info representation: |
| 51 | * |
| 52 | * 0b 0000 0000 0000 0000 0000 0000 0000 0000 |
| 53 | * ---- ------------------------ --------- |
| 54 | * type value (1 MB max) name length (header) |
| 55 | * ---------------------------------- |
| 56 | * data length (256 MB max) |
| 57 | * (body, method, path, version, status, reason, trailers) |
| 58 | * |
| 59 | * types: |
| 60 | * - 0000 = request start-line |
| 61 | * - 0001 = response start-line |
| 62 | * - 0010 = header |
| 63 | * - 0011 = pseudo-header ou "special" header |
| 64 | * - 0100 = end-of-headers |
| 65 | * - 0101 = data |
| 66 | * - 0110 = end-of-data |
| 67 | * - 0111 = trailer |
| 68 | * - 1000 = end-of-message |
| 69 | * ... |
| 70 | * - 1101 = out-of-band |
| 71 | * - 1110 = error |
| 72 | * - 1111 = unused |
| 73 | * |
| 74 | */ |
| 75 | |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 76 | /*HTX start-line flags */ |
| 77 | #define HTX_SL_F_NONE 0x00000000 |
| 78 | #define HTX_SL_F_IS_RESP 0x00000001 /* It is the response start-line (unset means the request one) */ |
| 79 | #define HTX_SL_F_XFER_LEN 0x00000002 /* The message xfer size can be dertermined */ |
| 80 | #define HTX_SL_F_XFER_ENC 0x00000004 /* The transfer-encoding header was found in message */ |
| 81 | #define HTX_SL_F_CLEN 0x00000008 /* The content-length header was found in message */ |
| 82 | #define HTX_SL_F_CHNK 0x00000010 /* The message payload is chunked */ |
| 83 | #define HTX_SL_F_VER_11 0x00000020 /* The message indicates version 1.1 or above */ |
| 84 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 85 | /* HTX flags */ |
| 86 | #define HTX_FL_NONE 0x00000000 |
| 87 | #define HTX_FL_PARSING_ERROR 0x00000001 |
| 88 | |
| 89 | |
| 90 | /* Pseudo header types (max 255). */ |
| 91 | enum htx_phdr_type { |
| 92 | HTX_PHDR_UNKNOWN = 0, |
| 93 | HTX_PHDR_SIZE, |
| 94 | }; |
| 95 | |
| 96 | /* HTTP block's type (max 15). */ |
| 97 | enum htx_blk_type { |
| 98 | HTX_BLK_REQ_SL = 0, /* Request start-line */ |
| 99 | HTX_BLK_RES_SL = 1, /* Response start-line */ |
| 100 | HTX_BLK_HDR = 2, /* header name/value block */ |
| 101 | HTX_BLK_PHDR = 3, /* pseudo header block */ |
| 102 | HTX_BLK_EOH = 4, /* end-of-headers block */ |
| 103 | HTX_BLK_DATA = 5, /* data block */ |
| 104 | HTX_BLK_EOD = 6, /* end-of-data block */ |
| 105 | HTX_BLK_TLR = 7, /* trailer name/value block */ |
| 106 | HTX_BLK_EOM = 8, /* end-of-message block */ |
| 107 | /* 9 .. 13 unused */ |
| 108 | HTX_BLK_OOB = 14, /* Out of band block, don't alter the parser */ |
| 109 | HTX_BLK_UNUSED = 15, /* unused/removed block */ |
| 110 | }; |
| 111 | |
| 112 | /* One HTTP block descriptor */ |
| 113 | struct htx_blk { |
| 114 | uint32_t addr; /* relative storage address of a data block */ |
| 115 | uint32_t info; /* information about data stored */ |
| 116 | }; |
| 117 | |
| 118 | struct htx_ret { |
| 119 | int32_t ret; |
| 120 | struct htx_blk *blk; |
| 121 | }; |
| 122 | |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 123 | struct htx_sl { |
| 124 | unsigned int flags; /* HTX_SL_F_* */ |
| 125 | union { |
| 126 | struct { |
| 127 | enum http_meth_t meth; /* method */ |
| 128 | } req; |
| 129 | struct { |
| 130 | uint16_t status; /* status code */ |
| 131 | } res; |
| 132 | } info; |
| 133 | |
| 134 | /* XXX 2 bytes unused */ |
| 135 | |
| 136 | unsigned int len[3]; /* length of differnt parts of the start-line */ |
| 137 | char l[0]; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | /* Internal representation of an HTTP message */ |
| 141 | struct htx { |
| 142 | uint32_t size; /* the array size, in bytes, used to store the HTTP message itself */ |
| 143 | uint32_t data; /* the data size, in bytes. To known to total size used by all allocated |
| 144 | * blocks (blocks and their contents), you need to add size used by blocks, |
| 145 | * i.e. [ used * sizeof(struct htx_blk *) ] */ |
| 146 | |
| 147 | uint32_t used; /* number of blocks in use */ |
| 148 | uint32_t tail; /* last inserted block */ |
| 149 | uint32_t front; /* block's position of the first content before the blocks table */ |
| 150 | uint32_t wrap; /* the position were the blocks table wraps, if any */ |
| 151 | |
| 152 | uint64_t extra; /* known bytes amount remaining to receive */ |
| 153 | uint32_t flags; /* HTX_FL_* */ |
| 154 | |
Christopher Faulet | 54483df | 2018-11-26 15:05:52 +0100 | [diff] [blame^] | 155 | int32_t sl_off; /* Offset of the start-line of the HTTP message relatively to the beginning the |
| 156 | data block. -1 if unset */ |
| 157 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 158 | struct htx_blk blocks[0]; /* Blocks representing the HTTP message itself */ |
| 159 | }; |
| 160 | |
| 161 | #endif /* _TYPES_HTX_H */ |
| 162 | |
| 163 | /* |
| 164 | * Local variables: |
| 165 | * c-indent-level: 8 |
| 166 | * c-basic-offset: 8 |
| 167 | * End: |
| 168 | */ |