Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 1 | /* |
| 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 Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 29 | #include <types/htx.h> |
| 30 | |
| 31 | extern struct htx htx_empty; |
| 32 | |
| 33 | struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk); |
| 34 | struct htx_blk *htx_add_blk(struct htx *htx, enum htx_blk_type type, uint32_t blksz); |
| 35 | struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk); |
| 36 | |
| 37 | 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] | 38 | const struct ist old, const struct ist new); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 39 | struct htx_ret htx_xfer_blks(struct htx *dst, struct htx *src, uint32_t count, |
| 40 | enum htx_blk_type mark); |
| 41 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 42 | struct 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); |
| 44 | struct 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 Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 47 | 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] | 48 | const struct ist name, const struct ist value); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 49 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 50 | struct htx_blk *htx_add_header(struct htx *htx, const struct ist name, const struct ist value); |
| 51 | struct htx_blk *htx_add_all_headers(struct htx *htx, const struct http_hdr *hdrs); |
| 52 | struct htx_blk *htx_add_pseudo_header(struct htx *htx, enum htx_phdr_type phdr, const struct ist value); |
| 53 | struct htx_blk *htx_add_endof(struct htx *htx, enum htx_blk_type type); |
| 54 | struct htx_blk *htx_add_data(struct htx *htx, const struct ist data); |
| 55 | struct htx_blk *htx_add_trailer(struct htx *htx, const struct ist tlr); |
| 56 | struct htx_blk *htx_add_oob(struct htx *htx, const struct ist oob); |
Christopher Faulet | 24ed835 | 2018-11-22 11:20:43 +0100 | [diff] [blame] | 57 | struct htx_blk *htx_add_data_before(struct htx *htx, const struct htx_blk *ref, const struct ist data); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 58 | |
Christopher Faulet | c59ff23 | 2018-12-03 13:58:44 +0100 | [diff] [blame] | 59 | int htx_reqline_to_h1(const struct htx_sl *sl, struct buffer *chk); |
| 60 | int htx_stline_to_h1(const struct htx_sl *sl, struct buffer *chk); |
| 61 | int htx_hdr_to_h1(const struct ist n, const struct ist v, struct buffer *chk); |
| 62 | int htx_data_to_h1(const struct ist data, struct buffer *chk, int chunked); |
| 63 | int htx_trailer_to_h1(const struct ist tlr, struct buffer *chk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 64 | |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 65 | /* 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 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 91 | static 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 | } |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 95 | |
| 96 | static 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 | |
| 101 | static 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 | |
| 107 | static inline const struct ist htx_sl_req_meth(const struct htx_sl *sl) |
| 108 | { |
| 109 | return htx_sl_p1(sl); |
| 110 | } |
| 111 | |
| 112 | static inline const struct ist htx_sl_req_uri(const struct htx_sl *sl) |
| 113 | { |
| 114 | return htx_sl_p2(sl); |
| 115 | } |
| 116 | |
| 117 | static inline const struct ist htx_sl_req_vsn(const struct htx_sl *sl) |
| 118 | { |
| 119 | return htx_sl_p3(sl); |
| 120 | } |
| 121 | |
| 122 | |
| 123 | static inline const struct ist htx_sl_res_vsn(const struct htx_sl *sl) |
| 124 | { |
| 125 | return htx_sl_p1(sl); |
| 126 | } |
| 127 | |
| 128 | static inline const struct ist htx_sl_res_code(const struct htx_sl *sl) |
| 129 | { |
| 130 | return htx_sl_p2(sl); |
| 131 | } |
| 132 | |
| 133 | static inline const struct ist htx_sl_res_reason(const struct htx_sl *sl) |
| 134 | { |
| 135 | return htx_sl_p3(sl); |
| 136 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 137 | |
Christopher Faulet | 54483df | 2018-11-26 15:05:52 +0100 | [diff] [blame] | 138 | /* Returns the HTX start-line if set, otherwise it returns NULL. */ |
| 139 | static 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 Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 149 | /* Returns the array index of a block given its position <pos> */ |
| 150 | static inline uint32_t htx_pos_to_idx(const struct htx *htx, uint32_t pos) |
| 151 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 152 | return ((htx->size / sizeof(htx->blocks[0])) - pos - 1); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /* Returns the position of the block <blk> */ |
| 156 | static inline uint32_t htx_get_blk_pos(const struct htx *htx, const struct htx_blk *blk) |
| 157 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 158 | return (htx->blocks + (htx->size / sizeof(htx->blocks[0])) - blk - 1); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /* Returns the block at the position <pos> */ |
| 162 | static inline struct htx_blk *htx_get_blk(const struct htx *htx, uint32_t pos) |
| 163 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 164 | return ((struct htx_blk *)(htx->blocks) + htx_pos_to_idx(htx, pos)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | /* Returns the type of the block <blk> */ |
| 168 | static inline enum htx_blk_type htx_get_blk_type(const struct htx_blk *blk) |
| 169 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 170 | return (blk->info >> 28); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 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 | */ |
| 176 | static inline enum htx_phdr_type htx_get_blk_phdr(const struct htx_blk *blk) |
| 177 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 178 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 179 | enum htx_phdr_type phdr; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 180 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 181 | switch (type) { |
| 182 | case HTX_BLK_PHDR: |
| 183 | phdr = (blk->info & 0xff); |
| 184 | return phdr; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 185 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 186 | default: |
| 187 | /* Not a pseudo-header */ |
| 188 | return HTX_PHDR_UNKNOWN; |
| 189 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* Returns the size of the block <blk>, depending of its type */ |
| 193 | static inline uint32_t htx_get_blksz(const struct htx_blk *blk) |
| 194 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 195 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 196 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 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 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 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 | */ |
| 216 | static inline int32_t htx_get_head(const struct htx *htx) |
| 217 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 218 | if (!htx->used) |
| 219 | return -1; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 220 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 221 | return (((htx->tail + 1U < htx->used) ? htx->wrap : 0) + htx->tail + 1U - htx->used); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | /* Returns the oldest HTX block (head) if the HTX message is not |
| 225 | * empty. Otherwise it returns NULL. |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 226 | */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 227 | static 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 | */ |
| 237 | static 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 | */ |
| 250 | static inline int32_t htx_get_tail(const struct htx *htx) |
| 251 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 252 | return (htx->used ? htx->tail : -1); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /* Returns the newest HTX block (tail) if the HTX message is not |
| 256 | * empty. Otherwise it returns NULL. |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 257 | */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 258 | static 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 | */ |
| 268 | static 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 Herlant | c42c0e9 | 2018-11-25 10:43:27 -0800 | [diff] [blame] | 275 | /* 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] | 276 | * 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 | */ |
| 282 | static inline int32_t htx_get_prev(const struct htx *htx, uint32_t pos) |
| 283 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 284 | int32_t head; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 285 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 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); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 292 | } |
| 293 | |
Christopher Faulet | d16b0a7 | 2018-11-22 11:23:23 +0100 | [diff] [blame] | 294 | /* Returns the HTX block before <blk> in the HTX message <htx>. If <blk> is the |
| 295 | * head, NULL returned. |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 296 | */ |
Christopher Faulet | d16b0a7 | 2018-11-22 11:23:23 +0100 | [diff] [blame] | 297 | static 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 Herlant | c42c0e9 | 2018-11-25 10:43:27 -0800 | [diff] [blame] | 306 | /* 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] | 307 | * 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 | */ |
| 313 | static inline int32_t htx_get_next(const struct htx *htx, uint32_t pos) |
| 314 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 315 | if (!htx->used) |
| 316 | return -1; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 317 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 318 | if (pos == htx->tail) |
| 319 | return -1; |
| 320 | pos++; |
| 321 | if (pos >= htx->wrap) |
| 322 | pos = 0; |
| 323 | return pos; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 324 | |
| 325 | } |
Christopher Faulet | d16b0a7 | 2018-11-22 11:23:23 +0100 | [diff] [blame] | 326 | |
| 327 | /* Returns the HTX block after <blk> in the HTX message <htx>. If <blk> is the |
| 328 | * tail, NULL returned. |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 329 | */ |
Christopher Faulet | d16b0a7 | 2018-11-22 11:23:23 +0100 | [diff] [blame] | 330 | static 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 Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 339 | static inline int32_t htx_find_front(const struct htx *htx) |
| 340 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 341 | int32_t front, pos; |
| 342 | uint32_t addr = 0; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 343 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 344 | if (!htx->used) |
| 345 | return -1; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 346 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 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); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 351 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 352 | if (type != HTX_BLK_UNUSED && blk->addr >= addr) { |
| 353 | front = pos; |
| 354 | addr = blk->addr; |
| 355 | } |
| 356 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 357 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 358 | return front; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Christopher Faulet | 14e8825 | 2018-11-22 11:28:18 +0100 | [diff] [blame] | 361 | /* 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 | */ |
| 366 | static 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 Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 381 | /* 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 | */ |
| 384 | static inline void htx_set_blk_value_len(struct htx_blk *blk, uint32_t vlen) |
| 385 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 386 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 387 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 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 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | /* Returns the data pointer of the block <blk> */ |
| 407 | static 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 | */ |
| 415 | static inline struct ist htx_get_blk_name(const struct htx *htx, const struct htx_blk *blk) |
| 416 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 417 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 418 | struct ist ret; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 419 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 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; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 425 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 426 | default: |
| 427 | return ist(""); |
| 428 | } |
| 429 | return ret; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 430 | } |
| 431 | |
Christopher Faulet | 54483df | 2018-11-26 15:05:52 +0100 | [diff] [blame] | 432 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 433 | /* Returns the value of the block <blk>, depending on its type. If there is no |
| 434 | * value, an empty one is retruned. |
| 435 | */ |
| 436 | static inline struct ist htx_get_blk_value(const struct htx *htx, const struct htx_blk *blk) |
| 437 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 438 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 439 | struct ist ret; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 440 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 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; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 446 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 447 | case HTX_BLK_PHDR: |
| 448 | ret.ptr = htx_get_blk_ptr(htx, blk); |
| 449 | ret.len = (blk->info >> 8) & 0xfffff; |
| 450 | break; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 451 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 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; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 460 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 461 | default: |
| 462 | return ist(""); |
| 463 | } |
| 464 | return ret; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 465 | } |
| 466 | |
Willy Tarreau | c01ed9f | 2018-11-30 14:29:31 +0100 | [diff] [blame] | 467 | /* 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 | */ |
| 474 | static 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 Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 480 | |
| 481 | /* Returns the space used by metadata in <htx>. */ |
| 482 | static inline uint32_t htx_meta_space(const struct htx *htx) |
| 483 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 484 | return (htx->used * sizeof(htx->blocks[0])); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | /* Returns the space used (data + metadata) in <htx> */ |
| 488 | static inline uint32_t htx_used_space(const struct htx *htx) |
| 489 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 490 | return (htx->data + htx_meta_space(htx)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /* Returns the free space in <htx> */ |
| 494 | static inline uint32_t htx_free_space(const struct htx *htx) |
| 495 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 496 | return (htx->size - htx_used_space(htx)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | /* Returns the maximum size available to store some data in <htx> if a new block |
| 500 | * is reserved. |
| 501 | */ |
| 502 | static inline uint32_t htx_free_data_space(const struct htx *htx) |
| 503 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 504 | uint32_t free = htx_free_space(htx); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 505 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 506 | if (free < sizeof(htx->blocks[0])) |
| 507 | return 0; |
| 508 | return (free - sizeof(htx->blocks[0])); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | /* Returns 1 if the message has less than 1/4 of its capacity free, otherwise 0 */ |
| 512 | static inline int htx_almost_full(const struct htx *htx) |
| 513 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 514 | if (!htx->size || htx_free_space(htx) < htx->size / 4) |
| 515 | return 1; |
| 516 | return 0; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | static inline void htx_reset(struct htx *htx) |
| 520 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 521 | htx->data = htx->used = htx->tail = htx->wrap = htx->front = 0; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 522 | htx->extra = 0; |
| 523 | htx->flags = HTX_FL_NONE; |
Christopher Faulet | 54483df | 2018-11-26 15:05:52 +0100 | [diff] [blame] | 524 | htx->sl_off = -1; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 525 | } |
| 526 | |
Willy Tarreau | 3906e22 | 2018-12-05 07:56:25 +0100 | [diff] [blame] | 527 | /* returns the available room for raw data in buffer <buf> once HTX overhead is |
| 528 | * taken into account (one HTX header and two blocks). The purpose is to figure |
| 529 | * the optimal fill length to avoid copies. |
| 530 | */ |
| 531 | static inline size_t buf_room_for_htx_data(const struct buffer *buf) |
| 532 | { |
| 533 | size_t room; |
| 534 | |
| 535 | room = b_room(buf); |
| 536 | if (room <= sizeof(struct htx) + 2 * sizeof(struct htx_blk)) |
| 537 | room = 0; |
| 538 | else |
| 539 | room -= sizeof(struct htx) + 2 * sizeof(struct htx_blk); |
| 540 | |
| 541 | return room; |
| 542 | } |
| 543 | |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 544 | |
| 545 | /* Returns an HTX message using the buffer <buf>. Unlike htx_from_buf(), this |
| 546 | * function does not update to the buffer. */ |
| 547 | static inline struct htx *htxbuf(const struct buffer *buf) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 548 | { |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 549 | struct htx *htx; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 550 | |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 551 | if (b_is_null(buf)) |
| 552 | return &htx_empty; |
| 553 | htx = ((struct htx *)(buf->area)); |
| 554 | if (!b_data(buf)) { |
Willy Tarreau | 8ae4235 | 2018-12-05 09:47:34 +0100 | [diff] [blame] | 555 | htx->size = buf->size - sizeof(*htx); |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 556 | htx_reset(htx); |
Willy Tarreau | 8ae4235 | 2018-12-05 09:47:34 +0100 | [diff] [blame] | 557 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 558 | return htx; |
| 559 | } |
| 560 | |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 561 | /* Returns an HTX message using the buffer <buf>. <buf> is updated to appear as |
| 562 | * full. It is the caller responsibility to call htx_to_buf() when it finish to |
| 563 | * manipulate the HTX message to update <buf> accordingly. |
| 564 | * |
| 565 | * If the caller can call htxbuf() function to avoir any update of the |
| 566 | * buffer. |
| 567 | */ |
| 568 | static inline struct htx *htx_from_buf(struct buffer *buf) |
| 569 | { |
| 570 | struct htx *htx = htxbuf(buf); |
| 571 | |
| 572 | b_set_data(buf, b_size(buf)); |
| 573 | return htx; |
| 574 | } |
| 575 | |
| 576 | /* Upate <buf> accordingly to the HTX message <htx> */ |
| 577 | static inline void htx_to_buf(struct htx *htx, struct buffer *buf) |
| 578 | { |
| 579 | if (!htx->used) { |
| 580 | htx_reset(htx); |
| 581 | b_set_data(buf, 0); |
| 582 | } |
| 583 | else |
| 584 | b_set_data(buf, b_size(buf)); |
| 585 | } |
| 586 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 587 | /* Returns 1 if the message is empty, otherwise it returns 0. */ |
| 588 | static inline int htx_is_empty(const struct htx *htx) |
| 589 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 590 | return (!htx || !htx->used); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | /* Returns 1 if the message is not empty, otherwise it returns 0. */ |
| 594 | static inline int htx_is_not_empty(const struct htx *htx) |
| 595 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 596 | return (htx && htx->used); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | /* For debugging purpose */ |
| 600 | static inline const char *htx_blk_type_str(enum htx_blk_type type) |
| 601 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 602 | switch (type) { |
| 603 | case HTX_BLK_REQ_SL: return "HTX_BLK_REQ_SL"; |
| 604 | case HTX_BLK_RES_SL: return "HTX_BLK_RES_SL"; |
| 605 | case HTX_BLK_HDR: return "HTX_BLK_HDR"; |
| 606 | case HTX_BLK_PHDR: return "HTX_BLK_PHDR"; |
| 607 | case HTX_BLK_EOH: return "HTX_BLK_EOH"; |
| 608 | case HTX_BLK_DATA: return "HTX_BLK_DATA"; |
| 609 | case HTX_BLK_EOD: return "HTX_BLK_EOD"; |
| 610 | case HTX_BLK_TLR: return "HTX_BLK_TLR"; |
| 611 | case HTX_BLK_EOM: return "HTX_BLK_EOM"; |
| 612 | case HTX_BLK_OOB: return "HTX_BLK_OOB"; |
| 613 | case HTX_BLK_UNUSED: return "HTX_BLK_UNUSED"; |
| 614 | default: return "HTX_BLK_???"; |
| 615 | }; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | static inline const char *htx_blk_phdr_str(enum htx_phdr_type phdr) |
| 619 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 620 | switch (phdr) { |
| 621 | case HTX_PHDR_UNKNOWN: return "HTX_PHDR_UNKNOWN"; |
| 622 | default: return "HTX_PHDR_???"; |
| 623 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | static inline void htx_dump(struct htx *htx) |
| 627 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 628 | int32_t pos; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 629 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 630 | fprintf(stderr, "htx:%p [ size=%u - data=%u - used=%u - wrap=%s - extra=%llu]\n", |
| 631 | htx, htx->size, htx->data, htx->used, |
| 632 | (!htx->used || htx->tail+1 == htx->wrap) ? "NO" : "YES", |
Willy Tarreau | a7280a1 | 2018-11-26 19:41:40 +0100 | [diff] [blame] | 633 | (unsigned long long)htx->extra); |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 634 | fprintf(stderr, "\thead=%d - tail=%u - front=%u - wrap=%u\n", |
| 635 | htx_get_head(htx), htx->tail, htx->front, htx->wrap); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 636 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 637 | 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] | 638 | struct htx_sl *sl; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 639 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 640 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 641 | enum htx_phdr_type phdr = htx_get_blk_phdr(blk); |
| 642 | uint32_t sz = htx_get_blksz(blk); |
| 643 | struct ist n, v; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 644 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 645 | n = htx_get_blk_name(htx, blk); |
| 646 | v = htx_get_blk_value(htx, blk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 647 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 648 | if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) { |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 649 | sl = htx_get_blk_ptr(htx, blk); |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 650 | fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s %.*s %.*s\n", |
| 651 | pos, htx_blk_type_str(type), sz, blk->addr, |
| 652 | HTX_SL_P1_LEN(sl), HTX_SL_P1_PTR(sl), |
| 653 | HTX_SL_P2_LEN(sl), HTX_SL_P2_PTR(sl), |
| 654 | HTX_SL_P3_LEN(sl), HTX_SL_P3_PTR(sl)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 655 | } |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 656 | else if (type == HTX_BLK_HDR) |
| 657 | fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s: %.*s\n", |
| 658 | pos, htx_blk_type_str(type), sz, blk->addr, |
| 659 | (int)n.len, n.ptr, |
| 660 | (int)v.len, v.ptr); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 661 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 662 | else if (type == HTX_BLK_PHDR) |
| 663 | fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s\n", |
| 664 | pos, htx_blk_phdr_str(phdr), sz, blk->addr, |
| 665 | (int)v.len, v.ptr); |
| 666 | else |
| 667 | fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u%s\n", |
| 668 | pos, htx_blk_type_str(type), sz, blk->addr, |
| 669 | (!v.len ? "\t<empty>" : "")); |
| 670 | } |
| 671 | fprintf(stderr, "\n"); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | #endif /* _PROTO_HTX_H */ |
| 675 | |
| 676 | /* |
| 677 | * Local variables: |
| 678 | * c-indent-level: 8 |
| 679 | * c-basic-offset: 8 |
| 680 | * End: |
| 681 | */ |