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 |
| 40 | * language that's simplify explainations. |
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 */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [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) */ |
Christopher Faulet | e21c016 | 2019-06-14 10:08:13 +0200 | [diff] [blame] | 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 */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 143 | |
| 144 | /* HTX flags */ |
| 145 | #define HTX_FL_NONE 0x00000000 |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 146 | #define HTX_FL_PARSING_ERROR 0x00000001 /* Set when a parsing error occurred */ |
| 147 | #define HTX_FL_UPGRADE 0x00000002 /* Set when an upgrade is in progress */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 148 | |
| 149 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 150 | /* HTX block's type (max 15). */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 151 | enum htx_blk_type { |
| 152 | HTX_BLK_REQ_SL = 0, /* Request start-line */ |
| 153 | HTX_BLK_RES_SL = 1, /* Response start-line */ |
| 154 | HTX_BLK_HDR = 2, /* header name/value block */ |
Christopher Faulet | 39744f7 | 2019-05-24 14:54:00 +0200 | [diff] [blame] | 155 | HTX_BLK_EOH = 3, /* end-of-headers block */ |
| 156 | HTX_BLK_DATA = 4, /* data block */ |
Christopher Faulet | 54b5e21 | 2019-06-04 10:08:28 +0200 | [diff] [blame] | 157 | HTX_BLK_TLR = 5, /* trailer name/value block */ |
| 158 | HTX_BLK_EOT = 6, /* end-of-trailers block */ |
| 159 | HTX_BLK_EOM = 7, /* end-of-message block */ |
Christopher Faulet | 39744f7 | 2019-05-24 14:54:00 +0200 | [diff] [blame] | 160 | /* 8 .. 14 unused */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 161 | HTX_BLK_UNUSED = 15, /* unused/removed block */ |
| 162 | }; |
| 163 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 164 | /* One HTX block descriptor */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 165 | struct htx_blk { |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 166 | uint32_t addr; /* relative storage address of the block's payload */ |
| 167 | uint32_t info; /* information about the block (type, length) */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 168 | }; |
| 169 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 170 | /* Composite return value used by some HTX functions */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 171 | struct htx_ret { |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 172 | int32_t ret; /* A numerical value */ |
| 173 | struct htx_blk *blk; /* An HTX block */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 174 | }; |
| 175 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 176 | /* HTX start-line */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 177 | struct htx_sl { |
| 178 | unsigned int flags; /* HTX_SL_F_* */ |
| 179 | union { |
| 180 | struct { |
| 181 | enum http_meth_t meth; /* method */ |
| 182 | } req; |
| 183 | struct { |
| 184 | uint16_t status; /* status code */ |
| 185 | } res; |
| 186 | } info; |
| 187 | |
| 188 | /* XXX 2 bytes unused */ |
| 189 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 190 | int32_t hdrs_bytes; /* Bytes held by all headers, as seen by the mux |
| 191 | * during parsing, from this start-line to the |
| 192 | * corresponding EOH. -1 if unknown */ |
Christopher Faulet | 05c083c | 2019-05-15 14:56:47 +0200 | [diff] [blame] | 193 | |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 194 | unsigned int len[3]; /* length of differnt parts of the start-line */ |
| 195 | char l[0]; |
| 196 | }; |
| 197 | |
| 198 | /* Internal representation of an HTTP message */ |
| 199 | struct htx { |
| 200 | uint32_t size; /* the array size, in bytes, used to store the HTTP message itself */ |
| 201 | uint32_t data; /* the data size, in bytes. To known to total size used by all allocated |
| 202 | * blocks (blocks and their contents), you need to add size used by blocks, |
| 203 | * i.e. [ used * sizeof(struct htx_blk *) ] */ |
| 204 | |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 205 | int32_t tail; /* newest inserted block. -1 if the HTX message is empty */ |
| 206 | int32_t head; /* oldest inserted block. -1 if the HTX message is empty */ |
| 207 | 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] | 208 | |
| 209 | uint32_t tail_addr; /* start address of the free space in front of the the blocks table */ |
| 210 | uint32_t head_addr; /* start address of the free space at the beginning */ |
| 211 | uint32_t end_addr; /* end address of the free space at the beginning */ |
| 212 | |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 213 | uint64_t extra; /* known bytes amount remaining to receive */ |
| 214 | uint32_t flags; /* HTX_FL_* */ |
| 215 | |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 216 | /* XXX 4 bytes unused */ |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 217 | |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 218 | /* Blocks representing the HTTP message itself */ |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 219 | char blocks[0] __attribute__((aligned(8))); |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 220 | }; |
| 221 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 222 | |
| 223 | extern struct htx htx_empty; |
| 224 | |
| 225 | struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk); |
| 226 | struct htx_blk *htx_add_blk(struct htx *htx, enum htx_blk_type type, uint32_t blksz); |
| 227 | struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk); |
Christopher Faulet | 00cf697 | 2019-01-07 14:53:27 +0100 | [diff] [blame] | 228 | void htx_truncate(struct htx *htx, uint32_t offset); |
Christopher Faulet | 549822f | 2019-02-25 10:23:19 +0100 | [diff] [blame] | 229 | struct htx_ret htx_drain(struct htx *htx, uint32_t max); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 230 | |
| 231 | 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] | 232 | const struct ist old, const struct ist new); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 233 | struct htx_ret htx_xfer_blks(struct htx *dst, struct htx *src, uint32_t count, |
| 234 | enum htx_blk_type mark); |
| 235 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 236 | struct htx_sl *htx_add_stline(struct htx *htx, enum htx_blk_type type, unsigned int flags, |
| 237 | const struct ist p1, const struct ist p2, const struct ist p3); |
| 238 | struct htx_sl *htx_replace_stline(struct htx *htx, struct htx_blk *blk, const struct ist p1, |
| 239 | const struct ist p2, const struct ist p3); |
| 240 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 241 | 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] | 242 | const struct ist name, const struct ist value); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 243 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 244 | 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] | 245 | 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] | 246 | 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] | 247 | 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] | 248 | 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] | 249 | 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] | 250 | size_t htx_add_data(struct htx *htx, const struct ist data); |
Christopher Faulet | 86bc8df | 2019-06-11 10:38:38 +0200 | [diff] [blame] | 251 | 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] | 252 | void htx_move_blk_before(struct htx *htx, struct htx_blk **blk, struct htx_blk **ref); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 253 | |
Christopher Faulet | c59ff23 | 2018-12-03 13:58:44 +0100 | [diff] [blame] | 254 | int htx_reqline_to_h1(const struct htx_sl *sl, struct buffer *chk); |
| 255 | int htx_stline_to_h1(const struct htx_sl *sl, struct buffer *chk); |
| 256 | int htx_hdr_to_h1(const struct ist n, const struct ist v, struct buffer *chk); |
| 257 | int htx_data_to_h1(const struct ist data, struct buffer *chk, int chunked); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 258 | |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 259 | /* Functions and macros to get parts of the start-line or legnth of these |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 260 | * parts. Request and response start-lines are both composed of 3 parts. |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 261 | */ |
| 262 | #define HTX_SL_LEN(sl) ((sl)->len[0] + (sl)->len[1] + (sl)->len[2]) |
| 263 | |
| 264 | #define HTX_SL_P1_LEN(sl) ((sl)->len[0]) |
| 265 | #define HTX_SL_P2_LEN(sl) ((sl)->len[1]) |
| 266 | #define HTX_SL_P3_LEN(sl) ((sl)->len[2]) |
| 267 | #define HTX_SL_P1_PTR(sl) ((sl)->l) |
| 268 | #define HTX_SL_P2_PTR(sl) (HTX_SL_P1_PTR(sl) + HTX_SL_P1_LEN(sl)) |
| 269 | #define HTX_SL_P3_PTR(sl) (HTX_SL_P2_PTR(sl) + HTX_SL_P2_LEN(sl)) |
| 270 | |
| 271 | #define HTX_SL_REQ_MLEN(sl) HTX_SL_P1_LEN(sl) |
| 272 | #define HTX_SL_REQ_ULEN(sl) HTX_SL_P2_LEN(sl) |
| 273 | #define HTX_SL_REQ_VLEN(sl) HTX_SL_P3_LEN(sl) |
| 274 | #define HTX_SL_REQ_MPTR(sl) HTX_SL_P1_PTR(sl) |
| 275 | #define HTX_SL_REQ_UPTR(sl) HTX_SL_P2_PTR(sl) |
| 276 | #define HTX_SL_REQ_VPTR(sl) HTX_SL_P3_PTR(sl) |
| 277 | |
| 278 | #define HTX_SL_RES_VLEN(sl) HTX_SL_P1_LEN(sl) |
| 279 | #define HTX_SL_RES_CLEN(sl) HTX_SL_P2_LEN(sl) |
| 280 | #define HTX_SL_RES_RLEN(sl) HTX_SL_P3_LEN(sl) |
| 281 | #define HTX_SL_RES_VPTR(sl) HTX_SL_P1_PTR(sl) |
| 282 | #define HTX_SL_RES_CPTR(sl) HTX_SL_P2_PTR(sl) |
| 283 | #define HTX_SL_RES_RPTR(sl) HTX_SL_P3_PTR(sl) |
| 284 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 285 | static inline struct ist htx_sl_p1(const struct htx_sl *sl) |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 286 | { |
| 287 | return ist2(HTX_SL_P1_PTR(sl), HTX_SL_P1_LEN(sl)); |
| 288 | } |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 289 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 290 | static inline struct ist htx_sl_p2(const struct htx_sl *sl) |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 291 | { |
| 292 | return ist2(HTX_SL_P2_PTR(sl), HTX_SL_P2_LEN(sl)); |
| 293 | } |
| 294 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 295 | static inline struct ist htx_sl_p3(const struct htx_sl *sl) |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 296 | { |
| 297 | return ist2(HTX_SL_P3_PTR(sl), HTX_SL_P3_LEN(sl)); |
| 298 | } |
| 299 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 300 | 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] | 301 | { |
| 302 | return htx_sl_p1(sl); |
| 303 | } |
| 304 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 305 | 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] | 306 | { |
| 307 | return htx_sl_p2(sl); |
| 308 | } |
| 309 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 310 | 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] | 311 | { |
| 312 | return htx_sl_p3(sl); |
| 313 | } |
| 314 | |
| 315 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 316 | 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] | 317 | { |
| 318 | return htx_sl_p1(sl); |
| 319 | } |
| 320 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 321 | 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] | 322 | { |
| 323 | return htx_sl_p2(sl); |
| 324 | } |
| 325 | |
Willy Tarreau | 8de1df9 | 2019-04-15 21:27:18 +0200 | [diff] [blame] | 326 | 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] | 327 | { |
| 328 | return htx_sl_p3(sl); |
| 329 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 330 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 331 | /* Converts a position to the corresponding relative address */ |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 332 | 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] | 333 | { |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 334 | return htx->size - (pos + 1) * sizeof(struct htx_blk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 335 | } |
| 336 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 337 | /* Returns the position of the block <blk>. It is the caller responsibility to |
| 338 | * be sure <blk> is part of <htx>. */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 339 | static inline uint32_t htx_get_blk_pos(const struct htx *htx, const struct htx_blk *blk) |
| 340 | { |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 341 | return ((htx->blocks + htx->size - (char *)blk) / sizeof(struct htx_blk) - 1); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 342 | } |
| 343 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 344 | /* Returns the block at the position <pos>. It is the caller responsibility to |
| 345 | * be sure the block at the position <pos> exists. */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 346 | static inline struct htx_blk *htx_get_blk(const struct htx *htx, uint32_t pos) |
| 347 | { |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 348 | return (struct htx_blk *)(htx->blocks + htx_pos_to_addr(htx, pos)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /* Returns the type of the block <blk> */ |
| 352 | static inline enum htx_blk_type htx_get_blk_type(const struct htx_blk *blk) |
| 353 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 354 | return (blk->info >> 28); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 355 | } |
| 356 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 357 | /* Returns the size of the block <blk>, depending of its type */ |
| 358 | static inline uint32_t htx_get_blksz(const struct htx_blk *blk) |
| 359 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 360 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 361 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 362 | switch (type) { |
| 363 | case HTX_BLK_HDR: |
Christopher Faulet | 2d7c539 | 2019-06-03 10:41:26 +0200 | [diff] [blame] | 364 | case HTX_BLK_TLR: |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 365 | /* name.length + value.length */ |
| 366 | return ((blk->info & 0xff) + ((blk->info >> 8) & 0xfffff)); |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 367 | default: |
| 368 | /* value.length */ |
| 369 | return (blk->info & 0xfffffff); |
| 370 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 371 | } |
| 372 | |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 373 | /* Returns the position of the oldest entry (head). It returns a signed 32-bits |
| 374 | * integer, -1 means the HTX message is empty. |
Christopher Faulet | 28f29c7 | 2019-04-30 17:55:45 +0200 | [diff] [blame] | 375 | */ |
| 376 | static inline int32_t htx_get_head(const struct htx *htx) |
| 377 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 378 | return htx->head; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | /* Returns the oldest HTX block (head) if the HTX message is not |
| 382 | * empty. Otherwise it returns NULL. |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 383 | */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 384 | static inline struct htx_blk *htx_get_head_blk(const struct htx *htx) |
| 385 | { |
| 386 | int32_t head = htx_get_head(htx); |
| 387 | |
| 388 | return ((head == -1) ? NULL : htx_get_blk(htx, head)); |
| 389 | } |
| 390 | |
| 391 | /* Returns the type of the oldest HTX block (head) if the HTX message is not |
| 392 | * empty. Otherwise it returns HTX_BLK_UNUSED. |
| 393 | */ |
| 394 | static inline enum htx_blk_type htx_get_head_type(const struct htx *htx) |
| 395 | { |
| 396 | struct htx_blk *blk = htx_get_head_blk(htx); |
| 397 | |
| 398 | return (blk ? htx_get_blk_type(blk) : HTX_BLK_UNUSED); |
| 399 | } |
| 400 | |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 401 | /* Returns the position of the newest entry (tail). It returns a signed 32-bits |
| 402 | * integer, -1 means the HTX message is empty. |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 403 | */ |
| 404 | static inline int32_t htx_get_tail(const struct htx *htx) |
| 405 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 406 | return htx->tail; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | /* Returns the newest HTX block (tail) if the HTX message is not |
| 410 | * empty. Otherwise it returns NULL. |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 411 | */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 412 | static inline struct htx_blk *htx_get_tail_blk(const struct htx *htx) |
| 413 | { |
| 414 | int32_t tail = htx_get_tail(htx); |
| 415 | |
| 416 | return ((tail == -1) ? NULL : htx_get_blk(htx, tail)); |
| 417 | } |
| 418 | |
| 419 | /* Returns the type of the newest HTX block (tail) if the HTX message is not |
| 420 | * empty. Otherwise it returns HTX_BLK_UNUSED. |
| 421 | */ |
| 422 | static inline enum htx_blk_type htx_get_tail_type(const struct htx *htx) |
| 423 | { |
| 424 | struct htx_blk *blk = htx_get_tail_blk(htx); |
| 425 | |
| 426 | return (blk ? htx_get_blk_type(blk) : HTX_BLK_UNUSED); |
| 427 | } |
| 428 | |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 429 | /* Returns the position of the first block in the HTX message <htx>. -1 means |
| 430 | * the first block is unset or the HTS is empty. |
Christopher Faulet | a3ad6b1 | 2019-05-13 11:36:27 +0200 | [diff] [blame] | 431 | */ |
| 432 | static inline int32_t htx_get_first(const struct htx *htx) |
| 433 | { |
Christopher Faulet | 29f1758 | 2019-05-23 11:03:26 +0200 | [diff] [blame] | 434 | return htx->first; |
Christopher Faulet | a3ad6b1 | 2019-05-13 11:36:27 +0200 | [diff] [blame] | 435 | } |
| 436 | |
Christopher Faulet | 29f1758 | 2019-05-23 11:03:26 +0200 | [diff] [blame] | 437 | /* Returns the first HTX block in the HTX message <htx>. If unset or if <htx> is |
| 438 | * empty, NULL returned. |
Christopher Faulet | a3ad6b1 | 2019-05-13 11:36:27 +0200 | [diff] [blame] | 439 | */ |
| 440 | static inline struct htx_blk *htx_get_first_blk(const struct htx *htx) |
| 441 | { |
| 442 | int32_t pos; |
| 443 | |
| 444 | pos = htx_get_first(htx); |
| 445 | return ((pos == -1) ? NULL : htx_get_blk(htx, pos)); |
| 446 | } |
| 447 | |
| 448 | /* Returns the type of the first block in the HTX message <htx>. If unset or if |
| 449 | * <htx> is empty, HTX_BLK_UNUSED is returned. |
| 450 | */ |
| 451 | static inline enum htx_blk_type htx_get_first_type(const struct htx *htx) |
| 452 | { |
| 453 | struct htx_blk *blk = htx_get_first_blk(htx); |
| 454 | |
| 455 | return (blk ? htx_get_blk_type(blk) : HTX_BLK_UNUSED); |
| 456 | } |
| 457 | |
Joseph Herlant | c42c0e9 | 2018-11-25 10:43:27 -0800 | [diff] [blame] | 458 | /* 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] | 459 | * 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] | 460 | */ |
| 461 | static inline int32_t htx_get_prev(const struct htx *htx, uint32_t pos) |
| 462 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 463 | if (htx->head == -1 || pos == htx->head) |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 464 | return -1; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 465 | return (pos - 1); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 466 | } |
| 467 | |
Christopher Faulet | d16b0a7 | 2018-11-22 11:23:23 +0100 | [diff] [blame] | 468 | /* Returns the HTX block before <blk> in the HTX message <htx>. If <blk> is the |
| 469 | * head, NULL returned. |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 470 | */ |
Christopher Faulet | d16b0a7 | 2018-11-22 11:23:23 +0100 | [diff] [blame] | 471 | static inline struct htx_blk *htx_get_prev_blk(const struct htx *htx, |
| 472 | const struct htx_blk *blk) |
| 473 | { |
| 474 | int32_t pos; |
| 475 | |
| 476 | pos = htx_get_prev(htx, htx_get_blk_pos(htx, blk)); |
| 477 | return ((pos == -1) ? NULL : htx_get_blk(htx, pos)); |
| 478 | } |
| 479 | |
Joseph Herlant | c42c0e9 | 2018-11-25 10:43:27 -0800 | [diff] [blame] | 480 | /* 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] | 481 | * 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] | 482 | */ |
| 483 | static inline int32_t htx_get_next(const struct htx *htx, uint32_t pos) |
| 484 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 485 | if (htx->tail == -1 || pos == htx->tail) |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 486 | return -1; |
Christopher Faulet | d7884d3 | 2019-06-11 10:40:43 +0200 | [diff] [blame] | 487 | return (pos + 1); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 488 | |
| 489 | } |
Christopher Faulet | d16b0a7 | 2018-11-22 11:23:23 +0100 | [diff] [blame] | 490 | |
| 491 | /* Returns the HTX block after <blk> in the HTX message <htx>. If <blk> is the |
| 492 | * tail, NULL returned. |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 493 | */ |
Christopher Faulet | d16b0a7 | 2018-11-22 11:23:23 +0100 | [diff] [blame] | 494 | static inline struct htx_blk *htx_get_next_blk(const struct htx *htx, |
| 495 | const struct htx_blk *blk) |
| 496 | { |
| 497 | int32_t pos; |
| 498 | |
| 499 | pos = htx_get_next(htx, htx_get_blk_pos(htx, blk)); |
| 500 | return ((pos == -1) ? NULL : htx_get_blk(htx, pos)); |
| 501 | } |
| 502 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 503 | /* 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] | 504 | * value itself, make sure there is enough space and update allocated |
| 505 | * value. This function updates the HTX message accordingly. |
| 506 | */ |
| 507 | static inline void htx_change_blk_value_len(struct htx *htx, struct htx_blk *blk, uint32_t newlen) |
| 508 | { |
| 509 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 510 | uint32_t oldlen, sz; |
| 511 | int32_t delta; |
| 512 | |
| 513 | sz = htx_get_blksz(blk); |
| 514 | switch (type) { |
| 515 | case HTX_BLK_HDR: |
| 516 | case HTX_BLK_TLR: |
| 517 | oldlen = (blk->info >> 8) & 0xfffff; |
| 518 | blk->info = (type << 28) + (newlen << 8) + (blk->info & 0xff); |
| 519 | break; |
| 520 | default: |
| 521 | oldlen = blk->info & 0xfffffff; |
| 522 | blk->info = (type << 28) + newlen; |
| 523 | break; |
| 524 | } |
| 525 | |
| 526 | /* Update HTTP message */ |
| 527 | delta = (newlen - oldlen); |
| 528 | htx->data += delta; |
| 529 | if (blk->addr+sz == htx->tail_addr) |
| 530 | htx->tail_addr += delta; |
| 531 | else if (blk->addr+sz == htx->head_addr) |
| 532 | htx->head_addr += delta; |
| 533 | } |
| 534 | |
| 535 | /* Changes the size of the value. It is the caller responsibility to change the |
| 536 | * value itself, make sure there is enough space and update allocated |
| 537 | * value. Unlike the function htx_change_blk_value_len(), this one does not |
| 538 | * update the HTX message. So it should be used with caution. |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 539 | */ |
| 540 | static inline void htx_set_blk_value_len(struct htx_blk *blk, uint32_t vlen) |
| 541 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 542 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 543 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 544 | switch (type) { |
| 545 | case HTX_BLK_HDR: |
Christopher Faulet | 2d7c539 | 2019-06-03 10:41:26 +0200 | [diff] [blame] | 546 | case HTX_BLK_TLR: |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 547 | blk->info = (type << 28) + (vlen << 8) + (blk->info & 0xff); |
| 548 | break; |
| 549 | case HTX_BLK_REQ_SL: |
| 550 | case HTX_BLK_RES_SL: |
| 551 | case HTX_BLK_DATA: |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 552 | blk->info = (type << 28) + vlen; |
| 553 | break; |
| 554 | default: |
| 555 | /* Unexpected case */ |
| 556 | break; |
| 557 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | /* Returns the data pointer of the block <blk> */ |
| 561 | static inline void *htx_get_blk_ptr(const struct htx *htx, const struct htx_blk *blk) |
| 562 | { |
| 563 | return ((void *)htx->blocks + blk->addr); |
| 564 | } |
| 565 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 566 | /* Returns the name of the block <blk>, only if it is a header or a |
| 567 | * trailer. Otherwise it returns an empty string. |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 568 | */ |
| 569 | static inline struct ist htx_get_blk_name(const struct htx *htx, const struct htx_blk *blk) |
| 570 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 571 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 572 | struct ist ret; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 573 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 574 | switch (type) { |
| 575 | case HTX_BLK_HDR: |
Christopher Faulet | 2d7c539 | 2019-06-03 10:41:26 +0200 | [diff] [blame] | 576 | case HTX_BLK_TLR: |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 577 | ret.ptr = htx_get_blk_ptr(htx, blk); |
| 578 | ret.len = blk->info & 0xff; |
| 579 | break; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 580 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 581 | default: |
| 582 | return ist(""); |
| 583 | } |
| 584 | return ret; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 585 | } |
| 586 | |
Christopher Faulet | 54483df | 2018-11-26 15:05:52 +0100 | [diff] [blame] | 587 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 588 | /* Returns the value of the block <blk>, depending on its type. If there is no |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 589 | * value (for end-of blocks), an empty one is retruned. |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 590 | */ |
| 591 | static inline struct ist htx_get_blk_value(const struct htx *htx, const struct htx_blk *blk) |
| 592 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 593 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 594 | struct ist ret; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 595 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 596 | switch (type) { |
| 597 | case HTX_BLK_HDR: |
Christopher Faulet | 2d7c539 | 2019-06-03 10:41:26 +0200 | [diff] [blame] | 598 | case HTX_BLK_TLR: |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 599 | ret.ptr = htx_get_blk_ptr(htx, blk) + (blk->info & 0xff); |
| 600 | ret.len = (blk->info >> 8) & 0xfffff; |
| 601 | break; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 602 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 603 | case HTX_BLK_REQ_SL: |
| 604 | case HTX_BLK_RES_SL: |
| 605 | case HTX_BLK_DATA: |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 606 | ret.ptr = htx_get_blk_ptr(htx, blk); |
| 607 | ret.len = blk->info & 0xfffffff; |
| 608 | break; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 609 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 610 | default: |
| 611 | return ist(""); |
| 612 | } |
| 613 | return ret; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 614 | } |
| 615 | |
Willy Tarreau | c01ed9f | 2018-11-30 14:29:31 +0100 | [diff] [blame] | 616 | /* Removes <n> bytes from the beginning of DATA block <blk>. The block's start |
| 617 | * address and its length are adjusted, and the htx's total data count is |
| 618 | * updated. This is used to mark that part of some data were transfered |
| 619 | * from a DATA block without removing this DATA block. No sanity check is |
| 620 | * performed, the caller is reponsible for doing this exclusively on DATA |
| 621 | * blocks, and never removing more than the block's size. |
| 622 | */ |
| 623 | static inline void htx_cut_data_blk(struct htx *htx, struct htx_blk *blk, uint32_t n) |
| 624 | { |
Christopher Faulet | d7884d3 | 2019-06-11 10:40:43 +0200 | [diff] [blame] | 625 | if (blk->addr == htx->end_addr) |
| 626 | htx->end_addr += n; |
Willy Tarreau | c01ed9f | 2018-11-30 14:29:31 +0100 | [diff] [blame] | 627 | blk->addr += n; |
| 628 | blk->info -= n; |
| 629 | htx->data -= n; |
| 630 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 631 | |
| 632 | /* Returns the space used by metadata in <htx>. */ |
| 633 | static inline uint32_t htx_meta_space(const struct htx *htx) |
| 634 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 635 | if (htx->tail == -1) |
| 636 | return 0; |
| 637 | |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 638 | return ((htx->tail + 1 - htx->head) * sizeof(struct htx_blk)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 639 | } |
| 640 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 641 | /* Returns the space used (payload + metadata) in <htx> */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 642 | static inline uint32_t htx_used_space(const struct htx *htx) |
| 643 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 644 | return (htx->data + htx_meta_space(htx)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | /* Returns the free space in <htx> */ |
| 648 | static inline uint32_t htx_free_space(const struct htx *htx) |
| 649 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 650 | return (htx->size - htx_used_space(htx)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | /* Returns the maximum size available to store some data in <htx> if a new block |
| 654 | * is reserved. |
| 655 | */ |
| 656 | static inline uint32_t htx_free_data_space(const struct htx *htx) |
| 657 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 658 | uint32_t free = htx_free_space(htx); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 659 | |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 660 | if (free < sizeof(struct htx_blk)) |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 661 | return 0; |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 662 | return (free - sizeof(struct htx_blk)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 663 | } |
| 664 | |
Christopher Faulet | 2ae3504 | 2019-05-16 11:16:39 +0200 | [diff] [blame] | 665 | /* Returns the maximum size for a block, not exceeding <max> bytes. <max> may be |
| 666 | * set to -1 to have no limit. |
| 667 | */ |
| 668 | static inline uint32_t htx_get_max_blksz(const struct htx *htx, int32_t max) |
| 669 | { |
| 670 | uint32_t free = htx_free_space(htx); |
| 671 | |
| 672 | if (max != -1 && free > max) |
| 673 | free = max; |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 674 | if (free < sizeof(struct htx_blk)) |
Christopher Faulet | 2ae3504 | 2019-05-16 11:16:39 +0200 | [diff] [blame] | 675 | return 0; |
Christopher Faulet | 2bf43f0 | 2019-06-12 11:28:11 +0200 | [diff] [blame] | 676 | return (free - sizeof(struct htx_blk)); |
Christopher Faulet | 2ae3504 | 2019-05-16 11:16:39 +0200 | [diff] [blame] | 677 | } |
| 678 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 679 | /* Returns 1 if the message has less than 1/4 of its capacity free, otherwise 0 */ |
| 680 | static inline int htx_almost_full(const struct htx *htx) |
| 681 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 682 | if (!htx->size || htx_free_space(htx) < htx->size / 4) |
| 683 | return 1; |
| 684 | return 0; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 685 | } |
| 686 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 687 | /* Resets an HTX message */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 688 | static inline void htx_reset(struct htx *htx) |
| 689 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 690 | htx->tail = htx->head = htx->first = -1; |
| 691 | htx->data = 0; |
Christopher Faulet | d7884d3 | 2019-06-11 10:40:43 +0200 | [diff] [blame] | 692 | htx->tail_addr = htx->head_addr = htx->end_addr = 0; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 693 | htx->extra = 0; |
| 694 | htx->flags = HTX_FL_NONE; |
| 695 | } |
| 696 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 697 | /* 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] | 698 | * taken into account (one HTX header and two blocks). The purpose is to figure |
| 699 | * the optimal fill length to avoid copies. |
| 700 | */ |
| 701 | static inline size_t buf_room_for_htx_data(const struct buffer *buf) |
| 702 | { |
| 703 | size_t room; |
| 704 | |
| 705 | room = b_room(buf); |
| 706 | if (room <= sizeof(struct htx) + 2 * sizeof(struct htx_blk)) |
| 707 | room = 0; |
| 708 | else |
| 709 | room -= sizeof(struct htx) + 2 * sizeof(struct htx_blk); |
| 710 | |
| 711 | return room; |
| 712 | } |
| 713 | |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 714 | |
| 715 | /* 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] | 716 | * function does not update the buffer. So if the HTX message is updated, the |
| 717 | * caller must call htx_to_buf() to be sure to also update the underlying buffer |
| 718 | * accordingly. Note that it always returns a valid pointer, either to an |
| 719 | * initialized buffer or to the empty buffer. This function must always be |
| 720 | * called with a buffer containing an HTX message (or an empty buffer). |
Willy Tarreau | 245d189 | 2019-01-31 07:21:42 +0100 | [diff] [blame] | 721 | */ |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 722 | static inline struct htx *htxbuf(const struct buffer *buf) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 723 | { |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 724 | struct htx *htx; |
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 | if (b_is_null(buf)) |
| 727 | return &htx_empty; |
| 728 | htx = ((struct htx *)(buf->area)); |
| 729 | if (!b_data(buf)) { |
Willy Tarreau | 8ae4235 | 2018-12-05 09:47:34 +0100 | [diff] [blame] | 730 | htx->size = buf->size - sizeof(*htx); |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 731 | htx_reset(htx); |
Willy Tarreau | 8ae4235 | 2018-12-05 09:47:34 +0100 | [diff] [blame] | 732 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 733 | return htx; |
| 734 | } |
| 735 | |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 736 | /* 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] | 737 | * full. It should be used when you want to add something into the HTX message, |
| 738 | * so the call to htx_to_buf() may be skipped. But, it is the caller |
| 739 | * responsibility to call htx_to_buf() to reset <buf> if it is relevant. The |
| 740 | * returned pointer is always valid. This function must always be called with a |
| 741 | * buffer containing an HTX message (or an empty buffer). |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 742 | * |
Willy Tarreau | 245d189 | 2019-01-31 07:21:42 +0100 | [diff] [blame] | 743 | * 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] | 744 | */ |
| 745 | static inline struct htx *htx_from_buf(struct buffer *buf) |
| 746 | { |
| 747 | struct htx *htx = htxbuf(buf); |
| 748 | |
| 749 | b_set_data(buf, b_size(buf)); |
| 750 | return htx; |
| 751 | } |
| 752 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 753 | /* Update <buf> accordingly to the HTX message <htx> */ |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 754 | static inline void htx_to_buf(struct htx *htx, struct buffer *buf) |
| 755 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 756 | if ((htx->head == -1) && !(htx->flags & (HTX_FL_PARSING_ERROR|HTX_FL_UPGRADE))) { |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 757 | htx_reset(htx); |
| 758 | b_set_data(buf, 0); |
| 759 | } |
| 760 | else |
| 761 | b_set_data(buf, b_size(buf)); |
| 762 | } |
| 763 | |
Willy Tarreau | e5fcfbe | 2019-01-31 07:31:18 +0100 | [diff] [blame] | 764 | /* Returns 1 if the message is empty, otherwise it returns 0. Note that it is |
| 765 | * illegal to call this with htx == NULL. |
| 766 | */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 767 | static inline int htx_is_empty(const struct htx *htx) |
| 768 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 769 | return (htx->head == -1); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 770 | } |
| 771 | |
Willy Tarreau | e5fcfbe | 2019-01-31 07:31:18 +0100 | [diff] [blame] | 772 | /* Returns 1 if the message is not empty, otherwise it returns 0. Note that it |
| 773 | * is illegal to call this with htx == NULL. |
| 774 | */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 775 | static inline int htx_is_not_empty(const struct htx *htx) |
| 776 | { |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 777 | return (htx->head != -1); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 778 | } |
| 779 | |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 780 | /* Returns the number of used blocks in the HTX message <htx>. Note that it is |
| 781 | * illegal to call this function with htx == NULL. Note also blocks of type |
| 782 | * HTX_BLK_UNUSED are part of used blocks. |
| 783 | */ |
| 784 | static inline int htx_nbblks(const struct htx *htx) |
| 785 | { |
| 786 | return ((htx->head != -1) ? (htx->tail + 1 - htx->head) : 0); |
| 787 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 788 | /* For debugging purpose */ |
| 789 | static inline const char *htx_blk_type_str(enum htx_blk_type type) |
| 790 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 791 | switch (type) { |
| 792 | case HTX_BLK_REQ_SL: return "HTX_BLK_REQ_SL"; |
| 793 | case HTX_BLK_RES_SL: return "HTX_BLK_RES_SL"; |
| 794 | case HTX_BLK_HDR: return "HTX_BLK_HDR"; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 795 | case HTX_BLK_EOH: return "HTX_BLK_EOH"; |
| 796 | case HTX_BLK_DATA: return "HTX_BLK_DATA"; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 797 | case HTX_BLK_TLR: return "HTX_BLK_TLR"; |
Christopher Faulet | 2d7c539 | 2019-06-03 10:41:26 +0200 | [diff] [blame] | 798 | case HTX_BLK_EOT: return "HTX_BLK_EOT"; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 799 | case HTX_BLK_EOM: return "HTX_BLK_EOM"; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 800 | case HTX_BLK_UNUSED: return "HTX_BLK_UNUSED"; |
| 801 | default: return "HTX_BLK_???"; |
| 802 | }; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 803 | } |
| 804 | |
Christopher Faulet | 3b21972 | 2019-06-19 13:48:09 +0200 | [diff] [blame] | 805 | /* For debugging purpose */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 806 | static inline void htx_dump(struct htx *htx) |
| 807 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 808 | int32_t pos; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 809 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 810 | fprintf(stderr, "htx:%p [ size=%u - data=%u - used=%u - wrap=%s - extra=%llu]\n", |
Christopher Faulet | 192c6a2 | 2019-06-11 16:32:24 +0200 | [diff] [blame] | 811 | htx, htx->size, htx->data, htx_nbblks(htx), |
| 812 | (!htx->head_addr) ? "NO" : "YES", |
Willy Tarreau | a7280a1 | 2018-11-26 19:41:40 +0100 | [diff] [blame] | 813 | (unsigned long long)htx->extra); |
Christopher Faulet | 24e116b | 2019-06-12 11:10:28 +0200 | [diff] [blame] | 814 | fprintf(stderr, "\tfirst=%d - head=%d - tail=%d - tail_addr=%d - head_addr=%d, end_addr=%d\n", |
| 815 | htx->first, htx->head, htx->tail, htx->tail_addr, htx->head_addr, htx->end_addr); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 816 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 817 | 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] | 818 | struct htx_sl *sl; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 819 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 820 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 821 | uint32_t sz = htx_get_blksz(blk); |
| 822 | struct ist n, v; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 823 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 824 | n = htx_get_blk_name(htx, blk); |
| 825 | v = htx_get_blk_value(htx, blk); |
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 | if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) { |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 828 | sl = htx_get_blk_ptr(htx, blk); |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 829 | fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s %.*s %.*s\n", |
| 830 | pos, htx_blk_type_str(type), sz, blk->addr, |
| 831 | HTX_SL_P1_LEN(sl), HTX_SL_P1_PTR(sl), |
| 832 | HTX_SL_P2_LEN(sl), HTX_SL_P2_PTR(sl), |
| 833 | HTX_SL_P3_LEN(sl), HTX_SL_P3_PTR(sl)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 834 | } |
Christopher Faulet | 2d7c539 | 2019-06-03 10:41:26 +0200 | [diff] [blame] | 835 | else if (type == HTX_BLK_HDR || type == HTX_BLK_TLR) |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 836 | fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s: %.*s\n", |
| 837 | pos, htx_blk_type_str(type), sz, blk->addr, |
| 838 | (int)n.len, n.ptr, |
| 839 | (int)v.len, v.ptr); |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 840 | else |
| 841 | fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u%s\n", |
| 842 | pos, htx_blk_type_str(type), sz, blk->addr, |
| 843 | (!v.len ? "\t<empty>" : "")); |
| 844 | } |
| 845 | fprintf(stderr, "\n"); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 846 | } |
| 847 | |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 848 | #endif /* _COMMON_HTX_H */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 849 | |
| 850 | /* |
| 851 | * Local variables: |
| 852 | * c-indent-level: 8 |
| 853 | * c-basic-offset: 8 |
| 854 | * End: |
| 855 | */ |