blob: 3a9215fac3f484574bba35f8ff9e91313f0b9d66 [file] [log] [blame]
Christopher Fauleta3d2a162018-10-22 08:59:39 +02001/*
Willy Tarreaub96b77e2018-12-11 10:22:41 +01002 * include/common/htx.h
Christopher Fauleta3d2a162018-10-22 08:59:39 +02003 * 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 Tarreaub96b77e2018-12-11 10:22:41 +010022#ifndef _COMMON_HTX_H
23#define _COMMON_HTX_H
Christopher Fauleta3d2a162018-10-22 08:59:39 +020024
Willy Tarreaub96b77e2018-12-11 10:22:41 +010025#include <stdio.h>
Christopher Fauleta3d2a162018-10-22 08:59:39 +020026#include <common/buf.h>
27#include <common/config.h>
Willy Tarreaub96b77e2018-12-11 10:22:41 +010028#include <common/ist.h>
29#include <common/http.h>
Christopher Fauleta3d2a162018-10-22 08:59:39 +020030#include <common/http-hdr.h>
Willy Tarreaub96b77e2018-12-11 10:22:41 +010031#include <common/standard.h>
32
33/*
34 * The internal representation of an HTTP message is a contiguous array
35 * containing both the blocks (htx_blk) and their contents. Blocks are stored
36 * starting from the end of the array while their contents are stored at the
37 * beginning.
38 *
39 * As data are sent to the peer, blocks and contents are released at the
40 * edges. This free space is reused when no more space left. So blocks and
41 * contents may wrap, not necessarily the same time.
42 *
43 * An HTTP block is as well a header as a body part or a trailer part. For all
44 * these types of block, a content is attached to the block. It can also be a
45 * mark, like the end-of-headers or end-of-message. For these blocks, there is
46 * no content but it count for a byte. It is important to not skip it when data
47 * are forwarded. An HTTP block is composed of 2 fields:
48 *
49 * - .info : It a 32 bits field containing the block's type on 4 bits
50 * followed by content' length. See below for details.
51 *
52 * - .addr : The content's address, if any, relatively to the beginning the
53 * array used to store the HTTP message itself.
54 *
55 * htx_blk.info representation:
56 *
57 * 0b 0000 0000 0000 0000 0000 0000 0000 0000
58 * ---- ------------------------ ---------
59 * type value (1 MB max) name length (header)
60 * ----------------------------------
61 * data length (256 MB max)
62 * (body, method, path, version, status, reason, trailers)
63 *
64 * types:
65 * - 0000 = request start-line
66 * - 0001 = response start-line
67 * - 0010 = header
68 * - 0011 = pseudo-header ou "special" header
69 * - 0100 = end-of-headers
70 * - 0101 = data
71 * - 0110 = end-of-data
72 * - 0111 = trailer
73 * - 1000 = end-of-message
74 * ...
75 * - 1101 = out-of-band
76 * - 1110 = error
77 * - 1111 = unused
78 *
79 */
80
81/*HTX start-line flags */
82#define HTX_SL_F_NONE 0x00000000
83#define HTX_SL_F_IS_RESP 0x00000001 /* It is the response start-line (unset means the request one) */
84#define HTX_SL_F_XFER_LEN 0x00000002 /* The message xfer size can be dertermined */
85#define HTX_SL_F_XFER_ENC 0x00000004 /* The transfer-encoding header was found in message */
86#define HTX_SL_F_CLEN 0x00000008 /* The content-length header was found in message */
87#define HTX_SL_F_CHNK 0x00000010 /* The message payload is chunked */
88#define HTX_SL_F_VER_11 0x00000020 /* The message indicates version 1.1 or above */
89#define HTX_SL_F_BODYLESS 0x00000040 /* The message has no body (content-length = 0) */
90
91/* HTX flags */
92#define HTX_FL_NONE 0x00000000
93#define HTX_FL_PARSING_ERROR 0x00000001
Christopher Faulet0ef372a2019-04-08 10:57:20 +020094#define HTX_FL_UPGRADE 0x00000002
Willy Tarreaub96b77e2018-12-11 10:22:41 +010095
96
97/* Pseudo header types (max 255). */
98enum htx_phdr_type {
99 HTX_PHDR_UNKNOWN = 0,
100 HTX_PHDR_SIZE,
101};
102
103/* HTTP block's type (max 15). */
104enum htx_blk_type {
105 HTX_BLK_REQ_SL = 0, /* Request start-line */
106 HTX_BLK_RES_SL = 1, /* Response start-line */
107 HTX_BLK_HDR = 2, /* header name/value block */
108 HTX_BLK_PHDR = 3, /* pseudo header block */
109 HTX_BLK_EOH = 4, /* end-of-headers block */
110 HTX_BLK_DATA = 5, /* data block */
111 HTX_BLK_EOD = 6, /* end-of-data block */
112 HTX_BLK_TLR = 7, /* trailer name/value block */
113 HTX_BLK_EOM = 8, /* end-of-message block */
Christopher Faulet6f3cb182019-05-07 21:48:12 +0200114 /* 9 .. 14 unused */
Willy Tarreaub96b77e2018-12-11 10:22:41 +0100115 HTX_BLK_UNUSED = 15, /* unused/removed block */
116};
117
118/* One HTTP block descriptor */
119struct htx_blk {
120 uint32_t addr; /* relative storage address of a data block */
121 uint32_t info; /* information about data stored */
122};
123
124struct htx_ret {
125 int32_t ret;
126 struct htx_blk *blk;
127};
128
129struct htx_sl {
130 unsigned int flags; /* HTX_SL_F_* */
131 union {
132 struct {
133 enum http_meth_t meth; /* method */
134 } req;
135 struct {
136 uint16_t status; /* status code */
137 } res;
138 } info;
139
140 /* XXX 2 bytes unused */
141
142 unsigned int len[3]; /* length of differnt parts of the start-line */
143 char l[0];
144};
145
146/* Internal representation of an HTTP message */
147struct htx {
148 uint32_t size; /* the array size, in bytes, used to store the HTTP message itself */
149 uint32_t data; /* the data size, in bytes. To known to total size used by all allocated
150 * blocks (blocks and their contents), you need to add size used by blocks,
151 * i.e. [ used * sizeof(struct htx_blk *) ] */
152
153 uint32_t used; /* number of blocks in use */
154 uint32_t tail; /* last inserted block */
Christopher Faulet28f29c72019-04-30 17:55:45 +0200155 uint32_t head; /* older inserted block */
Willy Tarreaub96b77e2018-12-11 10:22:41 +0100156 uint32_t front; /* block's position of the first content before the blocks table */
Willy Tarreaub96b77e2018-12-11 10:22:41 +0100157
158 uint64_t extra; /* known bytes amount remaining to receive */
159 uint32_t flags; /* HTX_FL_* */
160
Christopher Faulet9c66b982019-04-30 18:08:26 +0200161 int32_t sl_pos; /* position of the start-line of the HTTP message. -1 if unset */
Willy Tarreaub96b77e2018-12-11 10:22:41 +0100162
163 struct htx_blk blocks[0]; /* Blocks representing the HTTP message itself */
164};
165
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200166
167extern struct htx htx_empty;
168
169struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk);
170struct htx_blk *htx_add_blk(struct htx *htx, enum htx_blk_type type, uint32_t blksz);
171struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk);
Christopher Faulet00cf6972019-01-07 14:53:27 +0100172void htx_truncate(struct htx *htx, uint32_t offset);
Christopher Faulet549822f2019-02-25 10:23:19 +0100173struct htx_ret htx_drain(struct htx *htx, uint32_t max);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200174
175struct htx_blk *htx_replace_blk_value(struct htx *htx, struct htx_blk *blk,
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100176 const struct ist old, const struct ist new);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200177struct htx_ret htx_xfer_blks(struct htx *dst, struct htx *src, uint32_t count,
178 enum htx_blk_type mark);
179
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100180struct htx_sl *htx_add_stline(struct htx *htx, enum htx_blk_type type, unsigned int flags,
181 const struct ist p1, const struct ist p2, const struct ist p3);
182struct htx_sl *htx_replace_stline(struct htx *htx, struct htx_blk *blk, const struct ist p1,
183 const struct ist p2, const struct ist p3);
184
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200185struct htx_blk *htx_replace_header(struct htx *htx, struct htx_blk *blk,
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100186 const struct ist name, const struct ist value);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200187
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200188struct htx_blk *htx_add_header(struct htx *htx, const struct ist name, const struct ist value);
Willy Tarreau52610e92019-01-03 18:26:17 +0100189struct htx_blk *htx_add_blk_type_size(struct htx *htx, enum htx_blk_type type, uint32_t blksz);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200190struct htx_blk *htx_add_all_headers(struct htx *htx, const struct http_hdr *hdrs);
191struct htx_blk *htx_add_pseudo_header(struct htx *htx, enum htx_phdr_type phdr, const struct ist value);
192struct htx_blk *htx_add_endof(struct htx *htx, enum htx_blk_type type);
193struct htx_blk *htx_add_data(struct htx *htx, const struct ist data);
194struct htx_blk *htx_add_trailer(struct htx *htx, const struct ist tlr);
Christopher Faulet24ed8352018-11-22 11:20:43 +0100195struct htx_blk *htx_add_data_before(struct htx *htx, const struct htx_blk *ref, const struct ist data);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200196
Christopher Fauletc59ff232018-12-03 13:58:44 +0100197int htx_reqline_to_h1(const struct htx_sl *sl, struct buffer *chk);
198int htx_stline_to_h1(const struct htx_sl *sl, struct buffer *chk);
199int htx_hdr_to_h1(const struct ist n, const struct ist v, struct buffer *chk);
200int htx_data_to_h1(const struct ist data, struct buffer *chk, int chunked);
201int htx_trailer_to_h1(const struct ist tlr, struct buffer *chk);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200202
Christopher Faulet570d1612018-11-26 11:13:57 +0100203/* Functions and macros to get parts of the start-line or legnth of these
204 * parts
205 */
206#define HTX_SL_LEN(sl) ((sl)->len[0] + (sl)->len[1] + (sl)->len[2])
207
208#define HTX_SL_P1_LEN(sl) ((sl)->len[0])
209#define HTX_SL_P2_LEN(sl) ((sl)->len[1])
210#define HTX_SL_P3_LEN(sl) ((sl)->len[2])
211#define HTX_SL_P1_PTR(sl) ((sl)->l)
212#define HTX_SL_P2_PTR(sl) (HTX_SL_P1_PTR(sl) + HTX_SL_P1_LEN(sl))
213#define HTX_SL_P3_PTR(sl) (HTX_SL_P2_PTR(sl) + HTX_SL_P2_LEN(sl))
214
215#define HTX_SL_REQ_MLEN(sl) HTX_SL_P1_LEN(sl)
216#define HTX_SL_REQ_ULEN(sl) HTX_SL_P2_LEN(sl)
217#define HTX_SL_REQ_VLEN(sl) HTX_SL_P3_LEN(sl)
218#define HTX_SL_REQ_MPTR(sl) HTX_SL_P1_PTR(sl)
219#define HTX_SL_REQ_UPTR(sl) HTX_SL_P2_PTR(sl)
220#define HTX_SL_REQ_VPTR(sl) HTX_SL_P3_PTR(sl)
221
222#define HTX_SL_RES_VLEN(sl) HTX_SL_P1_LEN(sl)
223#define HTX_SL_RES_CLEN(sl) HTX_SL_P2_LEN(sl)
224#define HTX_SL_RES_RLEN(sl) HTX_SL_P3_LEN(sl)
225#define HTX_SL_RES_VPTR(sl) HTX_SL_P1_PTR(sl)
226#define HTX_SL_RES_CPTR(sl) HTX_SL_P2_PTR(sl)
227#define HTX_SL_RES_RPTR(sl) HTX_SL_P3_PTR(sl)
228
Willy Tarreau8de1df92019-04-15 21:27:18 +0200229static inline struct ist htx_sl_p1(const struct htx_sl *sl)
Willy Tarreaub96b77e2018-12-11 10:22:41 +0100230{
231 return ist2(HTX_SL_P1_PTR(sl), HTX_SL_P1_LEN(sl));
232}
Christopher Faulet570d1612018-11-26 11:13:57 +0100233
Willy Tarreau8de1df92019-04-15 21:27:18 +0200234static inline struct ist htx_sl_p2(const struct htx_sl *sl)
Christopher Faulet570d1612018-11-26 11:13:57 +0100235{
236 return ist2(HTX_SL_P2_PTR(sl), HTX_SL_P2_LEN(sl));
237}
238
Willy Tarreau8de1df92019-04-15 21:27:18 +0200239static inline struct ist htx_sl_p3(const struct htx_sl *sl)
Christopher Faulet570d1612018-11-26 11:13:57 +0100240{
241 return ist2(HTX_SL_P3_PTR(sl), HTX_SL_P3_LEN(sl));
242}
243
Willy Tarreau8de1df92019-04-15 21:27:18 +0200244static inline struct ist htx_sl_req_meth(const struct htx_sl *sl)
Christopher Faulet570d1612018-11-26 11:13:57 +0100245{
246 return htx_sl_p1(sl);
247}
248
Willy Tarreau8de1df92019-04-15 21:27:18 +0200249static inline struct ist htx_sl_req_uri(const struct htx_sl *sl)
Christopher Faulet570d1612018-11-26 11:13:57 +0100250{
251 return htx_sl_p2(sl);
252}
253
Willy Tarreau8de1df92019-04-15 21:27:18 +0200254static inline struct ist htx_sl_req_vsn(const struct htx_sl *sl)
Christopher Faulet570d1612018-11-26 11:13:57 +0100255{
256 return htx_sl_p3(sl);
257}
258
259
Willy Tarreau8de1df92019-04-15 21:27:18 +0200260static inline struct ist htx_sl_res_vsn(const struct htx_sl *sl)
Christopher Faulet570d1612018-11-26 11:13:57 +0100261{
262 return htx_sl_p1(sl);
263}
264
Willy Tarreau8de1df92019-04-15 21:27:18 +0200265static inline struct ist htx_sl_res_code(const struct htx_sl *sl)
Christopher Faulet570d1612018-11-26 11:13:57 +0100266{
267 return htx_sl_p2(sl);
268}
269
Willy Tarreau8de1df92019-04-15 21:27:18 +0200270static inline struct ist htx_sl_res_reason(const struct htx_sl *sl)
Christopher Faulet570d1612018-11-26 11:13:57 +0100271{
272 return htx_sl_p3(sl);
273}
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200274
275/* Returns the array index of a block given its position <pos> */
276static inline uint32_t htx_pos_to_idx(const struct htx *htx, uint32_t pos)
277{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100278 return ((htx->size / sizeof(htx->blocks[0])) - pos - 1);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200279}
280
281/* Returns the position of the block <blk> */
282static inline uint32_t htx_get_blk_pos(const struct htx *htx, const struct htx_blk *blk)
283{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100284 return (htx->blocks + (htx->size / sizeof(htx->blocks[0])) - blk - 1);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200285}
286
287/* Returns the block at the position <pos> */
288static inline struct htx_blk *htx_get_blk(const struct htx *htx, uint32_t pos)
289{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100290 return ((struct htx_blk *)(htx->blocks) + htx_pos_to_idx(htx, pos));
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200291}
292
293/* Returns the type of the block <blk> */
294static inline enum htx_blk_type htx_get_blk_type(const struct htx_blk *blk)
295{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100296 return (blk->info >> 28);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200297}
298
299/* Returns the pseudo-header type of the block <blk>. If it's not a
300 * pseudo-header, HTX_PHDR_UNKNOWN is returned.
301 */
302static inline enum htx_phdr_type htx_get_blk_phdr(const struct htx_blk *blk)
303{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100304 enum htx_blk_type type = htx_get_blk_type(blk);
305 enum htx_phdr_type phdr;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200306
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100307 switch (type) {
308 case HTX_BLK_PHDR:
309 phdr = (blk->info & 0xff);
310 return phdr;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200311
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100312 default:
313 /* Not a pseudo-header */
314 return HTX_PHDR_UNKNOWN;
315 }
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200316}
317
318/* Returns the size of the block <blk>, depending of its type */
319static inline uint32_t htx_get_blksz(const struct htx_blk *blk)
320{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100321 enum htx_blk_type type = htx_get_blk_type(blk);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200322
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100323 switch (type) {
324 case HTX_BLK_HDR:
325 /* name.length + value.length */
326 return ((blk->info & 0xff) + ((blk->info >> 8) & 0xfffff));
327 case HTX_BLK_PHDR:
328 /* value.length */
329 return ((blk->info >> 8) & 0xfffff);
330 default:
331 /* value.length */
332 return (blk->info & 0xfffffff);
333 }
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200334}
335
Christopher Faulet28f29c72019-04-30 17:55:45 +0200336/* Returns the wrap position, ie the position where the blocks table wraps.
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200337 *
338 * An signed 32-bits integer is returned to handle -1 case. Blocks position are
339 * store on unsigned 32-bits integer, but it is impossible to have so much
340 * blocks to overflow a 32-bits signed integer !
341 */
Christopher Faulet28f29c72019-04-30 17:55:45 +0200342static inline int32_t htx_get_wrap(const struct htx *htx)
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200343{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100344 if (!htx->used)
345 return -1;
Christopher Faulet28f29c72019-04-30 17:55:45 +0200346 return ((htx->tail >= htx->head)
347 ? (htx->used + htx->head)
348 : (htx->used - 1) + (htx->head - htx->tail));
349}
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200350
Christopher Faulet28f29c72019-04-30 17:55:45 +0200351/* Returns the position of the oldest entry (head).
352 *
353 * An signed 32-bits integer is returned to handle -1 case. Blocks position are
354 * store on unsigned 32-bits integer, but it is impossible to have so much
355 * blocks to overflow a 32-bits signed integer !
356 */
357static inline int32_t htx_get_head(const struct htx *htx)
358{
359 return (htx->used ? htx->head : -1);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200360}
361
362/* Returns the oldest HTX block (head) if the HTX message is not
363 * empty. Otherwise it returns NULL.
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100364 */
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200365static inline struct htx_blk *htx_get_head_blk(const struct htx *htx)
366{
367 int32_t head = htx_get_head(htx);
368
369 return ((head == -1) ? NULL : htx_get_blk(htx, head));
370}
371
372/* Returns the type of the oldest HTX block (head) if the HTX message is not
373 * empty. Otherwise it returns HTX_BLK_UNUSED.
374 */
375static inline enum htx_blk_type htx_get_head_type(const struct htx *htx)
376{
377 struct htx_blk *blk = htx_get_head_blk(htx);
378
379 return (blk ? htx_get_blk_type(blk) : HTX_BLK_UNUSED);
380}
381
382/* Returns the position of the newest entry (tail).
383 *
384 * An signed 32-bits integer is returned to handle -1 case. Blocks position are
385 * store on unsigned 32-bits integer, but it is impossible to have so much
386 * blocks to overflow a 32-bits signed integer !
387 */
388static inline int32_t htx_get_tail(const struct htx *htx)
389{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100390 return (htx->used ? htx->tail : -1);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200391}
392
393/* Returns the newest HTX block (tail) if the HTX message is not
394 * empty. Otherwise it returns NULL.
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100395 */
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200396static inline struct htx_blk *htx_get_tail_blk(const struct htx *htx)
397{
398 int32_t tail = htx_get_tail(htx);
399
400 return ((tail == -1) ? NULL : htx_get_blk(htx, tail));
401}
402
403/* Returns the type of the newest HTX block (tail) if the HTX message is not
404 * empty. Otherwise it returns HTX_BLK_UNUSED.
405 */
406static inline enum htx_blk_type htx_get_tail_type(const struct htx *htx)
407{
408 struct htx_blk *blk = htx_get_tail_blk(htx);
409
410 return (blk ? htx_get_blk_type(blk) : HTX_BLK_UNUSED);
411}
412
Christopher Fauleta3ad6b12019-05-13 11:36:27 +0200413/* Returns the position of the first block in the HTX message <htx>. It is the
414 * sl_pos if set, otherwise it is the head.
415 *
416 * An signed 32-bits integer is returned to handle -1 case. Blocks position are
417 * store on unsigned 32-bits integer, but it is impossible to have so much
418 * blocks to overflow a 32-bits signed integer !
419 */
420static inline int32_t htx_get_first(const struct htx *htx)
421{
422 if (htx->sl_pos != -1)
423 return htx->sl_pos;
424 return htx->head;
425}
426
427/* Returns the first HTX block in the HTX message <htx>. If <blk> is the head,
428 * NULL returned.
429 */
430static inline struct htx_blk *htx_get_first_blk(const struct htx *htx)
431{
432 int32_t pos;
433
434 pos = htx_get_first(htx);
435 return ((pos == -1) ? NULL : htx_get_blk(htx, pos));
436}
437
438/* Returns the type of the first block in the HTX message <htx>. If unset or if
439 * <htx> is empty, HTX_BLK_UNUSED is returned.
440 */
441static inline enum htx_blk_type htx_get_first_type(const struct htx *htx)
442{
443 struct htx_blk *blk = htx_get_first_blk(htx);
444
445 return (blk ? htx_get_blk_type(blk) : HTX_BLK_UNUSED);
446}
447
Joseph Herlantc42c0e92018-11-25 10:43:27 -0800448/* Returns the position of block immediately before the one pointed by <pos>. If
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200449 * the message is empty or if <pos> is the position of the head, -1 returned.
450 *
451 * An signed 32-bits integer is returned to handle -1 case. Blocks position are
452 * store on unsigned 32-bits integer, but it is impossible to have so much
453 * blocks to overflow a 32-bits signed integer !
454 */
455static inline int32_t htx_get_prev(const struct htx *htx, uint32_t pos)
456{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100457 int32_t head;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200458
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100459 head = htx_get_head(htx);
460 if (head == -1 || pos == head)
461 return -1;
Christopher Faulet28f29c72019-04-30 17:55:45 +0200462 if (!pos) {
463 /* htx_get_wrap() is always greater than 1 here */
464 return (htx_get_wrap(htx) - 1);
465 }
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100466 return (pos - 1);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200467}
468
Christopher Fauletd16b0a72018-11-22 11:23:23 +0100469/* Returns the HTX block before <blk> in the HTX message <htx>. If <blk> is the
470 * head, NULL returned.
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100471 */
Christopher Fauletd16b0a72018-11-22 11:23:23 +0100472static inline struct htx_blk *htx_get_prev_blk(const struct htx *htx,
473 const struct htx_blk *blk)
474{
475 int32_t pos;
476
477 pos = htx_get_prev(htx, htx_get_blk_pos(htx, blk));
478 return ((pos == -1) ? NULL : htx_get_blk(htx, pos));
479}
480
Joseph Herlantc42c0e92018-11-25 10:43:27 -0800481/* Returns the position of block immediately after the one pointed by <pos>. If
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200482 * the message is empty or if <pos> is the position of the tail, -1 returned.
483 *
484 * An signed 32-bits integer is returned to handle -1 case. Blocks position are
485 * store on unsigned 32-bits integer, but it is impossible to have so much
486 * blocks to overflow a 32-bits signed integer !
487 */
488static inline int32_t htx_get_next(const struct htx *htx, uint32_t pos)
489{
Christopher Faulet28f29c72019-04-30 17:55:45 +0200490 if (!htx->used || pos == htx->tail)
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100491 return -1;
492 pos++;
Christopher Faulet28f29c72019-04-30 17:55:45 +0200493 if (pos == htx_get_wrap(htx))
494 return 0;
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100495 return pos;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200496
497}
Christopher Fauletd16b0a72018-11-22 11:23:23 +0100498
499/* Returns the HTX block after <blk> in the HTX message <htx>. If <blk> is the
500 * tail, NULL returned.
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100501 */
Christopher Fauletd16b0a72018-11-22 11:23:23 +0100502static inline struct htx_blk *htx_get_next_blk(const struct htx *htx,
503 const struct htx_blk *blk)
504{
505 int32_t pos;
506
507 pos = htx_get_next(htx, htx_get_blk_pos(htx, blk));
508 return ((pos == -1) ? NULL : htx_get_blk(htx, pos));
509}
510
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200511static inline int32_t htx_find_front(const struct htx *htx)
512{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100513 int32_t front, pos;
514 uint32_t addr = 0;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200515
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100516 if (!htx->used)
517 return -1;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200518
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100519 front = -1;
520 for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) {
521 struct htx_blk *blk = htx_get_blk(htx, pos);
522 enum htx_blk_type type = htx_get_blk_type(blk);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200523
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100524 if (type != HTX_BLK_UNUSED && blk->addr >= addr) {
525 front = pos;
526 addr = blk->addr;
527 }
528 }
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200529
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100530 return front;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200531}
532
Christopher Faulet14e88252018-11-22 11:28:18 +0100533/* Returns the HTX block containing data with the <offset>, relatively to the
534 * beginning of the HTX message <htx>. It returns an htx_ret. if the HTX block is
535 * not found, htx_ret.blk is set to NULL. Otherwise, it points to the right HTX
536 * block and htx_ret.ret is set to the remaining offset inside the block.
537 */
538static inline struct htx_ret htx_find_blk(const struct htx *htx, uint32_t offset)
539{
540 int32_t pos;
541
542 for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) {
543 struct htx_blk *blk = htx_get_blk(htx, pos);
544 uint32_t sz = htx_get_blksz(blk);
545
546 if (offset < sz)
547 return (struct htx_ret){ .blk = blk, .ret = offset };
548 offset -= sz;
549 }
550
551 return (struct htx_ret){ .blk = NULL };
552}
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200553/* Changes the size of the value. It is the caller responsibility to change the
554 * value itself, make sure there is enough space and update allocated value.
555 */
556static inline void htx_set_blk_value_len(struct htx_blk *blk, uint32_t vlen)
557{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100558 enum htx_blk_type type = htx_get_blk_type(blk);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200559
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100560 switch (type) {
561 case HTX_BLK_HDR:
562 case HTX_BLK_PHDR:
563 blk->info = (type << 28) + (vlen << 8) + (blk->info & 0xff);
564 break;
565 case HTX_BLK_REQ_SL:
566 case HTX_BLK_RES_SL:
567 case HTX_BLK_DATA:
568 case HTX_BLK_TLR:
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100569 blk->info = (type << 28) + vlen;
570 break;
571 default:
572 /* Unexpected case */
573 break;
574 }
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200575}
576
577/* Returns the data pointer of the block <blk> */
578static inline void *htx_get_blk_ptr(const struct htx *htx, const struct htx_blk *blk)
579{
580 return ((void *)htx->blocks + blk->addr);
581}
582
583/* Returns the name of the block <blk>, only if it is a header. Otherwise it
584 * returns an empty name.
585 */
586static inline struct ist htx_get_blk_name(const struct htx *htx, const struct htx_blk *blk)
587{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100588 enum htx_blk_type type = htx_get_blk_type(blk);
589 struct ist ret;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200590
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100591 switch (type) {
592 case HTX_BLK_HDR:
593 ret.ptr = htx_get_blk_ptr(htx, blk);
594 ret.len = blk->info & 0xff;
595 break;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200596
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100597 default:
598 return ist("");
599 }
600 return ret;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200601}
602
Christopher Faulet54483df2018-11-26 15:05:52 +0100603
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200604/* Returns the value of the block <blk>, depending on its type. If there is no
605 * value, an empty one is retruned.
606 */
607static inline struct ist htx_get_blk_value(const struct htx *htx, const struct htx_blk *blk)
608{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100609 enum htx_blk_type type = htx_get_blk_type(blk);
610 struct ist ret;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200611
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100612 switch (type) {
613 case HTX_BLK_HDR:
614 ret.ptr = htx_get_blk_ptr(htx, blk) + (blk->info & 0xff);
615 ret.len = (blk->info >> 8) & 0xfffff;
616 break;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200617
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100618 case HTX_BLK_PHDR:
619 ret.ptr = htx_get_blk_ptr(htx, blk);
620 ret.len = (blk->info >> 8) & 0xfffff;
621 break;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200622
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100623 case HTX_BLK_REQ_SL:
624 case HTX_BLK_RES_SL:
625 case HTX_BLK_DATA:
626 case HTX_BLK_TLR:
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100627 ret.ptr = htx_get_blk_ptr(htx, blk);
628 ret.len = blk->info & 0xfffffff;
629 break;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200630
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100631 default:
632 return ist("");
633 }
634 return ret;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200635}
636
Christopher Faulet9c66b982019-04-30 18:08:26 +0200637/* Returns the HTX start-line if set, otherwise it returns NULL. */
638static inline struct htx_sl *htx_get_stline(struct htx *htx)
639{
640 struct htx_sl *sl = NULL;
641
642 if (htx->used && htx->sl_pos != -1) {
643 struct htx_blk *blk = htx_get_blk(htx, htx->sl_pos);
644
645 if (blk)
646 sl = htx_get_blk_ptr(htx, blk);
647 }
648 return sl;
649}
650
651
Willy Tarreauc01ed9f2018-11-30 14:29:31 +0100652/* Removes <n> bytes from the beginning of DATA block <blk>. The block's start
653 * address and its length are adjusted, and the htx's total data count is
654 * updated. This is used to mark that part of some data were transfered
655 * from a DATA block without removing this DATA block. No sanity check is
656 * performed, the caller is reponsible for doing this exclusively on DATA
657 * blocks, and never removing more than the block's size.
658 */
659static inline void htx_cut_data_blk(struct htx *htx, struct htx_blk *blk, uint32_t n)
660{
661 blk->addr += n;
662 blk->info -= n;
663 htx->data -= n;
664}
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200665
666/* Returns the space used by metadata in <htx>. */
667static inline uint32_t htx_meta_space(const struct htx *htx)
668{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100669 return (htx->used * sizeof(htx->blocks[0]));
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200670}
671
672/* Returns the space used (data + metadata) in <htx> */
673static inline uint32_t htx_used_space(const struct htx *htx)
674{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100675 return (htx->data + htx_meta_space(htx));
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200676}
677
678/* Returns the free space in <htx> */
679static inline uint32_t htx_free_space(const struct htx *htx)
680{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100681 return (htx->size - htx_used_space(htx));
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200682}
683
Christopher Faulet8564c1f2019-01-07 13:48:55 +0100684/* Returns the maximum space usable for data in <htx>. This is in fact the
685 * maximum sice for a uniq block to fill the HTX message. */
686static inline uint32_t htx_max_data_space(const struct htx *htx)
687{
688 if (!htx->size)
689 return 0;
690 return (htx->size - sizeof(htx->blocks[0]));
691}
692
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200693/* Returns the maximum size available to store some data in <htx> if a new block
694 * is reserved.
695 */
696static inline uint32_t htx_free_data_space(const struct htx *htx)
697{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100698 uint32_t free = htx_free_space(htx);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200699
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100700 if (free < sizeof(htx->blocks[0]))
701 return 0;
702 return (free - sizeof(htx->blocks[0]));
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200703}
704
705/* Returns 1 if the message has less than 1/4 of its capacity free, otherwise 0 */
706static inline int htx_almost_full(const struct htx *htx)
707{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100708 if (!htx->size || htx_free_space(htx) < htx->size / 4)
709 return 1;
710 return 0;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200711}
712
713static inline void htx_reset(struct htx *htx)
714{
Christopher Faulet28f29c72019-04-30 17:55:45 +0200715 htx->data = htx->used = htx->tail = htx->head = htx->front = 0;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200716 htx->extra = 0;
717 htx->flags = HTX_FL_NONE;
Christopher Faulet9c66b982019-04-30 18:08:26 +0200718 htx->sl_pos = -1;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200719}
720
Willy Tarreau3906e222018-12-05 07:56:25 +0100721/* returns the available room for raw data in buffer <buf> once HTX overhead is
722 * taken into account (one HTX header and two blocks). The purpose is to figure
723 * the optimal fill length to avoid copies.
724 */
725static inline size_t buf_room_for_htx_data(const struct buffer *buf)
726{
727 size_t room;
728
729 room = b_room(buf);
730 if (room <= sizeof(struct htx) + 2 * sizeof(struct htx_blk))
731 room = 0;
732 else
733 room -= sizeof(struct htx) + 2 * sizeof(struct htx_blk);
734
735 return room;
736}
737
Christopher Faulet27ba2dc2018-12-05 11:53:24 +0100738
739/* Returns an HTX message using the buffer <buf>. Unlike htx_from_buf(), this
Willy Tarreau245d1892019-01-31 07:21:42 +0100740 * function does not update to the buffer.
741 * Note that it always returns a valid pointer, either to an initialized buffer
742 * or to the empty buffer.
743 */
Christopher Faulet27ba2dc2018-12-05 11:53:24 +0100744static inline struct htx *htxbuf(const struct buffer *buf)
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200745{
Christopher Faulet27ba2dc2018-12-05 11:53:24 +0100746 struct htx *htx;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200747
Christopher Faulet27ba2dc2018-12-05 11:53:24 +0100748 if (b_is_null(buf))
749 return &htx_empty;
750 htx = ((struct htx *)(buf->area));
751 if (!b_data(buf)) {
Willy Tarreau8ae42352018-12-05 09:47:34 +0100752 htx->size = buf->size - sizeof(*htx);
Christopher Faulet27ba2dc2018-12-05 11:53:24 +0100753 htx_reset(htx);
Willy Tarreau8ae42352018-12-05 09:47:34 +0100754 }
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200755 return htx;
756}
757
Christopher Faulet27ba2dc2018-12-05 11:53:24 +0100758/* Returns an HTX message using the buffer <buf>. <buf> is updated to appear as
759 * full. It is the caller responsibility to call htx_to_buf() when it finish to
Willy Tarreau245d1892019-01-31 07:21:42 +0100760 * manipulate the HTX message to update <buf> accordingly. The returned pointer
761 * is always valid.
Christopher Faulet27ba2dc2018-12-05 11:53:24 +0100762 *
Willy Tarreau245d1892019-01-31 07:21:42 +0100763 * The caller can call htxbuf() function to avoid any update of the buffer.
Christopher Faulet27ba2dc2018-12-05 11:53:24 +0100764 */
765static inline struct htx *htx_from_buf(struct buffer *buf)
766{
767 struct htx *htx = htxbuf(buf);
768
769 b_set_data(buf, b_size(buf));
770 return htx;
771}
772
773/* Upate <buf> accordingly to the HTX message <htx> */
774static inline void htx_to_buf(struct htx *htx, struct buffer *buf)
775{
Christopher Faulet0ef372a2019-04-08 10:57:20 +0200776 if (!htx->used && !(htx->flags & (HTX_FL_PARSING_ERROR|HTX_FL_UPGRADE))) {
Christopher Faulet27ba2dc2018-12-05 11:53:24 +0100777 htx_reset(htx);
778 b_set_data(buf, 0);
779 }
780 else
781 b_set_data(buf, b_size(buf));
782}
783
Willy Tarreaue5fcfbe2019-01-31 07:31:18 +0100784/* Returns 1 if the message is empty, otherwise it returns 0. Note that it is
785 * illegal to call this with htx == NULL.
786 */
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200787static inline int htx_is_empty(const struct htx *htx)
788{
Willy Tarreaue5fcfbe2019-01-31 07:31:18 +0100789 return !htx->used;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200790}
791
Willy Tarreaue5fcfbe2019-01-31 07:31:18 +0100792/* Returns 1 if the message is not empty, otherwise it returns 0. Note that it
793 * is illegal to call this with htx == NULL.
794 */
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200795static inline int htx_is_not_empty(const struct htx *htx)
796{
Willy Tarreaue5fcfbe2019-01-31 07:31:18 +0100797 return htx->used;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200798}
799
800/* For debugging purpose */
801static inline const char *htx_blk_type_str(enum htx_blk_type type)
802{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100803 switch (type) {
804 case HTX_BLK_REQ_SL: return "HTX_BLK_REQ_SL";
805 case HTX_BLK_RES_SL: return "HTX_BLK_RES_SL";
806 case HTX_BLK_HDR: return "HTX_BLK_HDR";
807 case HTX_BLK_PHDR: return "HTX_BLK_PHDR";
808 case HTX_BLK_EOH: return "HTX_BLK_EOH";
809 case HTX_BLK_DATA: return "HTX_BLK_DATA";
810 case HTX_BLK_EOD: return "HTX_BLK_EOD";
811 case HTX_BLK_TLR: return "HTX_BLK_TLR";
812 case HTX_BLK_EOM: return "HTX_BLK_EOM";
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100813 case HTX_BLK_UNUSED: return "HTX_BLK_UNUSED";
814 default: return "HTX_BLK_???";
815 };
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200816}
817
818static inline const char *htx_blk_phdr_str(enum htx_phdr_type phdr)
819{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100820 switch (phdr) {
821 case HTX_PHDR_UNKNOWN: return "HTX_PHDR_UNKNOWN";
822 default: return "HTX_PHDR_???";
823 }
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200824}
825
826static inline void htx_dump(struct htx *htx)
827{
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100828 int32_t pos;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200829
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100830 fprintf(stderr, "htx:%p [ size=%u - data=%u - used=%u - wrap=%s - extra=%llu]\n",
Christopher Faulet28f29c72019-04-30 17:55:45 +0200831 htx, htx->size, htx->data, htx->used, (htx->tail >= htx->head) ? "NO" : "YES",
Willy Tarreaua7280a12018-11-26 19:41:40 +0100832 (unsigned long long)htx->extra);
Christopher Faulet9c66b982019-04-30 18:08:26 +0200833 fprintf(stderr, "\tsl_pos=%d - head=%u, tail=%u - front=%u\n",
834 htx->sl_pos, htx->head, htx->tail, htx->front);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200835
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100836 for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) {
Christopher Faulet570d1612018-11-26 11:13:57 +0100837 struct htx_sl *sl;
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100838 struct htx_blk *blk = htx_get_blk(htx, pos);
839 enum htx_blk_type type = htx_get_blk_type(blk);
840 enum htx_phdr_type phdr = htx_get_blk_phdr(blk);
841 uint32_t sz = htx_get_blksz(blk);
842 struct ist n, v;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200843
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100844 n = htx_get_blk_name(htx, blk);
845 v = htx_get_blk_value(htx, blk);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200846
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100847 if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) {
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200848 sl = htx_get_blk_ptr(htx, blk);
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100849 fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s %.*s %.*s\n",
850 pos, htx_blk_type_str(type), sz, blk->addr,
851 HTX_SL_P1_LEN(sl), HTX_SL_P1_PTR(sl),
852 HTX_SL_P2_LEN(sl), HTX_SL_P2_PTR(sl),
853 HTX_SL_P3_LEN(sl), HTX_SL_P3_PTR(sl));
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200854 }
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100855 else if (type == HTX_BLK_HDR)
856 fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s: %.*s\n",
857 pos, htx_blk_type_str(type), sz, blk->addr,
858 (int)n.len, n.ptr,
859 (int)v.len, v.ptr);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200860
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100861 else if (type == HTX_BLK_PHDR)
862 fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s\n",
863 pos, htx_blk_phdr_str(phdr), sz, blk->addr,
864 (int)v.len, v.ptr);
865 else
866 fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u%s\n",
867 pos, htx_blk_type_str(type), sz, blk->addr,
868 (!v.len ? "\t<empty>" : ""));
869 }
870 fprintf(stderr, "\n");
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200871}
872
Willy Tarreaub96b77e2018-12-11 10:22:41 +0100873#endif /* _COMMON_HTX_H */
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200874
875/*
876 * Local variables:
877 * c-indent-level: 8
878 * c-basic-offset: 8
879 * End:
880 */