blob: f15d9312b617020799763c2e5d0bc11b14ecb72a [file] [log] [blame]
Christopher Fauleta3d2a162018-10-22 08:59:39 +02001/*
2 * include/proto/hx.h
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
22#ifndef _PROTO_HTX_H
23#define _PROTO_HTX_H
24
25#include <common/buf.h>
26#include <common/config.h>
27#include <common/standard.h>
28#include <common/http-hdr.h>
Christopher Fauleta3d2a162018-10-22 08:59:39 +020029#include <types/htx.h>
30
31extern struct htx htx_empty;
32
33struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk);
34struct htx_blk *htx_add_blk(struct htx *htx, enum htx_blk_type type, uint32_t blksz);
35struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk);
36
37struct htx_blk *htx_replace_blk_value(struct htx *htx, struct htx_blk *blk,
38 const struct ist old, const struct ist new);
39struct htx_ret htx_xfer_blks(struct htx *dst, struct htx *src, uint32_t count,
40 enum htx_blk_type mark);
41
Christopher Fauletf1ba18d2018-11-26 21:37:08 +010042struct htx_sl *htx_add_stline(struct htx *htx, enum htx_blk_type type, unsigned int flags,
43 const struct ist p1, const struct ist p2, const struct ist p3);
44struct htx_sl *htx_replace_stline(struct htx *htx, struct htx_blk *blk, const struct ist p1,
45 const struct ist p2, const struct ist p3);
46
Christopher Fauleta3d2a162018-10-22 08:59:39 +020047struct htx_blk *htx_replace_header(struct htx *htx, struct htx_blk *blk,
48 const struct ist name, const struct ist value);
49
Christopher Fauleta3d2a162018-10-22 08:59:39 +020050struct htx_blk *htx_add_header(struct htx *htx, const struct ist name, const struct ist value);
51struct htx_blk *htx_add_all_headers(struct htx *htx, const struct http_hdr *hdrs);
52struct htx_blk *htx_add_pseudo_header(struct htx *htx, enum htx_phdr_type phdr, const struct ist value);
53struct htx_blk *htx_add_endof(struct htx *htx, enum htx_blk_type type);
54struct htx_blk *htx_add_data(struct htx *htx, const struct ist data);
55struct htx_blk *htx_add_trailer(struct htx *htx, const struct ist tlr);
56struct htx_blk *htx_add_oob(struct htx *htx, const struct ist oob);
Christopher Faulet24ed8352018-11-22 11:20:43 +010057struct 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 +020058
Christopher Faulet570d1612018-11-26 11:13:57 +010059int htx_reqline_to_str(const struct htx_sl *sl, struct buffer *chk);
60int htx_stline_to_str(const struct htx_sl *sl, struct buffer *chk);
Christopher Fauleta3d2a162018-10-22 08:59:39 +020061int htx_hdr_to_str(const struct ist n, const struct ist v, struct buffer *chk);
62int htx_data_to_str(const struct ist data, struct buffer *chk, int chunked);
63int htx_trailer_to_str(const struct ist tlr, struct buffer *chk);
64
Christopher Faulet570d1612018-11-26 11:13:57 +010065/* Functions and macros to get parts of the start-line or legnth of these
66 * parts
67 */
68#define HTX_SL_LEN(sl) ((sl)->len[0] + (sl)->len[1] + (sl)->len[2])
69
70#define HTX_SL_P1_LEN(sl) ((sl)->len[0])
71#define HTX_SL_P2_LEN(sl) ((sl)->len[1])
72#define HTX_SL_P3_LEN(sl) ((sl)->len[2])
73#define HTX_SL_P1_PTR(sl) ((sl)->l)
74#define HTX_SL_P2_PTR(sl) (HTX_SL_P1_PTR(sl) + HTX_SL_P1_LEN(sl))
75#define HTX_SL_P3_PTR(sl) (HTX_SL_P2_PTR(sl) + HTX_SL_P2_LEN(sl))
76
77#define HTX_SL_REQ_MLEN(sl) HTX_SL_P1_LEN(sl)
78#define HTX_SL_REQ_ULEN(sl) HTX_SL_P2_LEN(sl)
79#define HTX_SL_REQ_VLEN(sl) HTX_SL_P3_LEN(sl)
80#define HTX_SL_REQ_MPTR(sl) HTX_SL_P1_PTR(sl)
81#define HTX_SL_REQ_UPTR(sl) HTX_SL_P2_PTR(sl)
82#define HTX_SL_REQ_VPTR(sl) HTX_SL_P3_PTR(sl)
83
84#define HTX_SL_RES_VLEN(sl) HTX_SL_P1_LEN(sl)
85#define HTX_SL_RES_CLEN(sl) HTX_SL_P2_LEN(sl)
86#define HTX_SL_RES_RLEN(sl) HTX_SL_P3_LEN(sl)
87#define HTX_SL_RES_VPTR(sl) HTX_SL_P1_PTR(sl)
88#define HTX_SL_RES_CPTR(sl) HTX_SL_P2_PTR(sl)
89#define HTX_SL_RES_RPTR(sl) HTX_SL_P3_PTR(sl)
90
91static inline const struct ist htx_sl_p1(const struct htx_sl *sl)
92{
93 return ist2(HTX_SL_P1_PTR(sl), HTX_SL_P1_LEN(sl));
94}
95
96static inline const struct ist htx_sl_p2(const struct htx_sl *sl)
97{
98 return ist2(HTX_SL_P2_PTR(sl), HTX_SL_P2_LEN(sl));
99}
100
101static inline const struct ist htx_sl_p3(const struct htx_sl *sl)
102{
103 return ist2(HTX_SL_P3_PTR(sl), HTX_SL_P3_LEN(sl));
104}
105
106
107static inline const struct ist htx_sl_req_meth(const struct htx_sl *sl)
108{
109 return htx_sl_p1(sl);
110}
111
112static inline const struct ist htx_sl_req_uri(const struct htx_sl *sl)
113{
114 return htx_sl_p2(sl);
115}
116
117static inline const struct ist htx_sl_req_vsn(const struct htx_sl *sl)
118{
119 return htx_sl_p3(sl);
120}
121
122
123static inline const struct ist htx_sl_res_vsn(const struct htx_sl *sl)
124{
125 return htx_sl_p1(sl);
126}
127
128static inline const struct ist htx_sl_res_code(const struct htx_sl *sl)
129{
130 return htx_sl_p2(sl);
131}
132
133static inline const struct ist htx_sl_res_reason(const struct htx_sl *sl)
134{
135 return htx_sl_p3(sl);
136}
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200137
Christopher Faulet54483df2018-11-26 15:05:52 +0100138/* Returns the HTX start-line if set, otherwise it returns NULL. */
139static inline struct htx_sl *htx_get_stline(struct htx *htx)
140{
141 struct htx_sl *sl = NULL;
142
143 if (htx->sl_off != -1)
144 sl = ((void *)htx->blocks + htx->sl_off);
145
146 return sl;
147}
148
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200149/* Returns the array index of a block given its position <pos> */
150static inline uint32_t htx_pos_to_idx(const struct htx *htx, uint32_t pos)
151{
152 return ((htx->size / sizeof(htx->blocks[0])) - pos - 1);
153}
154
155/* Returns the position of the block <blk> */
156static inline uint32_t htx_get_blk_pos(const struct htx *htx, const struct htx_blk *blk)
157{
158 return (htx->blocks + (htx->size / sizeof(htx->blocks[0])) - blk - 1);
159}
160
161/* Returns the block at the position <pos> */
162static inline struct htx_blk *htx_get_blk(const struct htx *htx, uint32_t pos)
163{
164 return ((struct htx_blk *)(htx->blocks) + htx_pos_to_idx(htx, pos));
165}
166
167/* Returns the type of the block <blk> */
168static inline enum htx_blk_type htx_get_blk_type(const struct htx_blk *blk)
169{
170 return (blk->info >> 28);
171}
172
173/* Returns the pseudo-header type of the block <blk>. If it's not a
174 * pseudo-header, HTX_PHDR_UNKNOWN is returned.
175 */
176static inline enum htx_phdr_type htx_get_blk_phdr(const struct htx_blk *blk)
177{
178 enum htx_blk_type type = htx_get_blk_type(blk);
179 enum htx_phdr_type phdr;
180
181 switch (type) {
182 case HTX_BLK_PHDR:
183 phdr = (blk->info & 0xff);
184 return phdr;
185
186 default:
187 /* Not a pseudo-header */
188 return HTX_PHDR_UNKNOWN;
189 }
190}
191
192/* Returns the size of the block <blk>, depending of its type */
193static inline uint32_t htx_get_blksz(const struct htx_blk *blk)
194{
195 enum htx_blk_type type = htx_get_blk_type(blk);
196
197 switch (type) {
198 case HTX_BLK_HDR:
199 /* name.length + value.length */
200 return ((blk->info & 0xff) + ((blk->info >> 8) & 0xfffff));
201 case HTX_BLK_PHDR:
202 /* value.length */
203 return ((blk->info >> 8) & 0xfffff);
204 default:
205 /* value.length */
206 return (blk->info & 0xfffffff);
207 }
208}
209
210/* Returns the position of the oldest entry (head).
211 *
212 * An signed 32-bits integer is returned to handle -1 case. Blocks position are
213 * store on unsigned 32-bits integer, but it is impossible to have so much
214 * blocks to overflow a 32-bits signed integer !
215 */
216static inline int32_t htx_get_head(const struct htx *htx)
217{
218 if (!htx->used)
219 return -1;
220
221 return (((htx->tail + 1U < htx->used) ? htx->wrap : 0) + htx->tail + 1U - htx->used);
222}
223
224/* Returns the oldest HTX block (head) if the HTX message is not
225 * empty. Otherwise it returns NULL.
226*/
227static inline struct htx_blk *htx_get_head_blk(const struct htx *htx)
228{
229 int32_t head = htx_get_head(htx);
230
231 return ((head == -1) ? NULL : htx_get_blk(htx, head));
232}
233
234/* Returns the type of the oldest HTX block (head) if the HTX message is not
235 * empty. Otherwise it returns HTX_BLK_UNUSED.
236 */
237static inline enum htx_blk_type htx_get_head_type(const struct htx *htx)
238{
239 struct htx_blk *blk = htx_get_head_blk(htx);
240
241 return (blk ? htx_get_blk_type(blk) : HTX_BLK_UNUSED);
242}
243
244/* Returns the position of the newest entry (tail).
245 *
246 * An signed 32-bits integer is returned to handle -1 case. Blocks position are
247 * store on unsigned 32-bits integer, but it is impossible to have so much
248 * blocks to overflow a 32-bits signed integer !
249 */
250static inline int32_t htx_get_tail(const struct htx *htx)
251{
252 return (htx->used ? htx->tail : -1);
253}
254
255/* Returns the newest HTX block (tail) if the HTX message is not
256 * empty. Otherwise it returns NULL.
257*/
258static inline struct htx_blk *htx_get_tail_blk(const struct htx *htx)
259{
260 int32_t tail = htx_get_tail(htx);
261
262 return ((tail == -1) ? NULL : htx_get_blk(htx, tail));
263}
264
265/* Returns the type of the newest HTX block (tail) if the HTX message is not
266 * empty. Otherwise it returns HTX_BLK_UNUSED.
267 */
268static inline enum htx_blk_type htx_get_tail_type(const struct htx *htx)
269{
270 struct htx_blk *blk = htx_get_tail_blk(htx);
271
272 return (blk ? htx_get_blk_type(blk) : HTX_BLK_UNUSED);
273}
274
Joseph Herlantc42c0e92018-11-25 10:43:27 -0800275/* Returns the position of block immediately before the one pointed by <pos>. If
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200276 * the message is empty or if <pos> is the position of the head, -1 returned.
277 *
278 * An signed 32-bits integer is returned to handle -1 case. Blocks position are
279 * store on unsigned 32-bits integer, but it is impossible to have so much
280 * blocks to overflow a 32-bits signed integer !
281 */
282static inline int32_t htx_get_prev(const struct htx *htx, uint32_t pos)
283{
284 int32_t head;
285
286 head = htx_get_head(htx);
287 if (head == -1 || pos == head)
288 return -1;
289 if (!pos)
290 return (htx->wrap - 1);
291 return (pos - 1);
292}
293
Christopher Fauletd16b0a72018-11-22 11:23:23 +0100294/* Returns the HTX block before <blk> in the HTX message <htx>. If <blk> is the
295 * head, NULL returned.
296*/
297static inline struct htx_blk *htx_get_prev_blk(const struct htx *htx,
298 const struct htx_blk *blk)
299{
300 int32_t pos;
301
302 pos = htx_get_prev(htx, htx_get_blk_pos(htx, blk));
303 return ((pos == -1) ? NULL : htx_get_blk(htx, pos));
304}
305
Joseph Herlantc42c0e92018-11-25 10:43:27 -0800306/* Returns the position of block immediately after the one pointed by <pos>. If
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200307 * the message is empty or if <pos> is the position of the tail, -1 returned.
308 *
309 * An signed 32-bits integer is returned to handle -1 case. Blocks position are
310 * store on unsigned 32-bits integer, but it is impossible to have so much
311 * blocks to overflow a 32-bits signed integer !
312 */
313static inline int32_t htx_get_next(const struct htx *htx, uint32_t pos)
314{
315 if (!htx->used)
316 return -1;
317
318 if (pos == htx->tail)
319 return -1;
320 pos++;
321 if (pos >= htx->wrap)
322 pos = 0;
323 return pos;
324
325}
Christopher Fauletd16b0a72018-11-22 11:23:23 +0100326
327/* Returns the HTX block after <blk> in the HTX message <htx>. If <blk> is the
328 * tail, NULL returned.
329*/
330static inline struct htx_blk *htx_get_next_blk(const struct htx *htx,
331 const struct htx_blk *blk)
332{
333 int32_t pos;
334
335 pos = htx_get_next(htx, htx_get_blk_pos(htx, blk));
336 return ((pos == -1) ? NULL : htx_get_blk(htx, pos));
337}
338
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200339static inline int32_t htx_find_front(const struct htx *htx)
340{
341 int32_t front, pos;
342 uint32_t addr = 0;
343
344 if (!htx->used)
345 return -1;
346
347 front = -1;
348 for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) {
349 struct htx_blk *blk = htx_get_blk(htx, pos);
350 enum htx_blk_type type = htx_get_blk_type(blk);
351
352 if (type != HTX_BLK_UNUSED && blk->addr >= addr) {
353 front = pos;
354 addr = blk->addr;
355 }
356 }
357
358 return front;
359}
360
Christopher Faulet14e88252018-11-22 11:28:18 +0100361/* Returns the HTX block containing data with the <offset>, relatively to the
362 * beginning of the HTX message <htx>. It returns an htx_ret. if the HTX block is
363 * not found, htx_ret.blk is set to NULL. Otherwise, it points to the right HTX
364 * block and htx_ret.ret is set to the remaining offset inside the block.
365 */
366static inline struct htx_ret htx_find_blk(const struct htx *htx, uint32_t offset)
367{
368 int32_t pos;
369
370 for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) {
371 struct htx_blk *blk = htx_get_blk(htx, pos);
372 uint32_t sz = htx_get_blksz(blk);
373
374 if (offset < sz)
375 return (struct htx_ret){ .blk = blk, .ret = offset };
376 offset -= sz;
377 }
378
379 return (struct htx_ret){ .blk = NULL };
380}
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200381/* Changes the size of the value. It is the caller responsibility to change the
382 * value itself, make sure there is enough space and update allocated value.
383 */
384static inline void htx_set_blk_value_len(struct htx_blk *blk, uint32_t vlen)
385{
386 enum htx_blk_type type = htx_get_blk_type(blk);
387
388 switch (type) {
389 case HTX_BLK_HDR:
390 case HTX_BLK_PHDR:
391 blk->info = (type << 28) + (vlen << 8) + (blk->info & 0xff);
392 break;
393 case HTX_BLK_REQ_SL:
394 case HTX_BLK_RES_SL:
395 case HTX_BLK_DATA:
396 case HTX_BLK_TLR:
397 case HTX_BLK_OOB:
398 blk->info = (type << 28) + vlen;
399 break;
400 default:
401 /* Unexpected case */
402 break;
403 }
404}
405
406/* Returns the data pointer of the block <blk> */
407static inline void *htx_get_blk_ptr(const struct htx *htx, const struct htx_blk *blk)
408{
409 return ((void *)htx->blocks + blk->addr);
410}
411
412/* Returns the name of the block <blk>, only if it is a header. Otherwise it
413 * returns an empty name.
414 */
415static inline struct ist htx_get_blk_name(const struct htx *htx, const struct htx_blk *blk)
416{
417 enum htx_blk_type type = htx_get_blk_type(blk);
418 struct ist ret;
419
420 switch (type) {
421 case HTX_BLK_HDR:
422 ret.ptr = htx_get_blk_ptr(htx, blk);
423 ret.len = blk->info & 0xff;
424 break;
425
426 default:
427 return ist("");
428 }
429 return ret;
430}
431
Christopher Faulet54483df2018-11-26 15:05:52 +0100432
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200433/* Returns the value of the block <blk>, depending on its type. If there is no
434 * value, an empty one is retruned.
435 */
436static inline struct ist htx_get_blk_value(const struct htx *htx, const struct htx_blk *blk)
437{
438 enum htx_blk_type type = htx_get_blk_type(blk);
439 struct ist ret;
440
441 switch (type) {
442 case HTX_BLK_HDR:
443 ret.ptr = htx_get_blk_ptr(htx, blk) + (blk->info & 0xff);
444 ret.len = (blk->info >> 8) & 0xfffff;
445 break;
446
447 case HTX_BLK_PHDR:
448 ret.ptr = htx_get_blk_ptr(htx, blk);
449 ret.len = (blk->info >> 8) & 0xfffff;
450 break;
451
452 case HTX_BLK_REQ_SL:
453 case HTX_BLK_RES_SL:
454 case HTX_BLK_DATA:
455 case HTX_BLK_TLR:
456 case HTX_BLK_OOB:
457 ret.ptr = htx_get_blk_ptr(htx, blk);
458 ret.len = blk->info & 0xfffffff;
459 break;
460
461 default:
462 return ist("");
463 }
464 return ret;
465}
466
Willy Tarreauc01ed9f2018-11-30 14:29:31 +0100467/* Removes <n> bytes from the beginning of DATA block <blk>. The block's start
468 * address and its length are adjusted, and the htx's total data count is
469 * updated. This is used to mark that part of some data were transfered
470 * from a DATA block without removing this DATA block. No sanity check is
471 * performed, the caller is reponsible for doing this exclusively on DATA
472 * blocks, and never removing more than the block's size.
473 */
474static inline void htx_cut_data_blk(struct htx *htx, struct htx_blk *blk, uint32_t n)
475{
476 blk->addr += n;
477 blk->info -= n;
478 htx->data -= n;
479}
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200480
481/* Returns the space used by metadata in <htx>. */
482static inline uint32_t htx_meta_space(const struct htx *htx)
483{
484 return (htx->used * sizeof(htx->blocks[0]));
485}
486
487/* Returns the space used (data + metadata) in <htx> */
488static inline uint32_t htx_used_space(const struct htx *htx)
489{
490 return (htx->data + htx_meta_space(htx));
491}
492
493/* Returns the free space in <htx> */
494static inline uint32_t htx_free_space(const struct htx *htx)
495{
496 return (htx->size - htx_used_space(htx));
497}
498
499/* Returns the maximum size available to store some data in <htx> if a new block
500 * is reserved.
501 */
502static inline uint32_t htx_free_data_space(const struct htx *htx)
503{
504 uint32_t free = htx_free_space(htx);
505
506 if (free < sizeof(htx->blocks[0]))
507 return 0;
508 return (free - sizeof(htx->blocks[0]));
509}
510
511/* Returns 1 if the message has less than 1/4 of its capacity free, otherwise 0 */
512static inline int htx_almost_full(const struct htx *htx)
513{
514 if (!htx->size || htx_free_space(htx) < htx->size / 4)
515 return 1;
516 return 0;
517}
518
519static inline void htx_reset(struct htx *htx)
520{
521 htx->data = htx->used = htx->tail = htx->wrap = htx->front = 0;
522 htx->extra = 0;
523 htx->flags = HTX_FL_NONE;
Christopher Faulet54483df2018-11-26 15:05:52 +0100524 htx->sl_off = -1;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200525}
526
527/* Returns an HTX message using the buffer <buf>. */
528static inline struct htx *htx_from_buf(struct buffer *buf)
529{
530 struct htx *htx;
531
532 if (b_is_null(buf))
533 return &htx_empty;
534 htx = (struct htx *)(buf->area);
535 htx->size = buf->size - sizeof(*htx);
536 if (!b_data(buf))
537 htx_reset(htx);
538 return htx;
539}
540
541/* Returns 1 if the message is empty, otherwise it returns 0. */
542static inline int htx_is_empty(const struct htx *htx)
543{
544 return (!htx || !htx->used);
545}
546
547/* Returns 1 if the message is not empty, otherwise it returns 0. */
548static inline int htx_is_not_empty(const struct htx *htx)
549{
550 return (htx && htx->used);
551}
552
553/* For debugging purpose */
554static inline const char *htx_blk_type_str(enum htx_blk_type type)
555{
556 switch (type) {
557 case HTX_BLK_REQ_SL: return "HTX_BLK_REQ_SL";
558 case HTX_BLK_RES_SL: return "HTX_BLK_RES_SL";
559 case HTX_BLK_HDR: return "HTX_BLK_HDR";
560 case HTX_BLK_PHDR: return "HTX_BLK_PHDR";
561 case HTX_BLK_EOH: return "HTX_BLK_EOH";
562 case HTX_BLK_DATA: return "HTX_BLK_DATA";
563 case HTX_BLK_EOD: return "HTX_BLK_EOD";
564 case HTX_BLK_TLR: return "HTX_BLK_TLR";
565 case HTX_BLK_EOM: return "HTX_BLK_EOM";
566 case HTX_BLK_OOB: return "HTX_BLK_OOB";
567 case HTX_BLK_UNUSED: return "HTX_BLK_UNUSED";
568 default: return "HTX_BLK_???";
569 };
570}
571
572static inline const char *htx_blk_phdr_str(enum htx_phdr_type phdr)
573{
574 switch (phdr) {
575 case HTX_PHDR_UNKNOWN: return "HTX_PHDR_UNKNOWN";
576 default: return "HTX_PHDR_???";
577 }
578}
579
580static inline void htx_dump(struct htx *htx)
581{
582 int32_t pos;
583
Willy Tarreaua7280a12018-11-26 19:41:40 +0100584 fprintf(stderr, "htx:%p [ size=%u - data=%u - used=%u - wrap=%s - extra=%llu]\n",
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200585 htx, htx->size, htx->data, htx->used,
586 (!htx->used || htx->tail+1 == htx->wrap) ? "NO" : "YES",
Willy Tarreaua7280a12018-11-26 19:41:40 +0100587 (unsigned long long)htx->extra);
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200588 fprintf(stderr, "\thead=%d - tail=%u - front=%u - wrap=%u\n",
589 htx_get_head(htx), htx->tail, htx->front, htx->wrap);
590
591 for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) {
Christopher Faulet570d1612018-11-26 11:13:57 +0100592 struct htx_sl *sl;
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200593 struct htx_blk *blk = htx_get_blk(htx, pos);
594 enum htx_blk_type type = htx_get_blk_type(blk);
595 enum htx_phdr_type phdr = htx_get_blk_phdr(blk);
596 uint32_t sz = htx_get_blksz(blk);
597 struct ist n, v;
598
599 n = htx_get_blk_name(htx, blk);
600 v = htx_get_blk_value(htx, blk);
601
Christopher Faulet570d1612018-11-26 11:13:57 +0100602 if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) {
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200603 sl = htx_get_blk_ptr(htx, blk);
604 fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s %.*s %.*s\n",
605 pos, htx_blk_type_str(type), sz, blk->addr,
Christopher Faulet570d1612018-11-26 11:13:57 +0100606 HTX_SL_P1_LEN(sl), HTX_SL_P1_PTR(sl),
607 HTX_SL_P2_LEN(sl), HTX_SL_P2_PTR(sl),
608 HTX_SL_P3_LEN(sl), HTX_SL_P3_PTR(sl));
Christopher Fauleta3d2a162018-10-22 08:59:39 +0200609 }
610 else if (type == HTX_BLK_HDR)
611 fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s: %.*s\n",
612 pos, htx_blk_type_str(type), sz, blk->addr,
613 (int)n.len, n.ptr,
614 (int)v.len, v.ptr);
615
616 else if (type == HTX_BLK_PHDR)
617 fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s\n",
618 pos, htx_blk_phdr_str(phdr), sz, blk->addr,
619 (int)v.len, v.ptr);
620 else
621 fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u%s\n",
622 pos, htx_blk_type_str(type), sz, blk->addr,
623 (!v.len ? "\t<empty>" : ""));
624 }
625 fprintf(stderr, "\n");
626}
627
628#endif /* _PROTO_HTX_H */
629
630/*
631 * Local variables:
632 * c-indent-level: 8
633 * c-basic-offset: 8
634 * End:
635 */