Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 2 | * include/common/htx.h |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 3 | * This file defines everything related to the internal HTTP messages. |
| 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 | |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 22 | #ifndef _COMMON_HTX_H |
| 23 | #define _COMMON_HTX_H |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 24 | |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 25 | #include <stdio.h> |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 26 | #include <common/buf.h> |
| 27 | #include <common/config.h> |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 28 | #include <common/ist.h> |
| 29 | #include <common/http.h> |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 30 | #include <common/http-hdr.h> |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 31 | #include <common/standard.h> |
| 32 | |
| 33 | /* |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 34 | * The internal representation of an HTTP message, called HTX, is a structure |
| 35 | * with useful information on the message followed by a contiguous array |
| 36 | * containing parts of the message, called blocks. A block is composed of |
| 37 | * metadata (htx_blk) and the associated payload. Blocks' metadata are stored |
| 38 | * starting from the end of the array while their payload are stored at the |
| 39 | * beginning. Blocks' metadata are often simply called blocks. it is a misuse of |
Ilya Shipitsin | 77e3b4a | 2020-03-10 12:06:11 +0500 | [diff] [blame] | 40 | * language that's simplify explanations. |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 41 | * |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 42 | * |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 43 | * +-----+---------------+------------------------------+--------------+ |
| 44 | * | HTX | PAYLOADS ==> | | <== HTX_BLKs | |
| 45 | * +-----+---------------+------------------------------+--------------+ |
| 46 | * ^ |
| 47 | * blocks[] (the beginning of the bocks array) |
| 48 | * |
| 49 | * |
| 50 | * The blocks part remains linear and sorted. You may think about it as an array |
| 51 | * with negative indexes. But, instead of using negative indexes, we use |
| 52 | * positive positions to identify a block. This position is then converted to a |
| 53 | * address relatively to the beginning of the blocks array. |
| 54 | * |
| 55 | * |
| 56 | * .....--+------------------------------+-----+-----+ |
| 57 | * | ... | BLK | BLK | |
| 58 | * .....--+------------------------------+-----+-----+ |
| 59 | * ^ ^ |
| 60 | * Addr of the block Addr of the block |
| 61 | * at the position 1 at the position 0 |
| 62 | * |
| 63 | * |
| 64 | * The payloads part is a raw space that may wrap. You never access to a block's |
| 65 | * payload directly. Instead you get a block to retrieve the address of its |
| 66 | * payload. When no more space left between blocks and payloads parts, the free |
| 67 | * space at the beginning, if any, is used. |
| 68 | * |
| 69 | * |
| 70 | * +----------- WRAPPING ------------------------+ |
| 71 | * | | |
| 72 | * V | |
| 73 | * +-----+-------------+---------------+---------------++--------------+ |
| 74 | * | HTX | PAYLOAD ==> | | PAYLOADS ==X || X== HTX_BLKs | |
| 75 | * +-----+-------------+---------------+---------------++--------------+ |
| 76 | * |
| 77 | * |
| 78 | * The blocks part, on its side, never wrap. If we have no space to allocate a |
| 79 | * new block and if there is a hole at the beginning of the blocks part (so at |
| 80 | * the end of the blocks array), we move back all blocks.x |
| 81 | * |
| 82 | * |
| 83 | * ...+--------------+----------+ blocks ...+----------+--------------+ |
| 84 | * | X== HTX_BLKS | | defrag | | <== HTX_BLKS | |
| 85 | * ...+--------------+----------+ =====> ...+----------+--------------+ |
| 86 | * |
| 87 | * |
| 88 | * At the end, if payload wrapping or blocks defragmenation is not enough, some |
| 89 | * free space may be get back with a full defragmenation. This way, the holes in |
| 90 | * the middle are not reusable but count in the available free space. The only |
| 91 | * way to reuse this lost space is to fully defragmenate the HTX message. |
| 92 | * |
| 93 | * - * - |
| 94 | * |
| 95 | * An HTX block is as well a header as a body part or a trailer. For all these |
| 96 | * types of block, a payload is attached to the block. It can also be a mark, |
| 97 | * like the end-of-headers or end-of-message. For these blocks, there is no |
| 98 | * payload but it count for a byte. It is important to not skip it when data are |
| 99 | * forwarded. Metadata of an HTX block are composed of 2 fields : |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 100 | * |
| 101 | * - .info : It a 32 bits field containing the block's type on 4 bits |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 102 | * followed by the payload length. See below for details. |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 103 | * |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 104 | * - .addr : The payload's address, if any, relatively to the beginning the |
| 105 | * array used to store the HTX message itself. |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 106 | * |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 107 | * htx_blk.info representation : |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 108 | * |
| 109 | * 0b 0000 0000 0000 0000 0000 0000 0000 0000 |
| 110 | * ---- ------------------------ --------- |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 111 | * type value (1 MB max) name length (header/trailer) |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 112 | * ---------------------------------- |
| 113 | * data length (256 MB max) |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 114 | * (body, method, path, version, status, reason) |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 115 | * |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 116 | * types : |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 117 | * - 0000 = request start-line |
| 118 | * - 0001 = response start-line |
| 119 | * - 0010 = header |
| 120 | * - 0011 = pseudo-header ou "special" header |
| 121 | * - 0100 = end-of-headers |
| 122 | * - 0101 = data |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 123 | * - 0110 = trailer |
| 124 | * - 0111 = end-of-trailers |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 125 | * - 1000 = end-of-message |
| 126 | * ... |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 127 | * - 1111 = unused |
| 128 | * |
| 129 | */ |
| 130 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 131 | /* HTX start-line flags */ |
Christopher Faulet | 9a67c29 | 2019-10-08 14:27:52 +0200 | [diff] [blame] | 132 | #define HTX_SL_F_NONE 0x00000000 |
| 133 | #define HTX_SL_F_IS_RESP 0x00000001 /* It is the response start-line (unset means the request one) */ |
| 134 | #define HTX_SL_F_XFER_LEN 0x00000002 /* The message xfer size can be dertermined */ |
| 135 | #define HTX_SL_F_XFER_ENC 0x00000004 /* The transfer-encoding header was found in message */ |
| 136 | #define HTX_SL_F_CLEN 0x00000008 /* The content-length header was found in message */ |
| 137 | #define HTX_SL_F_CHNK 0x00000010 /* The message payload is chunked */ |
| 138 | #define HTX_SL_F_VER_11 0x00000020 /* The message indicates version 1.1 or above */ |
| 139 | #define HTX_SL_F_BODYLESS 0x00000040 /* The message has no body (content-length = 0) */ |
| 140 | #define HTX_SL_F_HAS_SCHM 0x00000080 /* The scheme is explicitly specified */ |
| 141 | #define HTX_SL_F_SCHM_HTTP 0x00000100 /* The scheme HTTP should be used */ |
| 142 | #define HTX_SL_F_SCHM_HTTPS 0x00000200 /* The scheme HTTPS should be used */ |
| 143 | #define HTX_SL_F_HAS_AUTHORITY 0x00000400 /* The request authority is explicitly specified */ |
| 144 | #define HTX_SL_F_NORMALIZED_URI 0x00000800 /* The received URI is normalized (an implicit absolute-uri form) */ |
| 145 | |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 146 | |
| 147 | /* HTX flags */ |
| 148 | #define HTX_FL_NONE 0x00000000 |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 149 | #define HTX_FL_PARSING_ERROR 0x00000001 /* Set when a parsing error occurred */ |
Christopher Faulet | 505adfc | 2019-09-06 19:08:27 +0200 | [diff] [blame] | 150 | #define HTX_FL_PROCESSING_ERROR 0x00000002 /* Set when a processing error occurred */ |
| 151 | #define HTX_FL_UPGRADE 0x00000004 /* Set when an upgrade is in progress */ |
Christopher Faulet | 0651181 | 2019-10-16 09:38:27 +0200 | [diff] [blame] | 152 | #define HTX_FL_PROXY_RESP 0x00000008 /* Set when the response was generated by HAProxy */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 153 | |
| 154 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 155 | /* HTX block's type (max 15). */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 156 | enum htx_blk_type { |
| 157 | HTX_BLK_REQ_SL = 0, /* Request start-line */ |
| 158 | HTX_BLK_RES_SL = 1, /* Response start-line */ |
| 159 | HTX_BLK_HDR = 2, /* header name/value block */ |
Christopher Faulet | 39744f7 | 2019-05-24 14:54:00 +0200 | [diff] [blame] | 160 | HTX_BLK_EOH = 3, /* end-of-headers block */ |
| 161 | HTX_BLK_DATA = 4, /* data block */ |
Christopher Faulet | 54b5e21 | 2019-06-04 10:08:28 +0200 | [diff] [blame] | 162 | HTX_BLK_TLR = 5, /* trailer name/value block */ |
| 163 | HTX_BLK_EOT = 6, /* end-of-trailers block */ |
| 164 | HTX_BLK_EOM = 7, /* end-of-message block */ |
Christopher Faulet | 39744f7 | 2019-05-24 14:54:00 +0200 | [diff] [blame] | 165 | /* 8 .. 14 unused */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 166 | HTX_BLK_UNUSED = 15, /* unused/removed block */ |
| 167 | }; |
| 168 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 169 | /* One HTX block descriptor */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 170 | struct htx_blk { |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 171 | uint32_t addr; /* relative storage address of the block's payload */ |
| 172 | uint32_t info; /* information about the block (type, length) */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 173 | }; |
| 174 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 175 | /* Composite return value used by some HTX functions */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 176 | struct htx_ret { |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 177 | int32_t ret; /* A numerical value */ |
| 178 | struct htx_blk *blk; /* An HTX block */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 179 | }; |
| 180 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 181 | /* HTX start-line */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 182 | struct htx_sl { |
| 183 | unsigned int flags; /* HTX_SL_F_* */ |
| 184 | union { |
| 185 | struct { |
| 186 | enum http_meth_t meth; /* method */ |
| 187 | } req; |
| 188 | struct { |
| 189 | uint16_t status; /* status code */ |
| 190 | } res; |
| 191 | } info; |
| 192 | |
| 193 | /* XXX 2 bytes unused */ |
| 194 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 195 | int32_t hdrs_bytes; /* Bytes held by all headers, as seen by the mux |
| 196 | * during parsing, from this start-line to the |
| 197 | * corresponding EOH. -1 if unknown */ |
Christopher Faulet | 05c083c | 2019-05-15 14:56:47 +0200 | [diff] [blame] | 198 | |
Ilya Shipitsin | 77e3b4a | 2020-03-10 12:06:11 +0500 | [diff] [blame] | 199 | unsigned int len[3]; /* length of different parts of the start-line */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 200 | char l[0]; |
| 201 | }; |
| 202 | |
| 203 | /* Internal representation of an HTTP message */ |
| 204 | struct htx { |
| 205 | uint32_t size; /* the array size, in bytes, used to store the HTTP message itself */ |
| 206 | uint32_t data; /* the data size, in bytes. To known to total size used by all allocated |
| 207 | * blocks (blocks and their contents), you need to add size used by blocks, |
| 208 | * i.e. [ used * sizeof(struct htx_blk *) ] */ |
| 209 | |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 210 | int32_t tail; /* newest inserted block. -1 if the HTX message is empty */ |
| 211 | int32_t head; /* oldest inserted block. -1 if the HTX message is empty */ |
| 212 | int32_t first; /* position of the first block to (re)start the analyse. -1 if unset. */ |
Christopher Faulet | d7884d3 | 2019-06-11 10:40:43 +0200 | [diff] [blame] | 213 | |
| 214 | uint32_t tail_addr; /* start address of the free space in front of the the blocks table */ |
| 215 | uint32_t head_addr; /* start address of the free space at the beginning */ |
| 216 | uint32_t end_addr; /* end address of the free space at the beginning */ |
| 217 | |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 218 | uint64_t extra; /* known bytes amount remaining to receive */ |
| 219 | uint32_t flags; /* HTX_FL_* */ |
| 220 | |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 221 | /* XXX 4 bytes unused */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 222 | |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 223 | /* Blocks representing the HTTP message itself */ |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 224 | char blocks[0] __attribute__((aligned(8))); |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 225 | }; |
| 226 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 227 | |
| 228 | extern struct htx htx_empty; |
| 229 | |
| 230 | struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk); |
| 231 | struct htx_blk *htx_add_blk(struct htx *htx, enum htx_blk_type type, uint32_t blksz); |
| 232 | struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk); |
Christopher Faulet | 1cdceb9 | 2020-02-24 11:41:59 +0100 | [diff] [blame] | 233 | struct htx_ret htx_find_offset(struct htx *htx, uint32_t offset); |
Christopher Faulet | 00cf697 | 2019-01-07 14:53:27 +0100 | [diff] [blame] | 234 | void htx_truncate(struct htx *htx, uint32_t offset); |
Christopher Faulet | 549822f | 2019-02-25 10:23:19 +0100 | [diff] [blame] | 235 | struct htx_ret htx_drain(struct htx *htx, uint32_t max); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 236 | |
| 237 | struct htx_blk *htx_replace_blk_value(struct htx *htx, struct htx_blk *blk, |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 238 | const struct ist old, const struct ist new); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 239 | struct htx_ret htx_xfer_blks(struct htx *dst, struct htx *src, uint32_t count, |
| 240 | enum htx_blk_type mark); |
| 241 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 242 | struct htx_sl *htx_add_stline(struct htx *htx, enum htx_blk_type type, unsigned int flags, |
| 243 | const struct ist p1, const struct ist p2, const struct ist p3); |
| 244 | struct htx_sl *htx_replace_stline(struct htx *htx, struct htx_blk *blk, const struct ist p1, |
| 245 | const struct ist p2, const struct ist p3); |
| 246 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 247 | struct htx_blk *htx_replace_header(struct htx *htx, struct htx_blk *blk, |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 248 | const struct ist name, const struct ist value); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 249 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 250 | struct htx_blk *htx_add_header(struct htx *htx, const struct ist name, const struct ist value); |
Christopher Faulet | 2d7c539 | 2019-06-03 10:41:26 +0200 | [diff] [blame] | 251 | struct htx_blk *htx_add_trailer(struct htx *htx, const struct ist name, const struct ist value); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 252 | struct htx_blk *htx_add_all_headers(struct htx *htx, const struct http_hdr *hdrs); |
Christopher Faulet | 2d7c539 | 2019-06-03 10:41:26 +0200 | [diff] [blame] | 253 | struct htx_blk *htx_add_all_trailers(struct htx *htx, const struct http_hdr *hdrs); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 254 | struct htx_blk *htx_add_endof(struct htx *htx, enum htx_blk_type type); |
Christopher Faulet | d7884d3 | 2019-06-11 10:40:43 +0200 | [diff] [blame] | 255 | struct htx_blk *htx_add_data_atonce(struct htx *htx, struct ist data); |
Willy Tarreau | 0a7ef02 | 2019-05-28 10:30:11 +0200 | [diff] [blame] | 256 | size_t htx_add_data(struct htx *htx, const struct ist data); |
Christopher Faulet | 86bc8df | 2019-06-11 10:38:38 +0200 | [diff] [blame] | 257 | struct htx_blk *htx_add_last_data(struct htx *htx, struct ist data); |
Christopher Faulet | 86fcf6d | 2019-06-11 10:41:19 +0200 | [diff] [blame] | 258 | void htx_move_blk_before(struct htx *htx, struct htx_blk **blk, struct htx_blk **ref); |
Christopher Faulet | 0ea0c86 | 2020-01-23 11:47:53 +0100 | [diff] [blame] | 259 | int htx_append_msg(struct htx *dst, const struct htx *src); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 260 | |
Ilya Shipitsin | 77e3b4a | 2020-03-10 12:06:11 +0500 | [diff] [blame] | 261 | /* Functions and macros to get parts of the start-line or length of these |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 262 | * parts. Request and response start-lines are both composed of 3 parts. |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 263 | */ |
| 264 | #define HTX_SL_LEN(sl) ((sl)->len[0] + (sl)->len[1] + (sl)->len[2]) |
| 265 | |
| 266 | #define HTX_SL_P1_LEN(sl) ((sl)->len[0]) |
| 267 | #define HTX_SL_P2_LEN(sl) ((sl)->len[1]) |
| 268 | #define HTX_SL_P3_LEN(sl) ((sl)->len[2]) |
| 269 | #define HTX_SL_P1_PTR(sl) ((sl)->l) |
| 270 | #define HTX_SL_P2_PTR(sl) (HTX_SL_P1_PTR(sl) + HTX_SL_P1_LEN(sl)) |
| 271 | #define HTX_SL_P3_PTR(sl) (HTX_SL_P2_PTR(sl) + HTX_SL_P2_LEN(sl)) |
| 272 | |
| 273 | #define HTX_SL_REQ_MLEN(sl) HTX_SL_P1_LEN(sl) |
| 274 | #define HTX_SL_REQ_ULEN(sl) HTX_SL_P2_LEN(sl) |
| 275 | #define HTX_SL_REQ_VLEN(sl) HTX_SL_P3_LEN(sl) |
| 276 | #define HTX_SL_REQ_MPTR(sl) HTX_SL_P1_PTR(sl) |
| 277 | #define HTX_SL_REQ_UPTR(sl) HTX_SL_P2_PTR(sl) |
| 278 | #define HTX_SL_REQ_VPTR(sl) HTX_SL_P3_PTR(sl) |
| 279 | |
| 280 | #define HTX_SL_RES_VLEN(sl) HTX_SL_P1_LEN(sl) |
| 281 | #define HTX_SL_RES_CLEN(sl) HTX_SL_P2_LEN(sl) |
| 282 | #define HTX_SL_RES_RLEN(sl) HTX_SL_P3_LEN(sl) |
| 283 | #define HTX_SL_RES_VPTR(sl) HTX_SL_P1_PTR(sl) |
| 284 | #define HTX_SL_RES_CPTR(sl) HTX_SL_P2_PTR(sl) |
| 285 | #define HTX_SL_RES_RPTR(sl) HTX_SL_P3_PTR(sl) |
| 286 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 287 | static inline struct ist htx_sl_p1(const struct htx_sl *sl) |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 288 | { |
| 289 | return ist2(HTX_SL_P1_PTR(sl), HTX_SL_P1_LEN(sl)); |
| 290 | } |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 291 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 292 | static inline struct ist htx_sl_p2(const struct htx_sl *sl) |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 293 | { |
| 294 | return ist2(HTX_SL_P2_PTR(sl), HTX_SL_P2_LEN(sl)); |
| 295 | } |
| 296 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 297 | static inline struct ist htx_sl_p3(const struct htx_sl *sl) |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 298 | { |
| 299 | return ist2(HTX_SL_P3_PTR(sl), HTX_SL_P3_LEN(sl)); |
| 300 | } |
| 301 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 302 | static inline struct ist htx_sl_req_meth(const struct htx_sl *sl) |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 303 | { |
| 304 | return htx_sl_p1(sl); |
| 305 | } |
| 306 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 307 | static inline struct ist htx_sl_req_uri(const struct htx_sl *sl) |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 308 | { |
| 309 | return htx_sl_p2(sl); |
| 310 | } |
| 311 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 312 | static inline struct ist htx_sl_req_vsn(const struct htx_sl *sl) |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 313 | { |
| 314 | return htx_sl_p3(sl); |
| 315 | } |
| 316 | |
| 317 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 318 | static inline struct ist htx_sl_res_vsn(const struct htx_sl *sl) |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 319 | { |
| 320 | return htx_sl_p1(sl); |
| 321 | } |
| 322 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 323 | static inline struct ist htx_sl_res_code(const struct htx_sl *sl) |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 324 | { |
| 325 | return htx_sl_p2(sl); |
| 326 | } |
| 327 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 328 | static inline struct ist htx_sl_res_reason(const struct htx_sl *sl) |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 329 | { |
| 330 | return htx_sl_p3(sl); |
| 331 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 332 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 333 | /* Converts a position to the corresponding relative address */ |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 334 | static inline uint32_t htx_pos_to_addr(const struct htx *htx, uint32_t pos) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 335 | { |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 336 | return htx->size - (pos + 1) * sizeof(struct htx_blk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 339 | /* Returns the position of the block <blk>. It is the caller responsibility to |
| 340 | * be sure <blk> is part of <htx>. */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 341 | static inline uint32_t htx_get_blk_pos(const struct htx *htx, const struct htx_blk *blk) |
| 342 | { |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 343 | return ((htx->blocks + htx->size - (char *)blk) / sizeof(struct htx_blk) - 1); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 344 | } |
| 345 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 346 | /* Returns the block at the position <pos>. It is the caller responsibility to |
| 347 | * be sure the block at the position <pos> exists. */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 348 | static inline struct htx_blk *htx_get_blk(const struct htx *htx, uint32_t pos) |
| 349 | { |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 350 | return (struct htx_blk *)(htx->blocks + htx_pos_to_addr(htx, pos)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /* Returns the type of the block <blk> */ |
| 354 | static inline enum htx_blk_type htx_get_blk_type(const struct htx_blk *blk) |
| 355 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 356 | return (blk->info >> 28); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 357 | } |
| 358 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 359 | /* Returns the size of the block <blk>, depending of its type */ |
| 360 | static inline uint32_t htx_get_blksz(const struct htx_blk *blk) |
| 361 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 362 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 363 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 364 | switch (type) { |
| 365 | case HTX_BLK_HDR: |
Christopher Faulet | 2d7c539 | 2019-06-03 10:41:26 +0200 | [diff] [blame] | 366 | case HTX_BLK_TLR: |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 367 | /* name.length + value.length */ |
| 368 | return ((blk->info & 0xff) + ((blk->info >> 8) & 0xfffff)); |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 369 | default: |
| 370 | /* value.length */ |
| 371 | return (blk->info & 0xfffffff); |
| 372 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 373 | } |
| 374 | |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 375 | /* Returns the position of the oldest entry (head). It returns a signed 32-bits |
| 376 | * integer, -1 means the HTX message is empty. |
Christopher Faulet | 28f29c7 | 2019-04-30 17:55:45 +0200 | [diff] [blame] | 377 | */ |
| 378 | static inline int32_t htx_get_head(const struct htx *htx) |
| 379 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 380 | return htx->head; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /* Returns the oldest HTX block (head) if the HTX message is not |
| 384 | * empty. Otherwise it returns NULL. |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 385 | */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 386 | static inline struct htx_blk *htx_get_head_blk(const struct htx *htx) |
| 387 | { |
| 388 | int32_t head = htx_get_head(htx); |
| 389 | |
| 390 | return ((head == -1) ? NULL : htx_get_blk(htx, head)); |
| 391 | } |
| 392 | |
| 393 | /* Returns the type of the oldest HTX block (head) if the HTX message is not |
| 394 | * empty. Otherwise it returns HTX_BLK_UNUSED. |
| 395 | */ |
| 396 | static inline enum htx_blk_type htx_get_head_type(const struct htx *htx) |
| 397 | { |
| 398 | struct htx_blk *blk = htx_get_head_blk(htx); |
| 399 | |
| 400 | return (blk ? htx_get_blk_type(blk) : HTX_BLK_UNUSED); |
| 401 | } |
| 402 | |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 403 | /* Returns the position of the newest entry (tail). It returns a signed 32-bits |
| 404 | * integer, -1 means the HTX message is empty. |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 405 | */ |
| 406 | static inline int32_t htx_get_tail(const struct htx *htx) |
| 407 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 408 | return htx->tail; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | /* Returns the newest HTX block (tail) if the HTX message is not |
| 412 | * empty. Otherwise it returns NULL. |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 413 | */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 414 | static inline struct htx_blk *htx_get_tail_blk(const struct htx *htx) |
| 415 | { |
| 416 | int32_t tail = htx_get_tail(htx); |
| 417 | |
| 418 | return ((tail == -1) ? NULL : htx_get_blk(htx, tail)); |
| 419 | } |
| 420 | |
| 421 | /* Returns the type of the newest HTX block (tail) if the HTX message is not |
| 422 | * empty. Otherwise it returns HTX_BLK_UNUSED. |
| 423 | */ |
| 424 | static inline enum htx_blk_type htx_get_tail_type(const struct htx *htx) |
| 425 | { |
| 426 | struct htx_blk *blk = htx_get_tail_blk(htx); |
| 427 | |
| 428 | return (blk ? htx_get_blk_type(blk) : HTX_BLK_UNUSED); |
| 429 | } |
| 430 | |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 431 | /* Returns the position of the first block in the HTX message <htx>. -1 means |
| 432 | * the first block is unset or the HTS is empty. |
Christopher Faulet | a3ad6b1 | 2019-05-13 11:36:27 +0200 | [diff] [blame] | 433 | */ |
| 434 | static inline int32_t htx_get_first(const struct htx *htx) |
| 435 | { |
Christopher Faulet | 29f1758 | 2019-05-23 11:03:26 +0200 | [diff] [blame] | 436 | return htx->first; |
Christopher Faulet | a3ad6b1 | 2019-05-13 11:36:27 +0200 | [diff] [blame] | 437 | } |
| 438 | |
Christopher Faulet | 29f1758 | 2019-05-23 11:03:26 +0200 | [diff] [blame] | 439 | /* Returns the first HTX block in the HTX message <htx>. If unset or if <htx> is |
| 440 | * empty, NULL returned. |
Christopher Faulet | a3ad6b1 | 2019-05-13 11:36:27 +0200 | [diff] [blame] | 441 | */ |
| 442 | static inline struct htx_blk *htx_get_first_blk(const struct htx *htx) |
| 443 | { |
| 444 | int32_t pos; |
| 445 | |
| 446 | pos = htx_get_first(htx); |
| 447 | return ((pos == -1) ? NULL : htx_get_blk(htx, pos)); |
| 448 | } |
| 449 | |
| 450 | /* Returns the type of the first block in the HTX message <htx>. If unset or if |
| 451 | * <htx> is empty, HTX_BLK_UNUSED is returned. |
| 452 | */ |
| 453 | static inline enum htx_blk_type htx_get_first_type(const struct htx *htx) |
| 454 | { |
| 455 | struct htx_blk *blk = htx_get_first_blk(htx); |
| 456 | |
| 457 | return (blk ? htx_get_blk_type(blk) : HTX_BLK_UNUSED); |
| 458 | } |
| 459 | |
Joseph Herlant | c42c0e9 | 2018-11-25 10:43:27 -0800 | [diff] [blame] | 460 | /* Returns the position of block immediately before the one pointed by <pos>. If |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 461 | * the message is empty or if <pos> is the position of the head, -1 returned. |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 462 | */ |
| 463 | static inline int32_t htx_get_prev(const struct htx *htx, uint32_t pos) |
| 464 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 465 | if (htx->head == -1 || pos == htx->head) |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 466 | return -1; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 467 | return (pos - 1); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 468 | } |
| 469 | |
Christopher Faulet | d16b0a7 | 2018-11-22 11:23:23 +0100 | [diff] [blame] | 470 | /* Returns the HTX block before <blk> in the HTX message <htx>. If <blk> is the |
| 471 | * head, NULL returned. |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 472 | */ |
Christopher Faulet | d16b0a7 | 2018-11-22 11:23:23 +0100 | [diff] [blame] | 473 | static inline struct htx_blk *htx_get_prev_blk(const struct htx *htx, |
| 474 | const struct htx_blk *blk) |
| 475 | { |
| 476 | int32_t pos; |
| 477 | |
| 478 | pos = htx_get_prev(htx, htx_get_blk_pos(htx, blk)); |
| 479 | return ((pos == -1) ? NULL : htx_get_blk(htx, pos)); |
| 480 | } |
| 481 | |
Joseph Herlant | c42c0e9 | 2018-11-25 10:43:27 -0800 | [diff] [blame] | 482 | /* Returns the position of block immediately after the one pointed by <pos>. If |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 483 | * the message is empty or if <pos> is the position of the tail, -1 returned. |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 484 | */ |
| 485 | static inline int32_t htx_get_next(const struct htx *htx, uint32_t pos) |
| 486 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 487 | if (htx->tail == -1 || pos == htx->tail) |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 488 | return -1; |
Christopher Faulet | d7884d3 | 2019-06-11 10:40:43 +0200 | [diff] [blame] | 489 | return (pos + 1); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 490 | |
| 491 | } |
Christopher Faulet | d16b0a7 | 2018-11-22 11:23:23 +0100 | [diff] [blame] | 492 | |
| 493 | /* Returns the HTX block after <blk> in the HTX message <htx>. If <blk> is the |
| 494 | * tail, NULL returned. |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 495 | */ |
Christopher Faulet | d16b0a7 | 2018-11-22 11:23:23 +0100 | [diff] [blame] | 496 | static inline struct htx_blk *htx_get_next_blk(const struct htx *htx, |
| 497 | const struct htx_blk *blk) |
| 498 | { |
| 499 | int32_t pos; |
| 500 | |
| 501 | pos = htx_get_next(htx, htx_get_blk_pos(htx, blk)); |
| 502 | return ((pos == -1) ? NULL : htx_get_blk(htx, pos)); |
| 503 | } |
| 504 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 505 | /* Changes the size of the value. It is the caller responsibility to change the |
Christopher Faulet | bb0efcd | 2019-06-18 09:37:00 +0200 | [diff] [blame] | 506 | * value itself, make sure there is enough space and update allocated |
| 507 | * value. This function updates the HTX message accordingly. |
| 508 | */ |
| 509 | static inline void htx_change_blk_value_len(struct htx *htx, struct htx_blk *blk, uint32_t newlen) |
| 510 | { |
| 511 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 512 | uint32_t oldlen, sz; |
| 513 | int32_t delta; |
| 514 | |
| 515 | sz = htx_get_blksz(blk); |
| 516 | switch (type) { |
| 517 | case HTX_BLK_HDR: |
| 518 | case HTX_BLK_TLR: |
| 519 | oldlen = (blk->info >> 8) & 0xfffff; |
| 520 | blk->info = (type << 28) + (newlen << 8) + (blk->info & 0xff); |
| 521 | break; |
| 522 | default: |
| 523 | oldlen = blk->info & 0xfffffff; |
| 524 | blk->info = (type << 28) + newlen; |
| 525 | break; |
| 526 | } |
| 527 | |
| 528 | /* Update HTTP message */ |
| 529 | delta = (newlen - oldlen); |
| 530 | htx->data += delta; |
| 531 | if (blk->addr+sz == htx->tail_addr) |
| 532 | htx->tail_addr += delta; |
| 533 | else if (blk->addr+sz == htx->head_addr) |
| 534 | htx->head_addr += delta; |
| 535 | } |
| 536 | |
| 537 | /* Changes the size of the value. It is the caller responsibility to change the |
| 538 | * value itself, make sure there is enough space and update allocated |
| 539 | * value. Unlike the function htx_change_blk_value_len(), this one does not |
| 540 | * update the HTX message. So it should be used with caution. |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 541 | */ |
| 542 | static inline void htx_set_blk_value_len(struct htx_blk *blk, uint32_t vlen) |
| 543 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 544 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 545 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 546 | switch (type) { |
| 547 | case HTX_BLK_HDR: |
Christopher Faulet | 2d7c539 | 2019-06-03 10:41:26 +0200 | [diff] [blame] | 548 | case HTX_BLK_TLR: |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 549 | blk->info = (type << 28) + (vlen << 8) + (blk->info & 0xff); |
| 550 | break; |
| 551 | case HTX_BLK_REQ_SL: |
| 552 | case HTX_BLK_RES_SL: |
| 553 | case HTX_BLK_DATA: |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 554 | blk->info = (type << 28) + vlen; |
| 555 | break; |
| 556 | default: |
| 557 | /* Unexpected case */ |
| 558 | break; |
| 559 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | /* Returns the data pointer of the block <blk> */ |
| 563 | static inline void *htx_get_blk_ptr(const struct htx *htx, const struct htx_blk *blk) |
| 564 | { |
| 565 | return ((void *)htx->blocks + blk->addr); |
| 566 | } |
| 567 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 568 | /* Returns the name of the block <blk>, only if it is a header or a |
| 569 | * trailer. Otherwise it returns an empty string. |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 570 | */ |
| 571 | static inline struct ist htx_get_blk_name(const struct htx *htx, const struct htx_blk *blk) |
| 572 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 573 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 574 | struct ist ret; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 575 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 576 | switch (type) { |
| 577 | case HTX_BLK_HDR: |
Christopher Faulet | 2d7c539 | 2019-06-03 10:41:26 +0200 | [diff] [blame] | 578 | case HTX_BLK_TLR: |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 579 | ret.ptr = htx_get_blk_ptr(htx, blk); |
| 580 | ret.len = blk->info & 0xff; |
| 581 | break; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 582 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 583 | default: |
| 584 | return ist(""); |
| 585 | } |
| 586 | return ret; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 587 | } |
| 588 | |
Christopher Faulet | 54483df | 2018-11-26 15:05:52 +0100 | [diff] [blame] | 589 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 590 | /* Returns the value of the block <blk>, depending on its type. If there is no |
Ilya Shipitsin | 77e3b4a | 2020-03-10 12:06:11 +0500 | [diff] [blame] | 591 | * value (for end-of blocks), an empty one is returned. |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 592 | */ |
| 593 | static inline struct ist htx_get_blk_value(const struct htx *htx, const struct htx_blk *blk) |
| 594 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 595 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 596 | struct ist ret; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 597 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 598 | switch (type) { |
| 599 | case HTX_BLK_HDR: |
Christopher Faulet | 2d7c539 | 2019-06-03 10:41:26 +0200 | [diff] [blame] | 600 | case HTX_BLK_TLR: |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 601 | ret.ptr = htx_get_blk_ptr(htx, blk) + (blk->info & 0xff); |
| 602 | ret.len = (blk->info >> 8) & 0xfffff; |
| 603 | break; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 604 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 605 | case HTX_BLK_REQ_SL: |
| 606 | case HTX_BLK_RES_SL: |
| 607 | case HTX_BLK_DATA: |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 608 | ret.ptr = htx_get_blk_ptr(htx, blk); |
| 609 | ret.len = blk->info & 0xfffffff; |
| 610 | break; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 611 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 612 | default: |
| 613 | return ist(""); |
| 614 | } |
| 615 | return ret; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 616 | } |
| 617 | |
Willy Tarreau | c01ed9f | 2018-11-30 14:29:31 +0100 | [diff] [blame] | 618 | /* Removes <n> bytes from the beginning of DATA block <blk>. The block's start |
| 619 | * address and its length are adjusted, and the htx's total data count is |
Ilya Shipitsin | 77e3b4a | 2020-03-10 12:06:11 +0500 | [diff] [blame] | 620 | * updated. This is used to mark that part of some data were transferred |
Willy Tarreau | c01ed9f | 2018-11-30 14:29:31 +0100 | [diff] [blame] | 621 | * from a DATA block without removing this DATA block. No sanity check is |
Ilya Shipitsin | 77e3b4a | 2020-03-10 12:06:11 +0500 | [diff] [blame] | 622 | * performed, the caller is responsible for doing this exclusively on DATA |
Willy Tarreau | c01ed9f | 2018-11-30 14:29:31 +0100 | [diff] [blame] | 623 | * blocks, and never removing more than the block's size. |
| 624 | */ |
| 625 | static inline void htx_cut_data_blk(struct htx *htx, struct htx_blk *blk, uint32_t n) |
| 626 | { |
Christopher Faulet | d7884d3 | 2019-06-11 10:40:43 +0200 | [diff] [blame] | 627 | if (blk->addr == htx->end_addr) |
| 628 | htx->end_addr += n; |
Willy Tarreau | c01ed9f | 2018-11-30 14:29:31 +0100 | [diff] [blame] | 629 | blk->addr += n; |
| 630 | blk->info -= n; |
| 631 | htx->data -= n; |
| 632 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 633 | |
| 634 | /* Returns the space used by metadata in <htx>. */ |
| 635 | static inline uint32_t htx_meta_space(const struct htx *htx) |
| 636 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 637 | if (htx->tail == -1) |
| 638 | return 0; |
| 639 | |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 640 | return ((htx->tail + 1 - htx->head) * sizeof(struct htx_blk)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 641 | } |
| 642 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 643 | /* Returns the space used (payload + metadata) in <htx> */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 644 | static inline uint32_t htx_used_space(const struct htx *htx) |
| 645 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 646 | return (htx->data + htx_meta_space(htx)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | /* Returns the free space in <htx> */ |
| 650 | static inline uint32_t htx_free_space(const struct htx *htx) |
| 651 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 652 | return (htx->size - htx_used_space(htx)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | /* Returns the maximum size available to store some data in <htx> if a new block |
| 656 | * is reserved. |
| 657 | */ |
| 658 | static inline uint32_t htx_free_data_space(const struct htx *htx) |
| 659 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 660 | uint32_t free = htx_free_space(htx); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 661 | |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 662 | if (free < sizeof(struct htx_blk)) |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 663 | return 0; |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 664 | return (free - sizeof(struct htx_blk)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 665 | } |
| 666 | |
Christopher Faulet | 2ae3504 | 2019-05-16 11:16:39 +0200 | [diff] [blame] | 667 | /* Returns the maximum size for a block, not exceeding <max> bytes. <max> may be |
| 668 | * set to -1 to have no limit. |
| 669 | */ |
| 670 | static inline uint32_t htx_get_max_blksz(const struct htx *htx, int32_t max) |
| 671 | { |
| 672 | uint32_t free = htx_free_space(htx); |
| 673 | |
| 674 | if (max != -1 && free > max) |
| 675 | free = max; |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 676 | if (free < sizeof(struct htx_blk)) |
Christopher Faulet | 2ae3504 | 2019-05-16 11:16:39 +0200 | [diff] [blame] | 677 | return 0; |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 678 | return (free - sizeof(struct htx_blk)); |
Christopher Faulet | 2ae3504 | 2019-05-16 11:16:39 +0200 | [diff] [blame] | 679 | } |
| 680 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 681 | /* Returns 1 if the message has less than 1/4 of its capacity free, otherwise 0 */ |
| 682 | static inline int htx_almost_full(const struct htx *htx) |
| 683 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 684 | if (!htx->size || htx_free_space(htx) < htx->size / 4) |
| 685 | return 1; |
| 686 | return 0; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 687 | } |
| 688 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 689 | /* Resets an HTX message */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 690 | static inline void htx_reset(struct htx *htx) |
| 691 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 692 | htx->tail = htx->head = htx->first = -1; |
| 693 | htx->data = 0; |
Christopher Faulet | d7884d3 | 2019-06-11 10:40:43 +0200 | [diff] [blame] | 694 | htx->tail_addr = htx->head_addr = htx->end_addr = 0; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 695 | htx->extra = 0; |
| 696 | htx->flags = HTX_FL_NONE; |
| 697 | } |
| 698 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 699 | /* Returns the available room for raw data in buffer <buf> once HTX overhead is |
Willy Tarreau | 3906e22 | 2018-12-05 07:56:25 +0100 | [diff] [blame] | 700 | * taken into account (one HTX header and two blocks). The purpose is to figure |
| 701 | * the optimal fill length to avoid copies. |
| 702 | */ |
| 703 | static inline size_t buf_room_for_htx_data(const struct buffer *buf) |
| 704 | { |
| 705 | size_t room; |
| 706 | |
| 707 | room = b_room(buf); |
| 708 | if (room <= sizeof(struct htx) + 2 * sizeof(struct htx_blk)) |
| 709 | room = 0; |
| 710 | else |
| 711 | room -= sizeof(struct htx) + 2 * sizeof(struct htx_blk); |
| 712 | |
| 713 | return room; |
| 714 | } |
| 715 | |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 716 | |
| 717 | /* Returns an HTX message using the buffer <buf>. Unlike htx_from_buf(), this |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 718 | * function does not update the buffer. So if the HTX message is updated, the |
| 719 | * caller must call htx_to_buf() to be sure to also update the underlying buffer |
| 720 | * accordingly. Note that it always returns a valid pointer, either to an |
| 721 | * initialized buffer or to the empty buffer. This function must always be |
| 722 | * called with a buffer containing an HTX message (or an empty buffer). |
Willy Tarreau | 245d189 | 2019-01-31 07:21:42 +0100 | [diff] [blame] | 723 | */ |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 724 | static inline struct htx *htxbuf(const struct buffer *buf) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 725 | { |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 726 | struct htx *htx; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 727 | |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 728 | if (b_is_null(buf)) |
| 729 | return &htx_empty; |
| 730 | htx = ((struct htx *)(buf->area)); |
| 731 | if (!b_data(buf)) { |
Willy Tarreau | 8ae4235 | 2018-12-05 09:47:34 +0100 | [diff] [blame] | 732 | htx->size = buf->size - sizeof(*htx); |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 733 | htx_reset(htx); |
Willy Tarreau | 8ae4235 | 2018-12-05 09:47:34 +0100 | [diff] [blame] | 734 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 735 | return htx; |
| 736 | } |
| 737 | |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 738 | /* Returns an HTX message using the buffer <buf>. <buf> is updated to appear as |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 739 | * full. It should be used when you want to add something into the HTX message, |
| 740 | * so the call to htx_to_buf() may be skipped. But, it is the caller |
| 741 | * responsibility to call htx_to_buf() to reset <buf> if it is relevant. The |
| 742 | * returned pointer is always valid. This function must always be called with a |
| 743 | * buffer containing an HTX message (or an empty buffer). |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 744 | * |
Willy Tarreau | 245d189 | 2019-01-31 07:21:42 +0100 | [diff] [blame] | 745 | * The caller can call htxbuf() function to avoid any update of the buffer. |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 746 | */ |
| 747 | static inline struct htx *htx_from_buf(struct buffer *buf) |
| 748 | { |
| 749 | struct htx *htx = htxbuf(buf); |
| 750 | |
| 751 | b_set_data(buf, b_size(buf)); |
| 752 | return htx; |
| 753 | } |
| 754 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 755 | /* Update <buf> accordingly to the HTX message <htx> */ |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 756 | static inline void htx_to_buf(struct htx *htx, struct buffer *buf) |
| 757 | { |
Christopher Faulet | 505adfc | 2019-09-06 19:08:27 +0200 | [diff] [blame] | 758 | if ((htx->head == -1) && |
| 759 | !(htx->flags & (HTX_FL_PARSING_ERROR|HTX_FL_PROCESSING_ERROR|HTX_FL_UPGRADE))) { |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 760 | htx_reset(htx); |
| 761 | b_set_data(buf, 0); |
| 762 | } |
| 763 | else |
| 764 | b_set_data(buf, b_size(buf)); |
| 765 | } |
| 766 | |
Willy Tarreau | e5fcfbe | 2019-01-31 07:31:18 +0100 | [diff] [blame] | 767 | /* Returns 1 if the message is empty, otherwise it returns 0. Note that it is |
| 768 | * illegal to call this with htx == NULL. |
| 769 | */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 770 | static inline int htx_is_empty(const struct htx *htx) |
| 771 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 772 | return (htx->head == -1); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 773 | } |
| 774 | |
Willy Tarreau | e5fcfbe | 2019-01-31 07:31:18 +0100 | [diff] [blame] | 775 | /* Returns 1 if the message is not empty, otherwise it returns 0. Note that it |
| 776 | * is illegal to call this with htx == NULL. |
| 777 | */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 778 | static inline int htx_is_not_empty(const struct htx *htx) |
| 779 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 780 | return (htx->head != -1); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 781 | } |
| 782 | |
Christopher Faulet | 2056736 | 2020-05-15 14:52:49 +0200 | [diff] [blame^] | 783 | /* Copy an HTX message stored in the buffer <msg> to <htx>. We take care to |
| 784 | * not overwrite existing data. All the message is copied or nothing. It returns |
| 785 | * 1 on success and 0 on error. |
| 786 | */ |
| 787 | static inline int htx_copy_msg(struct htx *htx, const struct buffer *msg) |
| 788 | { |
| 789 | /* The destination HTX message is empty, we can do a raw copy */ |
| 790 | if (htx_is_empty(htx)) { |
| 791 | memcpy(htx, msg->area, msg->size); |
| 792 | return 1; |
| 793 | } |
| 794 | |
| 795 | /* Otherwise, we need to append the HTX message */ |
| 796 | return htx_append_msg(htx, htxbuf(msg)); |
| 797 | } |
| 798 | |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 799 | /* Returns the number of used blocks in the HTX message <htx>. Note that it is |
| 800 | * illegal to call this function with htx == NULL. Note also blocks of type |
| 801 | * HTX_BLK_UNUSED are part of used blocks. |
| 802 | */ |
| 803 | static inline int htx_nbblks(const struct htx *htx) |
| 804 | { |
| 805 | return ((htx->head != -1) ? (htx->tail + 1 - htx->head) : 0); |
| 806 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 807 | /* For debugging purpose */ |
| 808 | static inline const char *htx_blk_type_str(enum htx_blk_type type) |
| 809 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 810 | switch (type) { |
| 811 | case HTX_BLK_REQ_SL: return "HTX_BLK_REQ_SL"; |
| 812 | case HTX_BLK_RES_SL: return "HTX_BLK_RES_SL"; |
| 813 | case HTX_BLK_HDR: return "HTX_BLK_HDR"; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 814 | case HTX_BLK_EOH: return "HTX_BLK_EOH"; |
| 815 | case HTX_BLK_DATA: return "HTX_BLK_DATA"; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 816 | case HTX_BLK_TLR: return "HTX_BLK_TLR"; |
Christopher Faulet | 2d7c539 | 2019-06-03 10:41:26 +0200 | [diff] [blame] | 817 | case HTX_BLK_EOT: return "HTX_BLK_EOT"; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 818 | case HTX_BLK_EOM: return "HTX_BLK_EOM"; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 819 | case HTX_BLK_UNUSED: return "HTX_BLK_UNUSED"; |
| 820 | default: return "HTX_BLK_???"; |
| 821 | }; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 822 | } |
| 823 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 824 | /* For debugging purpose */ |
Christopher Faulet | 27aa65e | 2019-10-01 22:03:49 +0200 | [diff] [blame] | 825 | static inline void htx_dump(struct buffer *chunk, const struct htx *htx, int full) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 826 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 827 | int32_t pos; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 828 | |
Christopher Faulet | 27aa65e | 2019-10-01 22:03:49 +0200 | [diff] [blame] | 829 | chunk_appendf(chunk, " htx=%p(size=%u,data=%u,used=%u,wrap=%s,flags=0x%08x,extra=%llu," |
| 830 | "first=%d,head=%d,tail=%d,tail_addr=%d,head_addr=%d,end_addr=%d)", |
| 831 | htx, htx->size, htx->data, htx_nbblks(htx), (!htx->head_addr) ? "NO" : "YES", |
| 832 | htx->flags, (unsigned long long)htx->extra, htx->first, htx->head, htx->tail, |
| 833 | htx->tail_addr, htx->head_addr, htx->end_addr); |
| 834 | |
| 835 | if (!full || !htx_nbblks(htx)) |
| 836 | return; |
| 837 | chunk_memcat(chunk, "\n", 1); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 838 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 839 | for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 840 | struct htx_sl *sl; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 841 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 842 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 843 | uint32_t sz = htx_get_blksz(blk); |
| 844 | struct ist n, v; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 845 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 846 | n = htx_get_blk_name(htx, blk); |
| 847 | v = htx_get_blk_value(htx, blk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 848 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 849 | if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) { |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 850 | sl = htx_get_blk_ptr(htx, blk); |
Christopher Faulet | 27aa65e | 2019-10-01 22:03:49 +0200 | [diff] [blame] | 851 | chunk_appendf(chunk, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s %.*s %.*s\n", |
| 852 | pos, htx_blk_type_str(type), sz, blk->addr, |
| 853 | HTX_SL_P1_LEN(sl), HTX_SL_P1_PTR(sl), |
| 854 | HTX_SL_P2_LEN(sl), HTX_SL_P2_PTR(sl), |
| 855 | HTX_SL_P3_LEN(sl), HTX_SL_P3_PTR(sl)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 856 | } |
Christopher Faulet | 2d7c539 | 2019-06-03 10:41:26 +0200 | [diff] [blame] | 857 | else if (type == HTX_BLK_HDR || type == HTX_BLK_TLR) |
Christopher Faulet | 27aa65e | 2019-10-01 22:03:49 +0200 | [diff] [blame] | 858 | chunk_appendf(chunk, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s: %.*s\n", |
| 859 | pos, htx_blk_type_str(type), sz, blk->addr, |
| 860 | (int)n.len, n.ptr, |
| 861 | (int)v.len, v.ptr); |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 862 | else |
Christopher Faulet | 27aa65e | 2019-10-01 22:03:49 +0200 | [diff] [blame] | 863 | chunk_appendf(chunk, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u%s\n", |
| 864 | pos, htx_blk_type_str(type), sz, blk->addr, |
| 865 | (!v.len ? "\t<empty>" : "")); |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 866 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 867 | } |
| 868 | |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 869 | #endif /* _COMMON_HTX_H */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 870 | |
| 871 | /* |
| 872 | * Local variables: |
| 873 | * c-indent-level: 8 |
| 874 | * c-basic-offset: 8 |
| 875 | * End: |
| 876 | */ |