Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | * internal HTTP message |
| 3 | * |
| 4 | * Copyright 2018 HAProxy Technologies, Christopher Faulet <cfaulet@haproxy.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <common/chunk.h> |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 14 | #include <common/htx.h> |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 15 | |
| 16 | struct htx htx_empty = { .size = 0, .data = 0, .used = 0 }; |
| 17 | |
| 18 | /* Defragments an HTTP message, removing unused blocks and unwrapping blocks and |
| 19 | * their contents. A temporary message is used to do so. This function never |
| 20 | * fails. if <blk> is not NULL, we replace it by the new block address, after |
| 21 | * the defragmentation. The new <blk> is returned. |
| 22 | */ |
| 23 | /* TODO: merge data blocks into one */ |
| 24 | struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk) |
| 25 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 26 | struct buffer *chunk = get_trash_chunk(); |
| 27 | struct htx *tmp = htxbuf(chunk); |
| 28 | struct htx_blk *newblk, *oldblk; |
Christopher Faulet | 200f895 | 2019-01-02 11:23:44 +0100 | [diff] [blame] | 29 | uint32_t new, old, blkpos; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 30 | uint32_t addr, blksz; |
Christopher Faulet | 174bfb1 | 2018-12-06 14:31:12 +0100 | [diff] [blame] | 31 | int32_t sl_off = -1; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 32 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 33 | if (!htx->used) |
| 34 | return NULL; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 35 | |
Christopher Faulet | 200f895 | 2019-01-02 11:23:44 +0100 | [diff] [blame] | 36 | blkpos = -1; |
| 37 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 38 | new = 0; |
| 39 | addr = 0; |
| 40 | tmp->size = htx->size; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 41 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 42 | /* start from the head */ |
| 43 | for (old = htx_get_head(htx); old != -1; old = htx_get_next(htx, old)) { |
| 44 | oldblk = htx_get_blk(htx, old); |
| 45 | if (htx_get_blk_type(oldblk) == HTX_BLK_UNUSED) { |
| 46 | htx->used--; |
| 47 | continue; |
| 48 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 49 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 50 | newblk = htx_get_blk(tmp, new); |
| 51 | newblk->addr = addr; |
| 52 | newblk->info = oldblk->info; |
| 53 | blksz = htx_get_blksz(oldblk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 54 | |
Christopher Faulet | 174bfb1 | 2018-12-06 14:31:12 +0100 | [diff] [blame] | 55 | /* update the start-line offset */ |
| 56 | if (htx->sl_off == oldblk->addr) |
| 57 | sl_off = addr; |
| 58 | |
Christopher Faulet | 200f895 | 2019-01-02 11:23:44 +0100 | [diff] [blame] | 59 | /* if <blk> is defined, set its new position */ |
| 60 | if (blk != NULL && blk == oldblk) |
| 61 | blkpos = new; |
| 62 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 63 | memcpy((void *)tmp->blocks + addr, htx_get_blk_ptr(htx, oldblk), blksz); |
| 64 | new++; |
| 65 | addr += blksz; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 66 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 67 | } while (new < htx->used); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 68 | |
Christopher Faulet | 174bfb1 | 2018-12-06 14:31:12 +0100 | [diff] [blame] | 69 | htx->sl_off = sl_off; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 70 | htx->wrap = htx->used; |
| 71 | htx->front = htx->tail = new - 1; |
| 72 | memcpy((void *)htx->blocks, (void *)tmp->blocks, htx->size); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 73 | |
Christopher Faulet | 200f895 | 2019-01-02 11:23:44 +0100 | [diff] [blame] | 74 | return ((blkpos == -1) ? NULL : htx_get_blk(htx, blkpos)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* Reserves a new block in the HTTP message <htx> with a content of <blksz> |
| 78 | * bytes. If there is not enough space, NULL is returned. Otherwise the reserved |
| 79 | * block is returned and the HTTP message is updated. Space for this new block |
| 80 | * is reserved in the HTTP message. But it is the caller responsibility to set |
| 81 | * right info in the block to reflect the stored data. |
| 82 | */ |
| 83 | static struct htx_blk *htx_reserve_nxblk(struct htx *htx, uint32_t blksz) |
| 84 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 85 | struct htx_blk *blk, *prevblk, *headblk, *frtblk; |
| 86 | uint32_t used; |
| 87 | uint32_t tail; |
| 88 | uint32_t prev; |
| 89 | uint32_t wrap; |
| 90 | uint32_t head; |
| 91 | int32_t headroom, tailroom; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 92 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 93 | if (blksz > htx_free_data_space(htx)) |
| 94 | return NULL; /* full */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 95 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 96 | if (!htx->used) { |
| 97 | /* Empty message */ |
| 98 | htx->front = htx->tail = 0; |
| 99 | htx->wrap = htx->used = 1; |
| 100 | blk = htx_get_blk(htx, htx->tail); |
| 101 | blk->addr = 0; |
| 102 | htx->data = blksz; |
| 103 | return blk; |
| 104 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 105 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 106 | used = htx->used + 1; |
| 107 | tail = htx->tail + 1; |
| 108 | prev = htx->tail; |
| 109 | wrap = htx->wrap; |
| 110 | head = htx_get_head(htx); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 111 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 112 | if (tail == wrap) { |
| 113 | frtblk = htx_get_blk(htx, htx->front); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 114 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 115 | /* Blocks don't wrap for now. We either need to push the new one |
| 116 | * on top of others or to defragement the table. */ |
| 117 | if (sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, wrap+1) >= frtblk->addr + htx_get_blksz(frtblk)) |
| 118 | wrap++; |
| 119 | else if (tail >= used) /* There is hole at the beginning */ |
| 120 | tail = 0; |
| 121 | else { |
| 122 | /* No more room, tail hits data. We have to realign the |
| 123 | * whole message. */ |
| 124 | goto defrag; |
| 125 | } |
| 126 | } |
| 127 | else if (used >= wrap) { |
| 128 | /* We have hit the tail, we need to reorganize the blocks. */ |
| 129 | goto defrag; |
| 130 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 131 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 132 | /* Now we have updated tail, used and wrap, we know that there is some |
| 133 | * available room at least from the protocol's perspective. This space |
| 134 | * is split in two areas : |
| 135 | * |
| 136 | * 1: the space between the beginning of the blocks table and the |
| 137 | * front data's address. This space will only be used if data don't |
| 138 | * wrap yet. |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 139 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 140 | * 2: If the previous tail was the front block, the space between the |
| 141 | * beginning of the message and the head data's address. |
| 142 | * Otherwise, the space between the tail data's address and the |
| 143 | * tail's one. |
| 144 | */ |
| 145 | prevblk = htx_get_blk(htx, prev); |
| 146 | headblk = htx_get_blk(htx, head); |
| 147 | if (prevblk->addr >= headblk->addr) { |
| 148 | /* the area was contiguous */ |
| 149 | frtblk = htx_get_blk(htx, htx->front); |
| 150 | tailroom = sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, wrap) - (frtblk->addr + htx_get_blksz(frtblk)); |
| 151 | headroom = headblk->addr; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 152 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 153 | if (tailroom >= (int32_t)blksz) { |
| 154 | /* install upfront and update ->front */ |
| 155 | blk = htx_get_blk(htx, tail); |
| 156 | blk->addr = frtblk->addr + htx_get_blksz(frtblk); |
| 157 | htx->front = tail; |
| 158 | } |
| 159 | else if (headroom >= (int32_t)blksz) { |
| 160 | blk = htx_get_blk(htx, tail); |
| 161 | blk->addr = 0; |
| 162 | } |
| 163 | else { |
| 164 | /* need to defragment the table before inserting upfront */ |
| 165 | goto defrag; |
| 166 | } |
| 167 | } |
| 168 | else { |
| 169 | /* it's already wrapped so we can't store anything in the tailroom */ |
| 170 | headroom = headblk->addr - (prevblk->addr + htx_get_blksz(prevblk)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 171 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 172 | if (headroom >= (int32_t)blksz) { |
| 173 | blk = htx_get_blk(htx, tail); |
| 174 | blk->addr = prevblk->addr + htx_get_blksz(prevblk); |
| 175 | } |
| 176 | else { |
| 177 | defrag: |
| 178 | /* need to defragment the table before inserting upfront */ |
| 179 | htx_defrag(htx, NULL); |
| 180 | frtblk = htx_get_blk(htx, htx->front); |
| 181 | wrap = htx->wrap + 1; |
| 182 | tail = htx->tail + 1; |
| 183 | used = htx->used + 1; |
| 184 | blk = htx_get_blk(htx, tail); |
| 185 | blk->addr = frtblk->addr + htx_get_blksz(frtblk); |
| 186 | htx->front = tail; |
| 187 | } |
| 188 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 189 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 190 | htx->wrap = wrap; |
| 191 | htx->tail = tail; |
| 192 | htx->used = used; |
| 193 | htx->data += blksz; |
| 194 | return blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* Adds a new block of type <type> in the HTTP message <htx>. Its content size |
| 198 | * is passed but it is the caller responsibility to do the copy. |
| 199 | */ |
| 200 | struct htx_blk *htx_add_blk(struct htx *htx, enum htx_blk_type type, uint32_t blksz) |
| 201 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 202 | struct htx_blk *blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 203 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 204 | blk = htx_reserve_nxblk(htx, blksz); |
| 205 | if (!blk) |
| 206 | return NULL; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 207 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 208 | blk->info = (type << 28); |
| 209 | return blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /* Removes the block <blk> from the HTTP message <htx>. The function returns the |
| 213 | * block following <blk> or NULL if <blk> is the last block or the last |
| 214 | * inserted one. |
| 215 | */ |
| 216 | struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk) |
| 217 | { |
Christopher Faulet | 54483df | 2018-11-26 15:05:52 +0100 | [diff] [blame] | 218 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 219 | uint32_t next, head, pos; |
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 | if (type != HTX_BLK_UNUSED) { |
| 222 | /* Mark the block as unused, decrement allocated size */ |
| 223 | htx->data -= htx_get_blksz(blk); |
| 224 | blk->info = ((uint32_t)HTX_BLK_UNUSED << 28); |
Christopher Faulet | 54483df | 2018-11-26 15:05:52 +0100 | [diff] [blame] | 225 | if (htx->sl_off == blk->addr) |
| 226 | htx->sl_off = -1; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 227 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 228 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 229 | /* This is the last block in use */ |
| 230 | if (htx->used == 1/* || !htx->data */) { |
| 231 | htx->front = htx->tail = 0; |
| 232 | htx->wrap = htx->used = 0; |
| 233 | htx->data = 0; |
| 234 | return NULL; |
| 235 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 236 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 237 | /* There is at least 2 blocks, so tail is always >= 0 */ |
| 238 | pos = htx_get_blk_pos(htx, blk); |
| 239 | head = htx_get_head(htx); |
| 240 | blk = NULL; |
| 241 | next = pos + 1; /* By default retrun the next block */ |
| 242 | if (htx->tail + 1 == htx->wrap) { |
| 243 | /* The HTTP message doesn't wrap */ |
| 244 | if (pos == head) { |
| 245 | /* remove the head, so just return the new head */ |
| 246 | htx->used--; |
| 247 | next = htx_get_head(htx); |
| 248 | } |
| 249 | else if (pos == htx->tail) { |
| 250 | /* remove the tail. this was the last inserted block so |
| 251 | * return NULL. */ |
| 252 | htx->wrap--; |
| 253 | htx->tail--; |
| 254 | htx->used--; |
| 255 | goto end; |
| 256 | } |
| 257 | } |
| 258 | else { |
| 259 | /* The HTTP message wraps */ |
| 260 | if (pos == htx->tail) { |
| 261 | /* remove the tail. try to unwrap the message (pos == 0) |
| 262 | * and return NULL. */ |
| 263 | htx->tail = ((pos == 0) ? htx->wrap-1 : htx->tail-1); |
| 264 | htx->used--; |
| 265 | goto end; |
| 266 | } |
| 267 | else if (pos == head) { |
| 268 | /* remove the head, try to unwrap the message (pos+1 == |
| 269 | * wrap) and return the new head */ |
| 270 | htx->used--; |
| 271 | if (pos + 1 == htx->wrap) |
| 272 | htx->wrap = htx->tail + 1; |
| 273 | next = htx_get_head(htx); |
| 274 | } |
| 275 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 276 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 277 | blk = htx_get_blk(htx, next); |
Christopher Faulet | 54483df | 2018-11-26 15:05:52 +0100 | [diff] [blame] | 278 | if (htx->sl_off == -1) { |
| 279 | /* Try to update the start-line offset, if possible */ |
| 280 | type = htx_get_blk_type(blk); |
| 281 | if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) |
| 282 | htx->sl_off = blk->addr; |
| 283 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 284 | end: |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 285 | if (pos == htx->front) |
| 286 | htx->front = htx_find_front(htx); |
| 287 | return blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 288 | } |
| 289 | |
Christopher Faulet | 00cf697 | 2019-01-07 14:53:27 +0100 | [diff] [blame] | 290 | /* Truncate all blocks after the one containing the offset <offset>. This last |
| 291 | * one is truncated too. |
| 292 | */ |
| 293 | void htx_truncate(struct htx *htx, uint32_t offset) |
| 294 | { |
| 295 | struct htx_blk *blk; |
| 296 | struct htx_ret htxret; |
| 297 | |
| 298 | htxret = htx_find_blk(htx, offset); |
| 299 | blk = htxret.blk; |
| 300 | if (blk && htxret.ret) { |
| 301 | uint32_t sz = htx_get_blksz(blk); |
| 302 | |
| 303 | htx_set_blk_value_len(blk, sz - htxret.ret); |
| 304 | blk = htx_get_next_blk(htx, blk); |
| 305 | } |
| 306 | while (blk) |
| 307 | blk = htx_remove_blk(htx, blk); |
| 308 | } |
| 309 | |
Christopher Faulet | 549822f | 2019-02-25 10:23:19 +0100 | [diff] [blame] | 310 | /* Drain <count> bytes from the HTX message <htx>. DATA blocks will be cut if |
| 311 | * necessary. Others blocks will be removed at once if <count> is large |
| 312 | * enough. The function returns an htx_ret with the first block remaing in the |
| 313 | * messsage and the amount of data drained. If everything is removed, |
| 314 | * htx_ret.blk is set to NULL. |
| 315 | */ |
| 316 | struct htx_ret htx_drain(struct htx *htx, uint32_t count) |
| 317 | { |
| 318 | struct htx_blk *blk; |
| 319 | struct htx_ret htxret = { .blk = NULL, .ret = 0 }; |
| 320 | |
| 321 | blk = htx_get_head_blk(htx); |
| 322 | while (count && blk) { |
| 323 | uint32_t sz = htx_get_blksz(blk); |
| 324 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 325 | |
| 326 | /* Ingore unused block */ |
| 327 | if (type == HTX_BLK_UNUSED) |
| 328 | goto next; |
| 329 | |
| 330 | if (sz > count) { |
| 331 | if (type == HTX_BLK_DATA) { |
| 332 | htx_cut_data_blk(htx, blk, count); |
| 333 | htxret.ret += count; |
| 334 | } |
| 335 | break; |
| 336 | } |
| 337 | count -= sz; |
| 338 | htxret.ret += sz; |
| 339 | next: |
| 340 | blk = htx_remove_blk(htx, blk); |
| 341 | } |
| 342 | htxret.blk = blk; |
| 343 | |
| 344 | return htxret; |
| 345 | } |
| 346 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 347 | /* Tries to append data to the last inserted block, if the type matches and if |
| 348 | * there is enough non-wrapping space. Only DATA and TRAILERS content can be |
| 349 | * appended. If the append fails, a new block is inserted. If an error occurred, |
| 350 | * NULL is returned. Otherwise, on success, the updated block (or the new one) |
| 351 | * is returned. |
| 352 | */ |
| 353 | static struct htx_blk *htx_append_blk_value(struct htx *htx, enum htx_blk_type type, |
| 354 | const struct ist data) |
| 355 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 356 | struct htx_blk *blk; |
| 357 | struct ist v; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 358 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 359 | if (!htx->used) |
| 360 | goto add_new_block; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 361 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 362 | /* Not enough space to store data */ |
| 363 | if (data.len > htx_free_data_space(htx)) |
| 364 | return NULL; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 365 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 366 | /* Append only DATA et TRAILERS data */ |
| 367 | if (type != HTX_BLK_DATA && type != HTX_BLK_TLR) |
| 368 | goto add_new_block; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 369 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 370 | /* get the tail block */ |
| 371 | blk = htx_get_blk(htx, htx->tail); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 372 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 373 | /* Don't try to append data if the last inserted block is not of the |
| 374 | * same type */ |
| 375 | if (type != htx_get_blk_type(blk)) |
| 376 | goto add_new_block; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 377 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 378 | /* |
| 379 | * Same type and enough space: append data |
| 380 | */ |
| 381 | if (htx->tail + 1 == htx->wrap) { |
| 382 | struct htx_blk *frtblk = htx_get_blk(htx, htx->front); |
| 383 | int32_t tailroom = sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, htx->tail) - (frtblk->addr + htx_get_blksz(frtblk)); |
| 384 | if (tailroom >= (int32_t)data.len) |
| 385 | goto append_data; |
| 386 | htx_defrag(htx, NULL); |
| 387 | blk = htx_get_blk(htx, htx->tail); |
| 388 | } |
| 389 | else { |
| 390 | struct htx_blk *headblk = htx_get_blk(htx, htx_get_head(htx)); |
| 391 | int32_t headroom = headblk->addr - (blk->addr + htx_get_blksz(blk)); |
| 392 | if (headroom >= (int32_t)data.len) |
| 393 | goto append_data; |
| 394 | htx_defrag(htx, NULL); |
| 395 | blk = htx_get_blk(htx, htx->tail); |
| 396 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 397 | |
| 398 | append_data: |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 399 | /* get the value of the tail block */ |
| 400 | /* FIXME: check v.len + data.len < 256MB */ |
| 401 | v = htx_get_blk_value(htx, blk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 402 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 403 | /* Append data and update the block itself */ |
| 404 | memcpy(v.ptr + v.len, data.ptr, data.len); |
| 405 | htx_set_blk_value_len(blk, v.len + data.len); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 406 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 407 | /* Update HTTP message */ |
| 408 | htx->data += data.len; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 409 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 410 | return blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 411 | |
| 412 | add_new_block: |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 413 | /* FIXME: check tlr.len (< 256MB) */ |
| 414 | blk = htx_add_blk(htx, type, data.len); |
| 415 | if (!blk) |
| 416 | return NULL; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 417 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 418 | blk->info += data.len; |
| 419 | memcpy(htx_get_blk_ptr(htx, blk), data.ptr, data.len); |
| 420 | return blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /* Replaces a value part of a block by a new one. The new part can be smaller or |
| 424 | * larger than the old one. This function works for any kind of block with |
| 425 | * attached data. It returns the new block on success, otherwise it returns |
| 426 | * NULL. |
| 427 | */ |
| 428 | 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] | 429 | const struct ist old, const struct ist new) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 430 | { |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 431 | struct buffer *tmp; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 432 | struct ist n, v; |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 433 | int32_t delta; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 434 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 435 | n = htx_get_blk_name(htx, blk); |
| 436 | v = htx_get_blk_value(htx, blk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 437 | |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 438 | delta = new.len - old.len; |
| 439 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 440 | /* easy case, new data are smaller, so replace it in-place */ |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 441 | if (delta <= 0) { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 442 | memcpy(old.ptr, new.ptr, new.len); |
| 443 | if (old.len != v.len) |
| 444 | memmove(old.ptr + new.len, old.ptr + old.len, (v.ptr + v.len) - (old.ptr + old.len)); |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 445 | htx_set_blk_value_len(blk, v.len + delta); |
| 446 | htx->data += delta; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 447 | return blk; |
| 448 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 449 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 450 | /* we need to allocate more space to store the new header value */ |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 451 | if (delta > htx_free_space(htx)) |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 452 | return NULL; /* not enough space */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 453 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 454 | /* |
| 455 | * Copy the new header in a temp buffer |
| 456 | */ |
| 457 | tmp = get_trash_chunk(); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 458 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 459 | /* 1. copy the header name */ |
| 460 | chunk_memcat(tmp, n.ptr, n.len); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 461 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 462 | /* 2. copy value before old part, if any */ |
| 463 | if (old.ptr != v.ptr) |
| 464 | chunk_memcat(tmp, v.ptr, old.ptr - v.ptr); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 465 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 466 | /* 3. copy new value */ |
| 467 | chunk_memcat(tmp, new.ptr, new.len); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 468 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 469 | /* 4. copy value after old part if any */ |
| 470 | if (old.len != v.len) |
| 471 | chunk_memcat(tmp, old.ptr + old.len, (v.ptr + v.len) - (old.ptr + old.len)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 472 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 473 | |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 474 | /* Expand the block size. But data are not copied yet. Then defragment |
| 475 | * the HTX message. |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 476 | */ |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 477 | htx_set_blk_value_len(blk, v.len + delta); |
| 478 | htx->data += delta; |
| 479 | blk = htx_defrag(htx, blk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 480 | |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 481 | /* Finaly, copy data. */ |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 482 | memcpy(htx_get_blk_ptr(htx, blk), tmp->area, tmp->data); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 483 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 484 | return blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | /* Transfer HTX blocks from <src> to <dst>, stopping on the first block of the |
| 488 | * type <mark> (typically EOH, EOD or EOM) or when <count> bytes of data were |
| 489 | * moved. It returns the number of bytes of data moved and the last HTX block |
| 490 | * inserted in <dst>. |
| 491 | */ |
| 492 | struct htx_ret htx_xfer_blks(struct htx *dst, struct htx *src, uint32_t count, |
| 493 | enum htx_blk_type mark) |
| 494 | { |
| 495 | struct htx_blk *blk, *dstblk; |
| 496 | enum htx_blk_type type; |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 497 | uint32_t info, max, sz, ret; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 498 | |
| 499 | ret = 0; |
| 500 | blk = htx_get_blk(src, htx_get_head(src)); |
| 501 | dstblk = NULL; |
| 502 | while (blk && ret <= count) { |
| 503 | type = htx_get_blk_type(blk); |
| 504 | |
| 505 | /* Ingore unused block */ |
| 506 | if (type == HTX_BLK_UNUSED) |
| 507 | goto next; |
| 508 | |
| 509 | sz = htx_get_blksz(blk); |
| 510 | if (!sz) { |
| 511 | dstblk = htx_reserve_nxblk(dst, 0); |
| 512 | if (!dstblk) |
| 513 | break; |
| 514 | dstblk->info = blk->info; |
| 515 | goto next; |
| 516 | } |
| 517 | |
| 518 | info = blk->info; |
| 519 | max = htx_free_data_space(dst); |
| 520 | if (max > count) |
| 521 | max = count; |
Willy Tarreau | 2bf0c13 | 2019-02-21 15:06:30 +0100 | [diff] [blame] | 522 | if (ret + sz > max) { |
| 523 | sz = max - ret; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 524 | info = (type << 28) + sz; |
| 525 | /* Headers and pseudo headers must be fully copied */ |
| 526 | if (type < HTX_BLK_DATA || !sz) |
| 527 | break; |
| 528 | } |
| 529 | |
| 530 | dstblk = htx_reserve_nxblk(dst, sz); |
| 531 | if (!dstblk) |
| 532 | break; |
| 533 | dstblk->info = info; |
| 534 | memcpy(htx_get_blk_ptr(dst, dstblk), htx_get_blk_ptr(src, blk), sz); |
| 535 | |
| 536 | ret += sz; |
| 537 | if (blk->info != info) { |
| 538 | /* Partial move: don't remove <blk> from <src> but |
| 539 | * resize its content */ |
| 540 | blk->addr += sz; |
| 541 | htx_set_blk_value_len(blk, htx_get_blksz(blk) - sz); |
| 542 | src->data -= sz; |
| 543 | break; |
| 544 | } |
| 545 | |
Christopher Faulet | 54483df | 2018-11-26 15:05:52 +0100 | [diff] [blame] | 546 | if (dst->sl_off == -1 && src->sl_off == blk->addr) |
| 547 | dst->sl_off = dstblk->addr; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 548 | next: |
| 549 | blk = htx_remove_blk(src, blk); |
| 550 | if (type == mark) |
| 551 | break; |
| 552 | |
| 553 | } |
| 554 | |
| 555 | return (struct htx_ret){.ret = ret, .blk = dstblk}; |
| 556 | } |
| 557 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 558 | /* Replaces an header by a new one. The new header can be smaller or larger than |
| 559 | * the old one. It returns the new block on success, otherwise it returns NULL. |
Willy Tarreau | ed00e34 | 2018-12-07 08:47:45 +0100 | [diff] [blame] | 560 | * The header name is always lower cased. |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 561 | */ |
| 562 | 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] | 563 | const struct ist name, const struct ist value) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 564 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 565 | enum htx_blk_type type; |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 566 | int32_t delta; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 567 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 568 | type = htx_get_blk_type(blk); |
| 569 | if (type != HTX_BLK_HDR) |
| 570 | return NULL; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 571 | |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 572 | delta = name.len + value.len - htx_get_blksz(blk); |
| 573 | |
| 574 | /* easy case, new value is smaller, so replace it in-place */ |
| 575 | if (delta <= 0) { |
| 576 | blk->info = (type << 28) + (value.len << 8) + name.len; |
| 577 | htx->data += delta; |
| 578 | goto copy; |
| 579 | } |
| 580 | |
| 581 | /* we need to allocate more space to store the new value */ |
| 582 | if (delta > htx_free_space(htx)) |
| 583 | return NULL; /* not enough space */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 584 | |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 585 | /* Expand the block size. But data are not copied yet. Then defragment |
| 586 | * the HTX message. |
| 587 | */ |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 588 | blk->info = (type << 28) + (value.len << 8) + name.len; |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 589 | htx->data += delta; |
| 590 | blk = htx_defrag(htx, blk); |
| 591 | |
| 592 | copy: |
| 593 | /* Finaly, copy data. */ |
Willy Tarreau | ed00e34 | 2018-12-07 08:47:45 +0100 | [diff] [blame] | 594 | ist2bin_lc(htx_get_blk_ptr(htx, blk), name); |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 595 | memcpy(htx_get_blk_ptr(htx, blk) + name.len, value.ptr, value.len); |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 596 | return blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 597 | } |
| 598 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 599 | /* Replaces the parts of the start-line. It returns the new start-line on |
| 600 | * success, otherwise it returns NULL. It is the caller responsibility to update |
| 601 | * sl->info, if necessary. |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 602 | */ |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 603 | struct htx_sl *htx_replace_stline(struct htx *htx, struct htx_blk *blk, const struct ist p1, |
| 604 | const struct ist p2, const struct ist p3) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 605 | { |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 606 | struct htx_sl *sl; |
| 607 | struct htx_sl tmp; /* used to save sl->info and sl->flags */ |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 608 | enum htx_blk_type type; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 609 | uint32_t size; |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 610 | int32_t delta; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 611 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 612 | type = htx_get_blk_type(blk); |
Willy Tarreau | c706cd7 | 2018-12-07 17:12:22 +0100 | [diff] [blame] | 613 | if (type != HTX_BLK_REQ_SL && type != HTX_BLK_RES_SL) |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 614 | return NULL; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 615 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 616 | /* Save start-line info and flags */ |
| 617 | sl = htx_get_blk_ptr(htx, blk); |
| 618 | tmp.info = sl->info; |
| 619 | tmp.flags = sl->flags; |
Christopher Faulet | 54483df | 2018-11-26 15:05:52 +0100 | [diff] [blame] | 620 | if (htx->sl_off == blk->addr) |
| 621 | htx->sl_off = -1; |
| 622 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 623 | |
| 624 | size = sizeof(*sl) + p1.len + p2.len + p3.len; |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 625 | delta = size - htx_get_blksz(blk); |
| 626 | |
| 627 | /* easy case, new data are smaller, so replace it in-place */ |
| 628 | if (delta <= 0) { |
| 629 | htx_set_blk_value_len(blk, size); |
| 630 | htx->data += delta; |
| 631 | goto copy; |
| 632 | } |
| 633 | |
| 634 | /* we need to allocate more space to store the new value */ |
| 635 | if (delta > htx_free_space(htx)) |
| 636 | return NULL; /* not enough space */ |
| 637 | |
| 638 | /* Expand the block size. But data are not copied yet. Then defragment |
| 639 | * the HTX message. |
| 640 | */ |
| 641 | htx_set_blk_value_len(blk, size); |
| 642 | htx->data += delta; |
| 643 | blk = htx_defrag(htx, blk); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 644 | |
Christopher Faulet | e97f3ba | 2018-12-10 15:39:40 +0100 | [diff] [blame] | 645 | copy: |
| 646 | /* Restore start-line info and flags and copy parts of the start-line */ |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 647 | sl = htx_get_blk_ptr(htx, blk); |
| 648 | sl->info = tmp.info; |
| 649 | sl->flags = tmp.flags; |
| 650 | if (htx->sl_off == -1) |
| 651 | htx->sl_off = blk->addr; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 652 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 653 | HTX_SL_P1_LEN(sl) = p1.len; |
| 654 | HTX_SL_P2_LEN(sl) = p2.len; |
| 655 | HTX_SL_P3_LEN(sl) = p3.len; |
Christopher Faulet | 54483df | 2018-11-26 15:05:52 +0100 | [diff] [blame] | 656 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 657 | memcpy(HTX_SL_P1_PTR(sl), p1.ptr, p1.len); |
| 658 | memcpy(HTX_SL_P2_PTR(sl), p2.ptr, p2.len); |
| 659 | memcpy(HTX_SL_P3_PTR(sl), p3.ptr, p3.len); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 660 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 661 | return sl; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 662 | } |
| 663 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 664 | /* Add a new start-line. It returns it on success, otherwise it returns NULL. It |
| 665 | * is the caller responsibility to set sl->info, if necessary. |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 666 | */ |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 667 | struct htx_sl *htx_add_stline(struct htx *htx, enum htx_blk_type type, unsigned int flags, |
| 668 | const struct ist p1, const struct ist p2, const struct ist p3) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 669 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 670 | struct htx_blk *blk; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 671 | struct htx_sl *sl; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 672 | uint32_t size; |
| 673 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 674 | if (type != HTX_BLK_REQ_SL && type != HTX_BLK_RES_SL) |
| 675 | return NULL; |
| 676 | |
| 677 | size = sizeof(*sl) + p1.len + p2.len + p3.len; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 678 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 679 | /* FIXME: check size (< 256MB) */ |
| 680 | blk = htx_add_blk(htx, type, size); |
| 681 | if (!blk) |
| 682 | return NULL; |
| 683 | blk->info += size; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 684 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 685 | sl = htx_get_blk_ptr(htx, blk); |
| 686 | if (htx->sl_off == -1) |
| 687 | htx->sl_off = blk->addr; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 688 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 689 | sl->flags = flags; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 690 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 691 | HTX_SL_P1_LEN(sl) = p1.len; |
| 692 | HTX_SL_P2_LEN(sl) = p2.len; |
| 693 | HTX_SL_P3_LEN(sl) = p3.len; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 694 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 695 | memcpy(HTX_SL_P1_PTR(sl), p1.ptr, p1.len); |
| 696 | memcpy(HTX_SL_P2_PTR(sl), p2.ptr, p2.len); |
| 697 | memcpy(HTX_SL_P3_PTR(sl), p3.ptr, p3.len); |
| 698 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 699 | return sl; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | /* Adds an HTX block of type HDR in <htx>. It returns the new block on |
Willy Tarreau | ed00e34 | 2018-12-07 08:47:45 +0100 | [diff] [blame] | 703 | * success. Otherwise, it returns NULL. The header name is always lower cased. |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 704 | */ |
| 705 | struct htx_blk *htx_add_header(struct htx *htx, const struct ist name, |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 706 | const struct ist value) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 707 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 708 | struct htx_blk *blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 709 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 710 | /* FIXME: check name.len (< 256B) and value.len (< 1MB) */ |
| 711 | blk = htx_add_blk(htx, HTX_BLK_HDR, name.len + value.len); |
| 712 | if (!blk) |
| 713 | return NULL; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 714 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 715 | blk->info += (value.len << 8) + name.len; |
Willy Tarreau | ed00e34 | 2018-12-07 08:47:45 +0100 | [diff] [blame] | 716 | ist2bin_lc(htx_get_blk_ptr(htx, blk), name); |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 717 | memcpy(htx_get_blk_ptr(htx, blk) + name.len, value.ptr, value.len); |
| 718 | return blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 719 | } |
| 720 | |
Willy Tarreau | 52610e9 | 2019-01-03 18:26:17 +0100 | [diff] [blame] | 721 | /* Adds an HTX block of type <type> in <htx>, of size <blksz>. It returns the |
| 722 | * new block on success. Otherwise, it returns NULL. The caller is responsible |
| 723 | * for filling the block itself. |
| 724 | */ |
| 725 | struct htx_blk *htx_add_blk_type_size(struct htx *htx, enum htx_blk_type type, uint32_t blksz) |
| 726 | { |
| 727 | struct htx_blk *blk; |
| 728 | |
| 729 | blk = htx_add_blk(htx, type, blksz); |
| 730 | if (!blk) |
| 731 | return NULL; |
| 732 | |
| 733 | blk->info += blksz; |
| 734 | return blk; |
| 735 | } |
| 736 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 737 | struct htx_blk *htx_add_all_headers(struct htx *htx, const struct http_hdr *hdrs) |
| 738 | { |
| 739 | int i; |
| 740 | |
| 741 | for (i = 0; hdrs[i].n.len; i++) { |
| 742 | if (!htx_add_header(htx, hdrs[i].n, hdrs[i].v)) |
| 743 | return NULL; |
| 744 | } |
| 745 | return htx_add_endof(htx, HTX_BLK_EOH); |
| 746 | } |
| 747 | /* Adds an HTX block of type PHDR in <htx>. It returns the new block on |
| 748 | * success. Otherwise, it returns NULL. |
| 749 | */ |
| 750 | struct htx_blk *htx_add_pseudo_header(struct htx *htx, enum htx_phdr_type phdr, |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 751 | const struct ist value) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 752 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 753 | struct htx_blk *blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 754 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 755 | /* FIXME: check value.len ( < 1MB) */ |
| 756 | blk = htx_add_blk(htx, HTX_BLK_PHDR, value.len); |
| 757 | if (!blk) |
| 758 | return NULL; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 759 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 760 | blk->info += (value.len << 8) + phdr; |
| 761 | memcpy(htx_get_blk_ptr(htx, blk), value.ptr, value.len); |
| 762 | return blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | /* Adds an HTX block of type EOH,EOD or EOM in <htx>. It returns the new block |
| 766 | * on success. Otherwise, it returns NULL. |
| 767 | */ |
| 768 | struct htx_blk *htx_add_endof(struct htx *htx, enum htx_blk_type type) |
| 769 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 770 | struct htx_blk *blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 771 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 772 | blk = htx_add_blk(htx, type, 1); |
| 773 | if (!blk) |
| 774 | return NULL; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 775 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 776 | blk->info += 1; |
| 777 | return blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | |
| 781 | /* Adds an HTX block of type DATA in <htx>. It first tries to append data if |
| 782 | * possible. It returns the new block on success. Otherwise, it returns NULL. |
| 783 | */ |
| 784 | struct htx_blk *htx_add_data(struct htx *htx, const struct ist data) |
| 785 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 786 | return htx_append_blk_value(htx, HTX_BLK_DATA, data); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | /* Adds an HTX block of type TLR in <htx>. It first tries to append trailers |
| 790 | * data if possible. It returns the new block on success. Otherwise, it returns |
| 791 | * NULL. |
| 792 | */ |
| 793 | struct htx_blk *htx_add_trailer(struct htx *htx, const struct ist tlr) |
| 794 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 795 | return htx_append_blk_value(htx, HTX_BLK_TLR, tlr); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /* Adds an HTX block of type OOB in <htx>. It returns the new block on |
| 799 | * success. Otherwise, it returns NULL. |
| 800 | */ |
| 801 | struct htx_blk *htx_add_oob(struct htx *htx, const struct ist oob) |
| 802 | { |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 803 | struct htx_blk *blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 804 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 805 | /* FIXME: check oob.len (< 256MB) */ |
| 806 | blk = htx_add_blk(htx, HTX_BLK_OOB, oob.len); |
| 807 | if (!blk) |
| 808 | return NULL; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 809 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 810 | blk->info += oob.len; |
| 811 | memcpy(htx_get_blk_ptr(htx, blk), oob.ptr, oob.len); |
| 812 | return blk; |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 813 | } |
| 814 | |
Christopher Faulet | 24ed835 | 2018-11-22 11:20:43 +0100 | [diff] [blame] | 815 | struct htx_blk *htx_add_data_before(struct htx *htx, const struct htx_blk *ref, |
| 816 | const struct ist data) |
| 817 | { |
| 818 | struct htx_blk *blk; |
| 819 | int32_t prev; |
| 820 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 821 | /* FIXME: check data.len (< 256MB) */ |
| 822 | blk = htx_add_blk(htx, HTX_BLK_DATA, data.len); |
| 823 | if (!blk) |
| 824 | return NULL; |
Christopher Faulet | 24ed835 | 2018-11-22 11:20:43 +0100 | [diff] [blame] | 825 | |
Christopher Faulet | aa75b3d | 2018-12-05 16:20:40 +0100 | [diff] [blame] | 826 | blk->info += data.len; |
| 827 | memcpy(htx_get_blk_ptr(htx, blk), data.ptr, data.len); |
Christopher Faulet | 24ed835 | 2018-11-22 11:20:43 +0100 | [diff] [blame] | 828 | |
| 829 | for (prev = htx_get_prev(htx, htx->tail); prev != -1; prev = htx_get_prev(htx, prev)) { |
| 830 | struct htx_blk *pblk = htx_get_blk(htx, prev); |
| 831 | |
| 832 | /* Swap .addr and .info fields */ |
| 833 | blk->addr ^= pblk->addr; pblk->addr ^= blk->addr; blk->addr ^= pblk->addr; |
| 834 | blk->info ^= pblk->info; pblk->info ^= blk->info; blk->info ^= pblk->info; |
| 835 | |
| 836 | if (blk->addr == pblk->addr) |
| 837 | blk->addr += htx_get_blksz(pblk); |
| 838 | htx->front = prev; |
| 839 | |
| 840 | if (pblk == ref) |
| 841 | break; |
| 842 | blk = pblk; |
| 843 | } |
| 844 | return blk; |
| 845 | } |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 846 | |
Christopher Faulet | c59ff23 | 2018-12-03 13:58:44 +0100 | [diff] [blame] | 847 | /* Appends the H1 representation of the request line block <blk> to the |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 848 | * chunk <chk>. It returns 1 if data are successfully appended, otherwise it |
| 849 | * returns 0. |
| 850 | */ |
Christopher Faulet | c59ff23 | 2018-12-03 13:58:44 +0100 | [diff] [blame] | 851 | int htx_reqline_to_h1(const struct htx_sl *sl, struct buffer *chk) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 852 | { |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 853 | if (HTX_SL_LEN(sl) + 4 > b_room(chk)) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 854 | return 0; |
| 855 | |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 856 | chunk_memcat(chk, HTX_SL_REQ_MPTR(sl), HTX_SL_REQ_MLEN(sl)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 857 | chunk_memcat(chk, " ", 1); |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 858 | chunk_memcat(chk, HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 859 | chunk_memcat(chk, " ", 1); |
Christopher Faulet | 1e7af46 | 2018-12-03 14:05:01 +0100 | [diff] [blame] | 860 | if (sl->flags & HTX_SL_F_VER_11) |
| 861 | chunk_memcat(chk, "HTTP/1.1", 8); |
| 862 | else |
| 863 | chunk_memcat(chk, HTX_SL_REQ_VPTR(sl), HTX_SL_REQ_VLEN(sl)); |
| 864 | |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 865 | chunk_memcat(chk, "\r\n", 2); |
| 866 | |
| 867 | return 1; |
| 868 | } |
| 869 | |
Christopher Faulet | c59ff23 | 2018-12-03 13:58:44 +0100 | [diff] [blame] | 870 | /* Appends the H1 representation of the status line block <blk> to the chunk |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 871 | * <chk>. It returns 1 if data are successfully appended, otherwise it |
| 872 | * returns 0. |
| 873 | */ |
Christopher Faulet | c59ff23 | 2018-12-03 13:58:44 +0100 | [diff] [blame] | 874 | int htx_stline_to_h1(const struct htx_sl *sl, struct buffer *chk) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 875 | { |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 876 | if (HTX_SL_LEN(sl) + 4 > b_size(chk)) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 877 | return 0; |
| 878 | |
Christopher Faulet | 1e7af46 | 2018-12-03 14:05:01 +0100 | [diff] [blame] | 879 | if (sl->flags & HTX_SL_F_VER_11) |
| 880 | chunk_memcat(chk, "HTTP/1.1", 8); |
| 881 | else |
| 882 | chunk_memcat(chk, HTX_SL_RES_VPTR(sl), HTX_SL_RES_VLEN(sl)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 883 | chunk_memcat(chk, " ", 1); |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 884 | chunk_memcat(chk, HTX_SL_RES_CPTR(sl), HTX_SL_RES_CLEN(sl)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 885 | chunk_memcat(chk, " ", 1); |
Christopher Faulet | 570d161 | 2018-11-26 11:13:57 +0100 | [diff] [blame] | 886 | chunk_memcat(chk, HTX_SL_RES_RPTR(sl), HTX_SL_RES_RLEN(sl)); |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 887 | chunk_memcat(chk, "\r\n", 2); |
| 888 | |
| 889 | return 1; |
| 890 | } |
| 891 | |
Christopher Faulet | c59ff23 | 2018-12-03 13:58:44 +0100 | [diff] [blame] | 892 | /* Appends the H1 representation of the header block <blk> to the chunk |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 893 | * <chk>. It returns 1 if data are successfully appended, otherwise it returns |
| 894 | * 0. |
| 895 | */ |
Christopher Faulet | c59ff23 | 2018-12-03 13:58:44 +0100 | [diff] [blame] | 896 | int htx_hdr_to_h1(const struct ist n, const struct ist v, struct buffer *chk) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 897 | { |
| 898 | if (n.len + v.len + 4 > b_room(chk)) |
| 899 | return 0; |
| 900 | |
| 901 | chunk_memcat(chk, n.ptr, n.len); |
| 902 | chunk_memcat(chk, ": ", 2); |
| 903 | chunk_memcat(chk, v.ptr, v.len); |
| 904 | chunk_memcat(chk, "\r\n", 2); |
| 905 | |
| 906 | return 1; |
| 907 | } |
| 908 | |
Christopher Faulet | c59ff23 | 2018-12-03 13:58:44 +0100 | [diff] [blame] | 909 | /* Appends the H1 representation of the data block <blk> to the chunk |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 910 | * <chk>. If <chunked> is non-zero, it emits HTTP/1 chunk-encoded data. It |
| 911 | * returns 1 if data are successfully appended, otherwise it returns 0. |
| 912 | */ |
Christopher Faulet | c59ff23 | 2018-12-03 13:58:44 +0100 | [diff] [blame] | 913 | int htx_data_to_h1(const struct ist data, struct buffer *chk, int chunked) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 914 | { |
| 915 | if (chunked) { |
| 916 | uint32_t chksz; |
| 917 | char tmp[10]; |
| 918 | char *beg, *end; |
| 919 | |
| 920 | chksz = data.len; |
| 921 | |
| 922 | beg = end = tmp+10; |
| 923 | *--beg = '\n'; |
| 924 | *--beg = '\r'; |
| 925 | do { |
| 926 | *--beg = hextab[chksz & 0xF]; |
| 927 | } while (chksz >>= 4); |
| 928 | |
| 929 | if (data.len + (end - beg) + 2 > b_room(chk)) |
| 930 | return 0; |
| 931 | chunk_memcat(chk, beg, end - beg); |
| 932 | chunk_memcat(chk, data.ptr, data.len); |
| 933 | chunk_memcat(chk, "\r\n", 2); |
| 934 | } |
| 935 | else { |
| 936 | if (!chunk_memcat(chk, data.ptr, data.len)) |
| 937 | return 0; |
| 938 | } |
| 939 | |
| 940 | return 1; |
| 941 | } |
| 942 | |
Christopher Faulet | c59ff23 | 2018-12-03 13:58:44 +0100 | [diff] [blame] | 943 | /* Appends the h1 representation of the trailer block <blk> to the chunk |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 944 | * <chk>. It returns 1 if data are successfully appended, otherwise it returns |
| 945 | * 0. |
| 946 | */ |
Christopher Faulet | c59ff23 | 2018-12-03 13:58:44 +0100 | [diff] [blame] | 947 | int htx_trailer_to_h1(const struct ist tlr, struct buffer *chk) |
Christopher Faulet | a3d2a16 | 2018-10-22 08:59:39 +0200 | [diff] [blame] | 948 | { |
| 949 | /* FIXME: be sure the CRLF is here or remove it when inserted */ |
| 950 | if (!chunk_memcat(chk, tlr.ptr, tlr.len)) |
| 951 | return 0; |
| 952 | return 1; |
| 953 | } |