From aa75b3d2d54dee48b0ad70f5f810dcc281003355 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 5 Dec 2018 16:20:40 +0100 Subject: [PATCH] CLEANUP: htx: Fix indentation here and there in HTX files --- include/proto/htx.h | 372 ++++++++++----------- src/http_htx.c | 10 +- src/htx.c | 796 ++++++++++++++++++++++---------------------- src/mux_h1.c | 28 +- 4 files changed, 603 insertions(+), 603 deletions(-) diff --git a/include/proto/htx.h b/include/proto/htx.h index d803947cd..3fd8fbab1 100644 --- a/include/proto/htx.h +++ b/include/proto/htx.h @@ -35,7 +35,7 @@ struct htx_blk *htx_add_blk(struct htx *htx, enum htx_blk_type type, uint32_t bl struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk); struct htx_blk *htx_replace_blk_value(struct htx *htx, struct htx_blk *blk, - const struct ist old, const struct ist new); + const struct ist old, const struct ist new); struct htx_ret htx_xfer_blks(struct htx *dst, struct htx *src, uint32_t count, enum htx_blk_type mark); @@ -45,7 +45,7 @@ struct htx_sl *htx_replace_stline(struct htx *htx, struct htx_blk *blk, const st const struct ist p2, const struct ist p3); struct htx_blk *htx_replace_header(struct htx *htx, struct htx_blk *blk, - const struct ist name, const struct ist value); + const struct ist name, const struct ist value); struct htx_blk *htx_add_header(struct htx *htx, const struct ist name, const struct ist value); struct htx_blk *htx_add_all_headers(struct htx *htx, const struct http_hdr *hdrs); @@ -88,10 +88,10 @@ int htx_trailer_to_h1(const struct ist tlr, struct buffer *chk); #define HTX_SL_RES_CPTR(sl) HTX_SL_P2_PTR(sl) #define HTX_SL_RES_RPTR(sl) HTX_SL_P3_PTR(sl) -static inline const struct ist htx_sl_p1(const struct htx_sl *sl) -{ - return ist2(HTX_SL_P1_PTR(sl), HTX_SL_P1_LEN(sl)); -} + static inline const struct ist htx_sl_p1(const struct htx_sl *sl) + { + return ist2(HTX_SL_P1_PTR(sl), HTX_SL_P1_LEN(sl)); + } static inline const struct ist htx_sl_p2(const struct htx_sl *sl) { @@ -149,25 +149,25 @@ static inline struct htx_sl *htx_get_stline(struct htx *htx) /* Returns the array index of a block given its position */ static inline uint32_t htx_pos_to_idx(const struct htx *htx, uint32_t pos) { - return ((htx->size / sizeof(htx->blocks[0])) - pos - 1); + return ((htx->size / sizeof(htx->blocks[0])) - pos - 1); } /* Returns the position of the block */ static inline uint32_t htx_get_blk_pos(const struct htx *htx, const struct htx_blk *blk) { - return (htx->blocks + (htx->size / sizeof(htx->blocks[0])) - blk - 1); + return (htx->blocks + (htx->size / sizeof(htx->blocks[0])) - blk - 1); } /* Returns the block at the position */ static inline struct htx_blk *htx_get_blk(const struct htx *htx, uint32_t pos) { - return ((struct htx_blk *)(htx->blocks) + htx_pos_to_idx(htx, pos)); + return ((struct htx_blk *)(htx->blocks) + htx_pos_to_idx(htx, pos)); } /* Returns the type of the block */ static inline enum htx_blk_type htx_get_blk_type(const struct htx_blk *blk) { - return (blk->info >> 28); + return (blk->info >> 28); } /* Returns the pseudo-header type of the block . If it's not a @@ -175,36 +175,36 @@ static inline enum htx_blk_type htx_get_blk_type(const struct htx_blk *blk) */ static inline enum htx_phdr_type htx_get_blk_phdr(const struct htx_blk *blk) { - enum htx_blk_type type = htx_get_blk_type(blk); - enum htx_phdr_type phdr; + enum htx_blk_type type = htx_get_blk_type(blk); + enum htx_phdr_type phdr; - switch (type) { - case HTX_BLK_PHDR: - phdr = (blk->info & 0xff); - return phdr; + switch (type) { + case HTX_BLK_PHDR: + phdr = (blk->info & 0xff); + return phdr; - default: - /* Not a pseudo-header */ - return HTX_PHDR_UNKNOWN; - } + default: + /* Not a pseudo-header */ + return HTX_PHDR_UNKNOWN; + } } /* Returns the size of the block , depending of its type */ static inline uint32_t htx_get_blksz(const struct htx_blk *blk) { - enum htx_blk_type type = htx_get_blk_type(blk); + enum htx_blk_type type = htx_get_blk_type(blk); - switch (type) { - case HTX_BLK_HDR: - /* name.length + value.length */ - return ((blk->info & 0xff) + ((blk->info >> 8) & 0xfffff)); - case HTX_BLK_PHDR: - /* value.length */ - return ((blk->info >> 8) & 0xfffff); - default: - /* value.length */ - return (blk->info & 0xfffffff); - } + switch (type) { + case HTX_BLK_HDR: + /* name.length + value.length */ + return ((blk->info & 0xff) + ((blk->info >> 8) & 0xfffff)); + case HTX_BLK_PHDR: + /* value.length */ + return ((blk->info >> 8) & 0xfffff); + default: + /* value.length */ + return (blk->info & 0xfffffff); + } } /* Returns the position of the oldest entry (head). @@ -215,15 +215,15 @@ static inline uint32_t htx_get_blksz(const struct htx_blk *blk) */ static inline int32_t htx_get_head(const struct htx *htx) { - if (!htx->used) - return -1; + if (!htx->used) + return -1; - return (((htx->tail + 1U < htx->used) ? htx->wrap : 0) + htx->tail + 1U - htx->used); + return (((htx->tail + 1U < htx->used) ? htx->wrap : 0) + htx->tail + 1U - htx->used); } /* Returns the oldest HTX block (head) if the HTX message is not * empty. Otherwise it returns NULL. -*/ + */ static inline struct htx_blk *htx_get_head_blk(const struct htx *htx) { int32_t head = htx_get_head(htx); @@ -249,12 +249,12 @@ static inline enum htx_blk_type htx_get_head_type(const struct htx *htx) */ static inline int32_t htx_get_tail(const struct htx *htx) { - return (htx->used ? htx->tail : -1); + return (htx->used ? htx->tail : -1); } /* Returns the newest HTX block (tail) if the HTX message is not * empty. Otherwise it returns NULL. -*/ + */ static inline struct htx_blk *htx_get_tail_blk(const struct htx *htx) { int32_t tail = htx_get_tail(htx); @@ -281,19 +281,19 @@ static inline enum htx_blk_type htx_get_tail_type(const struct htx *htx) */ static inline int32_t htx_get_prev(const struct htx *htx, uint32_t pos) { - int32_t head; + int32_t head; - head = htx_get_head(htx); - if (head == -1 || pos == head) - return -1; - if (!pos) - return (htx->wrap - 1); - return (pos - 1); + head = htx_get_head(htx); + if (head == -1 || pos == head) + return -1; + if (!pos) + return (htx->wrap - 1); + return (pos - 1); } /* Returns the HTX block before in the HTX message . If is the * head, NULL returned. -*/ + */ static inline struct htx_blk *htx_get_prev_blk(const struct htx *htx, const struct htx_blk *blk) { @@ -312,21 +312,21 @@ static inline struct htx_blk *htx_get_prev_blk(const struct htx *htx, */ static inline int32_t htx_get_next(const struct htx *htx, uint32_t pos) { - if (!htx->used) - return -1; + if (!htx->used) + return -1; - if (pos == htx->tail) - return -1; - pos++; - if (pos >= htx->wrap) - pos = 0; - return pos; + if (pos == htx->tail) + return -1; + pos++; + if (pos >= htx->wrap) + pos = 0; + return pos; } /* Returns the HTX block after in the HTX message . If is the * tail, NULL returned. -*/ + */ static inline struct htx_blk *htx_get_next_blk(const struct htx *htx, const struct htx_blk *blk) { @@ -338,24 +338,24 @@ static inline struct htx_blk *htx_get_next_blk(const struct htx *htx, static inline int32_t htx_find_front(const struct htx *htx) { - int32_t front, pos; - uint32_t addr = 0; + int32_t front, pos; + uint32_t addr = 0; - if (!htx->used) - return -1; + if (!htx->used) + return -1; - front = -1; - for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) { - struct htx_blk *blk = htx_get_blk(htx, pos); - enum htx_blk_type type = htx_get_blk_type(blk); + front = -1; + for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) { + struct htx_blk *blk = htx_get_blk(htx, pos); + enum htx_blk_type type = htx_get_blk_type(blk); - if (type != HTX_BLK_UNUSED && blk->addr >= addr) { - front = pos; - addr = blk->addr; - } - } + if (type != HTX_BLK_UNUSED && blk->addr >= addr) { + front = pos; + addr = blk->addr; + } + } - return front; + return front; } /* Returns the HTX block containing data with the , relatively to the @@ -383,24 +383,24 @@ static inline struct htx_ret htx_find_blk(const struct htx *htx, uint32_t offset */ static inline void htx_set_blk_value_len(struct htx_blk *blk, uint32_t vlen) { - enum htx_blk_type type = htx_get_blk_type(blk); + enum htx_blk_type type = htx_get_blk_type(blk); - switch (type) { - case HTX_BLK_HDR: - case HTX_BLK_PHDR: - blk->info = (type << 28) + (vlen << 8) + (blk->info & 0xff); - break; - case HTX_BLK_REQ_SL: - case HTX_BLK_RES_SL: - case HTX_BLK_DATA: - case HTX_BLK_TLR: - case HTX_BLK_OOB: - blk->info = (type << 28) + vlen; - break; - default: - /* Unexpected case */ - break; - } + switch (type) { + case HTX_BLK_HDR: + case HTX_BLK_PHDR: + blk->info = (type << 28) + (vlen << 8) + (blk->info & 0xff); + break; + case HTX_BLK_REQ_SL: + case HTX_BLK_RES_SL: + case HTX_BLK_DATA: + case HTX_BLK_TLR: + case HTX_BLK_OOB: + blk->info = (type << 28) + vlen; + break; + default: + /* Unexpected case */ + break; + } } /* Returns the data pointer of the block */ @@ -414,19 +414,19 @@ static inline void *htx_get_blk_ptr(const struct htx *htx, const struct htx_blk */ static inline struct ist htx_get_blk_name(const struct htx *htx, const struct htx_blk *blk) { - enum htx_blk_type type = htx_get_blk_type(blk); - struct ist ret; + enum htx_blk_type type = htx_get_blk_type(blk); + struct ist ret; - switch (type) { - case HTX_BLK_HDR: - ret.ptr = htx_get_blk_ptr(htx, blk); - ret.len = blk->info & 0xff; - break; + switch (type) { + case HTX_BLK_HDR: + ret.ptr = htx_get_blk_ptr(htx, blk); + ret.len = blk->info & 0xff; + break; - default: - return ist(""); - } - return ret; + default: + return ist(""); + } + return ret; } @@ -435,33 +435,33 @@ static inline struct ist htx_get_blk_name(const struct htx *htx, const struct ht */ static inline struct ist htx_get_blk_value(const struct htx *htx, const struct htx_blk *blk) { - enum htx_blk_type type = htx_get_blk_type(blk); - struct ist ret; + enum htx_blk_type type = htx_get_blk_type(blk); + struct ist ret; - switch (type) { - case HTX_BLK_HDR: - ret.ptr = htx_get_blk_ptr(htx, blk) + (blk->info & 0xff); - ret.len = (blk->info >> 8) & 0xfffff; - break; + switch (type) { + case HTX_BLK_HDR: + ret.ptr = htx_get_blk_ptr(htx, blk) + (blk->info & 0xff); + ret.len = (blk->info >> 8) & 0xfffff; + break; - case HTX_BLK_PHDR: - ret.ptr = htx_get_blk_ptr(htx, blk); - ret.len = (blk->info >> 8) & 0xfffff; - break; + case HTX_BLK_PHDR: + ret.ptr = htx_get_blk_ptr(htx, blk); + ret.len = (blk->info >> 8) & 0xfffff; + break; - case HTX_BLK_REQ_SL: - case HTX_BLK_RES_SL: - case HTX_BLK_DATA: - case HTX_BLK_TLR: - case HTX_BLK_OOB: - ret.ptr = htx_get_blk_ptr(htx, blk); - ret.len = blk->info & 0xfffffff; - break; + case HTX_BLK_REQ_SL: + case HTX_BLK_RES_SL: + case HTX_BLK_DATA: + case HTX_BLK_TLR: + case HTX_BLK_OOB: + ret.ptr = htx_get_blk_ptr(htx, blk); + ret.len = blk->info & 0xfffffff; + break; - default: - return ist(""); - } - return ret; + default: + return ist(""); + } + return ret; } /* Removes bytes from the beginning of DATA block . The block's start @@ -481,19 +481,19 @@ static inline void htx_cut_data_blk(struct htx *htx, struct htx_blk *blk, uint32 /* Returns the space used by metadata in . */ static inline uint32_t htx_meta_space(const struct htx *htx) { - return (htx->used * sizeof(htx->blocks[0])); + return (htx->used * sizeof(htx->blocks[0])); } /* Returns the space used (data + metadata) in */ static inline uint32_t htx_used_space(const struct htx *htx) { - return (htx->data + htx_meta_space(htx)); + return (htx->data + htx_meta_space(htx)); } /* Returns the free space in */ static inline uint32_t htx_free_space(const struct htx *htx) { - return (htx->size - htx_used_space(htx)); + return (htx->size - htx_used_space(htx)); } /* Returns the maximum size available to store some data in if a new block @@ -501,24 +501,24 @@ static inline uint32_t htx_free_space(const struct htx *htx) */ static inline uint32_t htx_free_data_space(const struct htx *htx) { - uint32_t free = htx_free_space(htx); + uint32_t free = htx_free_space(htx); - if (free < sizeof(htx->blocks[0])) - return 0; - return (free - sizeof(htx->blocks[0])); + if (free < sizeof(htx->blocks[0])) + return 0; + return (free - sizeof(htx->blocks[0])); } /* Returns 1 if the message has less than 1/4 of its capacity free, otherwise 0 */ static inline int htx_almost_full(const struct htx *htx) { - if (!htx->size || htx_free_space(htx) < htx->size / 4) - return 1; - return 0; + if (!htx->size || htx_free_space(htx) < htx->size / 4) + return 1; + return 0; } static inline void htx_reset(struct htx *htx) { - htx->data = htx->used = htx->tail = htx->wrap = htx->front = 0; + htx->data = htx->used = htx->tail = htx->wrap = htx->front = 0; htx->extra = 0; htx->flags = HTX_FL_NONE; htx->sl_off = -1; @@ -587,88 +587,88 @@ static inline void htx_to_buf(struct htx *htx, struct buffer *buf) /* Returns 1 if the message is empty, otherwise it returns 0. */ static inline int htx_is_empty(const struct htx *htx) { - return (!htx || !htx->used); + return (!htx || !htx->used); } /* Returns 1 if the message is not empty, otherwise it returns 0. */ static inline int htx_is_not_empty(const struct htx *htx) { - return (htx && htx->used); + return (htx && htx->used); } /* For debugging purpose */ static inline const char *htx_blk_type_str(enum htx_blk_type type) { - switch (type) { - case HTX_BLK_REQ_SL: return "HTX_BLK_REQ_SL"; - case HTX_BLK_RES_SL: return "HTX_BLK_RES_SL"; - case HTX_BLK_HDR: return "HTX_BLK_HDR"; - case HTX_BLK_PHDR: return "HTX_BLK_PHDR"; - case HTX_BLK_EOH: return "HTX_BLK_EOH"; - case HTX_BLK_DATA: return "HTX_BLK_DATA"; - case HTX_BLK_EOD: return "HTX_BLK_EOD"; - case HTX_BLK_TLR: return "HTX_BLK_TLR"; - case HTX_BLK_EOM: return "HTX_BLK_EOM"; - case HTX_BLK_OOB: return "HTX_BLK_OOB"; - case HTX_BLK_UNUSED: return "HTX_BLK_UNUSED"; - default: return "HTX_BLK_???"; - }; + switch (type) { + case HTX_BLK_REQ_SL: return "HTX_BLK_REQ_SL"; + case HTX_BLK_RES_SL: return "HTX_BLK_RES_SL"; + case HTX_BLK_HDR: return "HTX_BLK_HDR"; + case HTX_BLK_PHDR: return "HTX_BLK_PHDR"; + case HTX_BLK_EOH: return "HTX_BLK_EOH"; + case HTX_BLK_DATA: return "HTX_BLK_DATA"; + case HTX_BLK_EOD: return "HTX_BLK_EOD"; + case HTX_BLK_TLR: return "HTX_BLK_TLR"; + case HTX_BLK_EOM: return "HTX_BLK_EOM"; + case HTX_BLK_OOB: return "HTX_BLK_OOB"; + case HTX_BLK_UNUSED: return "HTX_BLK_UNUSED"; + default: return "HTX_BLK_???"; + }; } static inline const char *htx_blk_phdr_str(enum htx_phdr_type phdr) { - switch (phdr) { - case HTX_PHDR_UNKNOWN: return "HTX_PHDR_UNKNOWN"; - default: return "HTX_PHDR_???"; - } + switch (phdr) { + case HTX_PHDR_UNKNOWN: return "HTX_PHDR_UNKNOWN"; + default: return "HTX_PHDR_???"; + } } static inline void htx_dump(struct htx *htx) { - int32_t pos; + int32_t pos; - fprintf(stderr, "htx:%p [ size=%u - data=%u - used=%u - wrap=%s - extra=%llu]\n", - htx, htx->size, htx->data, htx->used, - (!htx->used || htx->tail+1 == htx->wrap) ? "NO" : "YES", + fprintf(stderr, "htx:%p [ size=%u - data=%u - used=%u - wrap=%s - extra=%llu]\n", + htx, htx->size, htx->data, htx->used, + (!htx->used || htx->tail+1 == htx->wrap) ? "NO" : "YES", (unsigned long long)htx->extra); - fprintf(stderr, "\thead=%d - tail=%u - front=%u - wrap=%u\n", - htx_get_head(htx), htx->tail, htx->front, htx->wrap); + fprintf(stderr, "\thead=%d - tail=%u - front=%u - wrap=%u\n", + htx_get_head(htx), htx->tail, htx->front, htx->wrap); - for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) { + for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) { struct htx_sl *sl; - struct htx_blk *blk = htx_get_blk(htx, pos); - enum htx_blk_type type = htx_get_blk_type(blk); - enum htx_phdr_type phdr = htx_get_blk_phdr(blk); - uint32_t sz = htx_get_blksz(blk); - struct ist n, v; + struct htx_blk *blk = htx_get_blk(htx, pos); + enum htx_blk_type type = htx_get_blk_type(blk); + enum htx_phdr_type phdr = htx_get_blk_phdr(blk); + uint32_t sz = htx_get_blksz(blk); + struct ist n, v; - n = htx_get_blk_name(htx, blk); - v = htx_get_blk_value(htx, blk); + n = htx_get_blk_name(htx, blk); + v = htx_get_blk_value(htx, blk); - if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) { + if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) { sl = htx_get_blk_ptr(htx, blk); - fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s %.*s %.*s\n", - pos, htx_blk_type_str(type), sz, blk->addr, - HTX_SL_P1_LEN(sl), HTX_SL_P1_PTR(sl), - HTX_SL_P2_LEN(sl), HTX_SL_P2_PTR(sl), - HTX_SL_P3_LEN(sl), HTX_SL_P3_PTR(sl)); + fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s %.*s %.*s\n", + pos, htx_blk_type_str(type), sz, blk->addr, + HTX_SL_P1_LEN(sl), HTX_SL_P1_PTR(sl), + HTX_SL_P2_LEN(sl), HTX_SL_P2_PTR(sl), + HTX_SL_P3_LEN(sl), HTX_SL_P3_PTR(sl)); } - else if (type == HTX_BLK_HDR) - fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s: %.*s\n", - pos, htx_blk_type_str(type), sz, blk->addr, - (int)n.len, n.ptr, - (int)v.len, v.ptr); + else if (type == HTX_BLK_HDR) + fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s: %.*s\n", + pos, htx_blk_type_str(type), sz, blk->addr, + (int)n.len, n.ptr, + (int)v.len, v.ptr); - else if (type == HTX_BLK_PHDR) - fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s\n", - pos, htx_blk_phdr_str(phdr), sz, blk->addr, - (int)v.len, v.ptr); - else - fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u%s\n", - pos, htx_blk_type_str(type), sz, blk->addr, - (!v.len ? "\t" : "")); - } - fprintf(stderr, "\n"); + else if (type == HTX_BLK_PHDR) + fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s\n", + pos, htx_blk_phdr_str(phdr), sz, blk->addr, + (int)v.len, v.ptr); + else + fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u%s\n", + pos, htx_blk_type_str(type), sz, blk->addr, + (!v.len ? "\t" : "")); + } + fprintf(stderr, "\n"); } #endif /* _PROTO_HTX_H */ diff --git a/src/http_htx.c b/src/http_htx.c index 9a1dfb469..83768f6fb 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -34,9 +34,9 @@ struct htx_sl *http_find_stline(struct htx *htx) if (sl) return sl; - for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) { - struct htx_blk *blk = htx_get_blk(htx, pos); - enum htx_blk_type type = htx_get_blk_type(blk); + for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) { + struct htx_blk *blk = htx_get_blk(htx, pos); + enum htx_blk_type type = htx_get_blk_type(blk); if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) { sl = htx_get_blk_ptr(htx, blk); @@ -194,9 +194,9 @@ int http_replace_stline(struct htx *htx, const struct ist p1, const struct ist p { int32_t pos; - for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) { + for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) { struct htx_blk *blk = htx_get_blk(htx, pos); - enum htx_blk_type type = htx_get_blk_type(blk); + enum htx_blk_type type = htx_get_blk_type(blk); if (htx->sl_off == blk->addr) { if (!htx_replace_stline(htx, blk, p1, p2, p3)) diff --git a/src/htx.c b/src/htx.c index d691c2e58..1f0ebebc9 100644 --- a/src/htx.c +++ b/src/htx.c @@ -23,50 +23,50 @@ struct htx htx_empty = { .size = 0, .data = 0, .used = 0 }; /* TODO: merge data blocks into one */ struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk) { - struct buffer *chunk = get_trash_chunk(); - struct htx *tmp = htxbuf(chunk); - struct htx_blk *newblk, *oldblk; - uint32_t new, old; - uint32_t addr, blksz; + struct buffer *chunk = get_trash_chunk(); + struct htx *tmp = htxbuf(chunk); + struct htx_blk *newblk, *oldblk; + uint32_t new, old; + uint32_t addr, blksz; - if (!htx->used) - return NULL; + if (!htx->used) + return NULL; - new = 0; - addr = 0; - tmp->size = htx->size; + new = 0; + addr = 0; + tmp->size = htx->size; - /* start from the head */ - for (old = htx_get_head(htx); old != -1; old = htx_get_next(htx, old)) { - oldblk = htx_get_blk(htx, old); - if (htx_get_blk_type(oldblk) == HTX_BLK_UNUSED) { - htx->used--; - continue; - } + /* start from the head */ + for (old = htx_get_head(htx); old != -1; old = htx_get_next(htx, old)) { + oldblk = htx_get_blk(htx, old); + if (htx_get_blk_type(oldblk) == HTX_BLK_UNUSED) { + htx->used--; + continue; + } - newblk = htx_get_blk(tmp, new); - newblk->addr = addr; - newblk->info = oldblk->info; - blksz = htx_get_blksz(oldblk); + newblk = htx_get_blk(tmp, new); + newblk->addr = addr; + newblk->info = oldblk->info; + blksz = htx_get_blksz(oldblk); - memcpy((void *)tmp->blocks + addr, htx_get_blk_ptr(htx, oldblk), blksz); - new++; - addr += blksz; + memcpy((void *)tmp->blocks + addr, htx_get_blk_ptr(htx, oldblk), blksz); + new++; + addr += blksz; /* update the start-line offset */ if (htx->sl_off == oldblk->addr) htx->sl_off = addr; - /* if is defined, set its new location */ - if (blk != NULL && blk == oldblk) - blk = newblk; - } while (new < htx->used); + /* if is defined, set its new location */ + if (blk != NULL && blk == oldblk) + blk = newblk; + } while (new < htx->used); - htx->wrap = htx->used; - htx->front = htx->tail = new - 1; - memcpy((void *)htx->blocks, (void *)tmp->blocks, htx->size); + htx->wrap = htx->used; + htx->front = htx->tail = new - 1; + memcpy((void *)htx->blocks, (void *)tmp->blocks, htx->size); - return blk; + return blk; } /* Reserves a new block in the HTTP message with a content of @@ -77,116 +77,116 @@ struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk) */ static struct htx_blk *htx_reserve_nxblk(struct htx *htx, uint32_t blksz) { - struct htx_blk *blk, *prevblk, *headblk, *frtblk; - uint32_t used; - uint32_t tail; - uint32_t prev; - uint32_t wrap; - uint32_t head; - int32_t headroom, tailroom; + struct htx_blk *blk, *prevblk, *headblk, *frtblk; + uint32_t used; + uint32_t tail; + uint32_t prev; + uint32_t wrap; + uint32_t head; + int32_t headroom, tailroom; - if (blksz > htx_free_data_space(htx)) - return NULL; /* full */ + if (blksz > htx_free_data_space(htx)) + return NULL; /* full */ - if (!htx->used) { - /* Empty message */ - htx->front = htx->tail = 0; - htx->wrap = htx->used = 1; - blk = htx_get_blk(htx, htx->tail); - blk->addr = 0; - htx->data = blksz; - return blk; - } + if (!htx->used) { + /* Empty message */ + htx->front = htx->tail = 0; + htx->wrap = htx->used = 1; + blk = htx_get_blk(htx, htx->tail); + blk->addr = 0; + htx->data = blksz; + return blk; + } - used = htx->used + 1; - tail = htx->tail + 1; - prev = htx->tail; - wrap = htx->wrap; - head = htx_get_head(htx); + used = htx->used + 1; + tail = htx->tail + 1; + prev = htx->tail; + wrap = htx->wrap; + head = htx_get_head(htx); - if (tail == wrap) { - frtblk = htx_get_blk(htx, htx->front); + if (tail == wrap) { + frtblk = htx_get_blk(htx, htx->front); - /* Blocks don't wrap for now. We either need to push the new one - * on top of others or to defragement the table. */ - if (sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, wrap+1) >= frtblk->addr + htx_get_blksz(frtblk)) - wrap++; - else if (tail >= used) /* There is hole at the beginning */ - tail = 0; - else { - /* No more room, tail hits data. We have to realign the - * whole message. */ - goto defrag; - } - } - else if (used >= wrap) { - /* We have hit the tail, we need to reorganize the blocks. */ - goto defrag; - } + /* Blocks don't wrap for now. We either need to push the new one + * on top of others or to defragement the table. */ + if (sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, wrap+1) >= frtblk->addr + htx_get_blksz(frtblk)) + wrap++; + else if (tail >= used) /* There is hole at the beginning */ + tail = 0; + else { + /* No more room, tail hits data. We have to realign the + * whole message. */ + goto defrag; + } + } + else if (used >= wrap) { + /* We have hit the tail, we need to reorganize the blocks. */ + goto defrag; + } - /* Now we have updated tail, used and wrap, we know that there is some - * available room at least from the protocol's perspective. This space - * is split in two areas : - * - * 1: the space between the beginning of the blocks table and the - * front data's address. This space will only be used if data don't - * wrap yet. + /* Now we have updated tail, used and wrap, we know that there is some + * available room at least from the protocol's perspective. This space + * is split in two areas : + * + * 1: the space between the beginning of the blocks table and the + * front data's address. This space will only be used if data don't + * wrap yet. - * 2: If the previous tail was the front block, the space between the - * beginning of the message and the head data's address. - * Otherwise, the space between the tail data's address and the - * tail's one. - */ - prevblk = htx_get_blk(htx, prev); - headblk = htx_get_blk(htx, head); - if (prevblk->addr >= headblk->addr) { - /* the area was contiguous */ - frtblk = htx_get_blk(htx, htx->front); - tailroom = sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, wrap) - (frtblk->addr + htx_get_blksz(frtblk)); - headroom = headblk->addr; + * 2: If the previous tail was the front block, the space between the + * beginning of the message and the head data's address. + * Otherwise, the space between the tail data's address and the + * tail's one. + */ + prevblk = htx_get_blk(htx, prev); + headblk = htx_get_blk(htx, head); + if (prevblk->addr >= headblk->addr) { + /* the area was contiguous */ + frtblk = htx_get_blk(htx, htx->front); + tailroom = sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, wrap) - (frtblk->addr + htx_get_blksz(frtblk)); + headroom = headblk->addr; - if (tailroom >= (int32_t)blksz) { - /* install upfront and update ->front */ - blk = htx_get_blk(htx, tail); - blk->addr = frtblk->addr + htx_get_blksz(frtblk); - htx->front = tail; - } - else if (headroom >= (int32_t)blksz) { - blk = htx_get_blk(htx, tail); - blk->addr = 0; - } - else { - /* need to defragment the table before inserting upfront */ - goto defrag; - } - } - else { - /* it's already wrapped so we can't store anything in the tailroom */ - headroom = headblk->addr - (prevblk->addr + htx_get_blksz(prevblk)); + if (tailroom >= (int32_t)blksz) { + /* install upfront and update ->front */ + blk = htx_get_blk(htx, tail); + blk->addr = frtblk->addr + htx_get_blksz(frtblk); + htx->front = tail; + } + else if (headroom >= (int32_t)blksz) { + blk = htx_get_blk(htx, tail); + blk->addr = 0; + } + else { + /* need to defragment the table before inserting upfront */ + goto defrag; + } + } + else { + /* it's already wrapped so we can't store anything in the tailroom */ + headroom = headblk->addr - (prevblk->addr + htx_get_blksz(prevblk)); - if (headroom >= (int32_t)blksz) { - blk = htx_get_blk(htx, tail); - blk->addr = prevblk->addr + htx_get_blksz(prevblk); - } - else { - defrag: - /* need to defragment the table before inserting upfront */ - htx_defrag(htx, NULL); - frtblk = htx_get_blk(htx, htx->front); - wrap = htx->wrap + 1; - tail = htx->tail + 1; - used = htx->used + 1; - blk = htx_get_blk(htx, tail); - blk->addr = frtblk->addr + htx_get_blksz(frtblk); - htx->front = tail; - } - } + if (headroom >= (int32_t)blksz) { + blk = htx_get_blk(htx, tail); + blk->addr = prevblk->addr + htx_get_blksz(prevblk); + } + else { + defrag: + /* need to defragment the table before inserting upfront */ + htx_defrag(htx, NULL); + frtblk = htx_get_blk(htx, htx->front); + wrap = htx->wrap + 1; + tail = htx->tail + 1; + used = htx->used + 1; + blk = htx_get_blk(htx, tail); + blk->addr = frtblk->addr + htx_get_blksz(frtblk); + htx->front = tail; + } + } - htx->wrap = wrap; - htx->tail = tail; - htx->used = used; - htx->data += blksz; - return blk; + htx->wrap = wrap; + htx->tail = tail; + htx->used = used; + htx->data += blksz; + return blk; } /* Adds a new block of type in the HTTP message . Its content size @@ -194,14 +194,14 @@ static struct htx_blk *htx_reserve_nxblk(struct htx *htx, uint32_t blksz) */ struct htx_blk *htx_add_blk(struct htx *htx, enum htx_blk_type type, uint32_t blksz) { - struct htx_blk *blk; + struct htx_blk *blk; - blk = htx_reserve_nxblk(htx, blksz); - if (!blk) - return NULL; + blk = htx_reserve_nxblk(htx, blksz); + if (!blk) + return NULL; - blk->info = (type << 28); - return blk; + blk->info = (type << 28); + return blk; } /* Removes the block from the HTTP message . The function returns the @@ -211,65 +211,65 @@ struct htx_blk *htx_add_blk(struct htx *htx, enum htx_blk_type type, uint32_t bl struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk) { enum htx_blk_type type = htx_get_blk_type(blk); - uint32_t next, head, pos; + uint32_t next, head, pos; - if (type != HTX_BLK_UNUSED) { - /* Mark the block as unused, decrement allocated size */ - htx->data -= htx_get_blksz(blk); - blk->info = ((uint32_t)HTX_BLK_UNUSED << 28); + if (type != HTX_BLK_UNUSED) { + /* Mark the block as unused, decrement allocated size */ + htx->data -= htx_get_blksz(blk); + blk->info = ((uint32_t)HTX_BLK_UNUSED << 28); if (htx->sl_off == blk->addr) htx->sl_off = -1; - } + } - /* This is the last block in use */ - if (htx->used == 1/* || !htx->data */) { - htx->front = htx->tail = 0; - htx->wrap = htx->used = 0; - htx->data = 0; - return NULL; - } + /* This is the last block in use */ + if (htx->used == 1/* || !htx->data */) { + htx->front = htx->tail = 0; + htx->wrap = htx->used = 0; + htx->data = 0; + return NULL; + } - /* There is at least 2 blocks, so tail is always >= 0 */ - pos = htx_get_blk_pos(htx, blk); - head = htx_get_head(htx); - blk = NULL; - next = pos + 1; /* By default retrun the next block */ - if (htx->tail + 1 == htx->wrap) { - /* The HTTP message doesn't wrap */ - if (pos == head) { - /* remove the head, so just return the new head */ - htx->used--; - next = htx_get_head(htx); - } - else if (pos == htx->tail) { - /* remove the tail. this was the last inserted block so - * return NULL. */ - htx->wrap--; - htx->tail--; - htx->used--; - goto end; - } - } - else { - /* The HTTP message wraps */ - if (pos == htx->tail) { - /* remove the tail. try to unwrap the message (pos == 0) - * and return NULL. */ - htx->tail = ((pos == 0) ? htx->wrap-1 : htx->tail-1); - htx->used--; - goto end; - } - else if (pos == head) { - /* remove the head, try to unwrap the message (pos+1 == - * wrap) and return the new head */ - htx->used--; - if (pos + 1 == htx->wrap) - htx->wrap = htx->tail + 1; - next = htx_get_head(htx); - } - } + /* There is at least 2 blocks, so tail is always >= 0 */ + pos = htx_get_blk_pos(htx, blk); + head = htx_get_head(htx); + blk = NULL; + next = pos + 1; /* By default retrun the next block */ + if (htx->tail + 1 == htx->wrap) { + /* The HTTP message doesn't wrap */ + if (pos == head) { + /* remove the head, so just return the new head */ + htx->used--; + next = htx_get_head(htx); + } + else if (pos == htx->tail) { + /* remove the tail. this was the last inserted block so + * return NULL. */ + htx->wrap--; + htx->tail--; + htx->used--; + goto end; + } + } + else { + /* The HTTP message wraps */ + if (pos == htx->tail) { + /* remove the tail. try to unwrap the message (pos == 0) + * and return NULL. */ + htx->tail = ((pos == 0) ? htx->wrap-1 : htx->tail-1); + htx->used--; + goto end; + } + else if (pos == head) { + /* remove the head, try to unwrap the message (pos+1 == + * wrap) and return the new head */ + htx->used--; + if (pos + 1 == htx->wrap) + htx->wrap = htx->tail + 1; + next = htx_get_head(htx); + } + } - blk = htx_get_blk(htx, next); + blk = htx_get_blk(htx, next); if (htx->sl_off == -1) { /* Try to update the start-line offset, if possible */ type = htx_get_blk_type(blk); @@ -277,9 +277,9 @@ struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk) htx->sl_off = blk->addr; } end: - if (pos == htx->front) - htx->front = htx_find_front(htx); - return blk; + if (pos == htx->front) + htx->front = htx_find_front(htx); + return blk; } /* Tries to append data to the last inserted block, if the type matches and if @@ -291,71 +291,71 @@ struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk) static struct htx_blk *htx_append_blk_value(struct htx *htx, enum htx_blk_type type, const struct ist data) { - struct htx_blk *blk; - struct ist v; + struct htx_blk *blk; + struct ist v; - if (!htx->used) - goto add_new_block; + if (!htx->used) + goto add_new_block; - /* Not enough space to store data */ - if (data.len > htx_free_data_space(htx)) - return NULL; + /* Not enough space to store data */ + if (data.len > htx_free_data_space(htx)) + return NULL; - /* Append only DATA et TRAILERS data */ - if (type != HTX_BLK_DATA && type != HTX_BLK_TLR) - goto add_new_block; + /* Append only DATA et TRAILERS data */ + if (type != HTX_BLK_DATA && type != HTX_BLK_TLR) + goto add_new_block; - /* get the tail block */ - blk = htx_get_blk(htx, htx->tail); + /* get the tail block */ + blk = htx_get_blk(htx, htx->tail); - /* Don't try to append data if the last inserted block is not of the - * same type */ - if (type != htx_get_blk_type(blk)) - goto add_new_block; + /* Don't try to append data if the last inserted block is not of the + * same type */ + if (type != htx_get_blk_type(blk)) + goto add_new_block; - /* - * Same type and enough space: append data - */ - if (htx->tail + 1 == htx->wrap) { - struct htx_blk *frtblk = htx_get_blk(htx, htx->front); - int32_t tailroom = sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, htx->tail) - (frtblk->addr + htx_get_blksz(frtblk)); - if (tailroom >= (int32_t)data.len) - goto append_data; - htx_defrag(htx, NULL); - blk = htx_get_blk(htx, htx->tail); - } - else { - struct htx_blk *headblk = htx_get_blk(htx, htx_get_head(htx)); - int32_t headroom = headblk->addr - (blk->addr + htx_get_blksz(blk)); - if (headroom >= (int32_t)data.len) - goto append_data; - htx_defrag(htx, NULL); - blk = htx_get_blk(htx, htx->tail); - } + /* + * Same type and enough space: append data + */ + if (htx->tail + 1 == htx->wrap) { + struct htx_blk *frtblk = htx_get_blk(htx, htx->front); + int32_t tailroom = sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, htx->tail) - (frtblk->addr + htx_get_blksz(frtblk)); + if (tailroom >= (int32_t)data.len) + goto append_data; + htx_defrag(htx, NULL); + blk = htx_get_blk(htx, htx->tail); + } + else { + struct htx_blk *headblk = htx_get_blk(htx, htx_get_head(htx)); + int32_t headroom = headblk->addr - (blk->addr + htx_get_blksz(blk)); + if (headroom >= (int32_t)data.len) + goto append_data; + htx_defrag(htx, NULL); + blk = htx_get_blk(htx, htx->tail); + } append_data: - /* get the value of the tail block */ - /* FIXME: check v.len + data.len < 256MB */ - v = htx_get_blk_value(htx, blk); + /* get the value of the tail block */ + /* FIXME: check v.len + data.len < 256MB */ + v = htx_get_blk_value(htx, blk); - /* Append data and update the block itself */ - memcpy(v.ptr + v.len, data.ptr, data.len); - htx_set_blk_value_len(blk, v.len + data.len); + /* Append data and update the block itself */ + memcpy(v.ptr + v.len, data.ptr, data.len); + htx_set_blk_value_len(blk, v.len + data.len); - /* Update HTTP message */ - htx->data += data.len; + /* Update HTTP message */ + htx->data += data.len; - return blk; + return blk; add_new_block: - /* FIXME: check tlr.len (< 256MB) */ - blk = htx_add_blk(htx, type, data.len); - if (!blk) - return NULL; + /* FIXME: check tlr.len (< 256MB) */ + blk = htx_add_blk(htx, type, data.len); + if (!blk) + return NULL; - blk->info += data.len; - memcpy(htx_get_blk_ptr(htx, blk), data.ptr, data.len); - return blk; + blk->info += data.len; + memcpy(htx_get_blk_ptr(htx, blk), data.ptr, data.len); + return blk; } /* Replaces a value part of a block by a new one. The new part can be smaller or @@ -364,81 +364,81 @@ static struct htx_blk *htx_append_blk_value(struct htx *htx, enum htx_blk_type t * NULL. */ struct htx_blk *htx_replace_blk_value(struct htx *htx, struct htx_blk *blk, - const struct ist old, const struct ist new) + const struct ist old, const struct ist new) { - struct htx_blk *frtblk; - struct buffer *tmp; - struct ist n, v; - uint32_t info, room; + struct htx_blk *frtblk; + struct buffer *tmp; + struct ist n, v; + uint32_t info, room; - n = htx_get_blk_name(htx, blk); - v = htx_get_blk_value(htx, blk); + n = htx_get_blk_name(htx, blk); + v = htx_get_blk_value(htx, blk); - /* easy case, new data are smaller, so replace it in-place */ - if (new.len <= old.len) { - memcpy(old.ptr, new.ptr, new.len); - if (old.len != v.len) - memmove(old.ptr + new.len, old.ptr + old.len, (v.ptr + v.len) - (old.ptr + old.len)); - htx_set_blk_value_len(blk, v.len - old.len + new.len); - htx->data -= (old.len - new.len); - return blk; - } + /* easy case, new data are smaller, so replace it in-place */ + if (new.len <= old.len) { + memcpy(old.ptr, new.ptr, new.len); + if (old.len != v.len) + memmove(old.ptr + new.len, old.ptr + old.len, (v.ptr + v.len) - (old.ptr + old.len)); + htx_set_blk_value_len(blk, v.len - old.len + new.len); + htx->data -= (old.len - new.len); + return blk; + } - /* we need to allocate more space to store the new header value */ - if ((new.len - old.len) > htx_free_space(htx)) - return NULL; /* not enough space */ + /* we need to allocate more space to store the new header value */ + if ((new.len - old.len) > htx_free_space(htx)) + return NULL; /* not enough space */ - /* - * Copy the new header in a temp buffer - */ - tmp = get_trash_chunk(); + /* + * Copy the new header in a temp buffer + */ + tmp = get_trash_chunk(); - /* 1. copy the header name */ - chunk_memcat(tmp, n.ptr, n.len); + /* 1. copy the header name */ + chunk_memcat(tmp, n.ptr, n.len); - /* 2. copy value before old part, if any */ - if (old.ptr != v.ptr) - chunk_memcat(tmp, v.ptr, old.ptr - v.ptr); + /* 2. copy value before old part, if any */ + if (old.ptr != v.ptr) + chunk_memcat(tmp, v.ptr, old.ptr - v.ptr); - /* 3. copy new value */ - chunk_memcat(tmp, new.ptr, new.len); + /* 3. copy new value */ + chunk_memcat(tmp, new.ptr, new.len); - /* 4. copy value after old part if any */ - if (old.len != v.len) - chunk_memcat(tmp, old.ptr + old.len, (v.ptr + v.len) - (old.ptr + old.len)); + /* 4. copy value after old part if any */ + if (old.len != v.len) + chunk_memcat(tmp, old.ptr + old.len, (v.ptr + v.len) - (old.ptr + old.len)); - /* - * temporarely remove space reserved for the header - */ - info = blk->info; - blk->info &= 0xf0000000; - htx->data -= (n.len + v.len); + /* + * temporarely remove space reserved for the header + */ + info = blk->info; + blk->info &= 0xf0000000; + htx->data -= (n.len + v.len); - /* - * Try to find right addr to copy all the data - */ - if (htx->tail + 1 == htx->wrap) { - frtblk = htx_get_blk(htx, htx->front); - room = sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, htx->tail) - (frtblk->addr + htx_get_blksz(frtblk)); - if (room >= htx->data) { - blk->addr = frtblk->addr + htx_get_blksz(frtblk); - goto replace_value; - } - } + /* + * Try to find right addr to copy all the data + */ + if (htx->tail + 1 == htx->wrap) { + frtblk = htx_get_blk(htx, htx->front); + room = sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, htx->tail) - (frtblk->addr + htx_get_blksz(frtblk)); + if (room >= htx->data) { + blk->addr = frtblk->addr + htx_get_blksz(frtblk); + goto replace_value; + } + } - /* HTX message need to be defragmented first */ - blk = htx_defrag(htx, blk); - frtblk = htx_get_blk(htx, htx->front); - blk->addr = frtblk->addr + htx_get_blksz(frtblk); + /* HTX message need to be defragmented first */ + blk = htx_defrag(htx, blk); + frtblk = htx_get_blk(htx, htx->front); + blk->addr = frtblk->addr + htx_get_blksz(frtblk); replace_value: - blk->info = info; - htx_set_blk_value_len(blk, v.len - old.len + new.len); - memcpy(htx_get_blk_ptr(htx, blk), tmp->area, tmp->data); - htx->data += tmp->data; - htx->front = htx_get_blk_pos(htx, blk); + blk->info = info; + htx_set_blk_value_len(blk, v.len - old.len + new.len); + memcpy(htx_get_blk_ptr(htx, blk), tmp->area, tmp->data); + htx->data += tmp->data; + htx->front = htx_get_blk_pos(htx, blk); - return blk; + return blk; } /* Transfer HTX blocks from to , stopping on the first block of the @@ -451,7 +451,7 @@ struct htx_ret htx_xfer_blks(struct htx *dst, struct htx *src, uint32_t count, { struct htx_blk *blk, *dstblk; enum htx_blk_type type; - uint32_t info, max, sz, ret; + uint32_t info, max, sz, ret; ret = 0; blk = htx_get_blk(src, htx_get_head(src)); @@ -515,75 +515,75 @@ struct htx_ret htx_xfer_blks(struct htx *dst, struct htx *src, uint32_t count, static struct htx_blk *htx_new_blk_value(struct htx *htx, struct htx_blk *blk, uint32_t newsz) { - struct htx_blk *frtblk; - uint32_t sz, room; - int32_t delta; + struct htx_blk *frtblk; + uint32_t sz, room; + int32_t delta; sz = htx_get_blksz(blk); - delta = newsz - sz; + delta = newsz - sz; - /* easy case, new value is smaller, so replace it in-place */ - if (delta <= 0) { + /* easy case, new value is smaller, so replace it in-place */ + if (delta <= 0) { /* Reset value size. It is the caller responsibility to set the new one */ blk->info &= 0xf0000000; - htx->data += delta; - return blk; - } + htx->data += delta; + return blk; + } - /* we need to allocate more space to store the new value */ - if (delta > htx_free_space(htx)) - return NULL; /* not enough space */ + /* we need to allocate more space to store the new value */ + if (delta > htx_free_space(htx)) + return NULL; /* not enough space */ - /* - * temporarely remove space reserved for the old value - */ + /* + * temporarely remove space reserved for the old value + */ /* Reset value size. It is the caller responsibility to set the new one */ blk->info &= 0xf0000000; - htx->data -= sz; + htx->data -= sz; - /* - * Try to find right addr to copy all the data - */ - if (htx->tail + 1 == htx->wrap) { - frtblk = htx_get_blk(htx, htx->front); - room = sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, htx->tail) - (frtblk->addr + htx_get_blksz(frtblk)); - if (room >= newsz) - goto replace_value; - } + /* + * Try to find right addr to copy all the data + */ + if (htx->tail + 1 == htx->wrap) { + frtblk = htx_get_blk(htx, htx->front); + room = sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, htx->tail) - (frtblk->addr + htx_get_blksz(frtblk)); + if (room >= newsz) + goto replace_value; + } - /* HTX message need to be defragmented first */ - blk = htx_defrag(htx, blk); - frtblk = htx_get_blk(htx, htx->front); + /* HTX message need to be defragmented first */ + blk = htx_defrag(htx, blk); + frtblk = htx_get_blk(htx, htx->front); replace_value: - blk->addr = frtblk->addr + htx_get_blksz(frtblk); - htx->data += newsz; - htx->front = htx_get_blk_pos(htx, blk); + blk->addr = frtblk->addr + htx_get_blksz(frtblk); + htx->data += newsz; + htx->front = htx_get_blk_pos(htx, blk); - return blk; + return blk; } /* Replaces an header by a new one. The new header can be smaller or larger than * the old one. It returns the new block on success, otherwise it returns NULL. */ struct htx_blk *htx_replace_header(struct htx *htx, struct htx_blk *blk, - const struct ist name, const struct ist value) + const struct ist name, const struct ist value) { - enum htx_blk_type type; + enum htx_blk_type type; - type = htx_get_blk_type(blk); - if (type != HTX_BLK_HDR) - return NULL; + type = htx_get_blk_type(blk); + if (type != HTX_BLK_HDR) + return NULL; blk = htx_new_blk_value(htx, blk, (name.len + value.len)); if (!blk) return NULL; blk->info = (type << 28) + (value.len << 8) + name.len; - memcpy(htx_get_blk_ptr(htx, blk), name.ptr, name.len); - memcpy(htx_get_blk_ptr(htx, blk) + name.len, value.ptr, value.len); + memcpy(htx_get_blk_ptr(htx, blk), name.ptr, name.len); + memcpy(htx_get_blk_ptr(htx, blk) + name.len, value.ptr, value.len); - return blk; + return blk; } /* Replaces the parts of the start-line. It returns the new start-line on @@ -595,12 +595,12 @@ struct htx_sl *htx_replace_stline(struct htx *htx, struct htx_blk *blk, const st { struct htx_sl *sl; struct htx_sl tmp; /* used to save sl->info and sl->flags */ - enum htx_blk_type type; + enum htx_blk_type type; uint32_t size; - type = htx_get_blk_type(blk); - if (type != HTX_BLK_REQ_SL || HTX_BLK_RES_SL) - return NULL; + type = htx_get_blk_type(blk); + if (type != HTX_BLK_REQ_SL || HTX_BLK_RES_SL) + return NULL; /* Save start-line info and flags */ sl = htx_get_blk_ptr(htx, blk); @@ -640,7 +640,7 @@ struct htx_sl *htx_replace_stline(struct htx *htx, struct htx_blk *blk, const st struct htx_sl *htx_add_stline(struct htx *htx, enum htx_blk_type type, unsigned int flags, const struct ist p1, const struct ist p2, const struct ist p3) { - struct htx_blk *blk; + struct htx_blk *blk; struct htx_sl *sl; uint32_t size; @@ -649,11 +649,11 @@ struct htx_sl *htx_add_stline(struct htx *htx, enum htx_blk_type type, unsigned size = sizeof(*sl) + p1.len + p2.len + p3.len; - /* FIXME: check size (< 256MB) */ - blk = htx_add_blk(htx, type, size); - if (!blk) - return NULL; - blk->info += size; + /* FIXME: check size (< 256MB) */ + blk = htx_add_blk(htx, type, size); + if (!blk) + return NULL; + blk->info += size; sl = htx_get_blk_ptr(htx, blk); if (htx->sl_off == -1) @@ -669,26 +669,26 @@ struct htx_sl *htx_add_stline(struct htx *htx, enum htx_blk_type type, unsigned memcpy(HTX_SL_P2_PTR(sl), p2.ptr, p2.len); memcpy(HTX_SL_P3_PTR(sl), p3.ptr, p3.len); - return sl; + return sl; } /* Adds an HTX block of type HDR in . It returns the new block on * success. Otherwise, it returns NULL. */ struct htx_blk *htx_add_header(struct htx *htx, const struct ist name, - const struct ist value) + const struct ist value) { - struct htx_blk *blk; + struct htx_blk *blk; - /* FIXME: check name.len (< 256B) and value.len (< 1MB) */ - blk = htx_add_blk(htx, HTX_BLK_HDR, name.len + value.len); - if (!blk) - return NULL; + /* FIXME: check name.len (< 256B) and value.len (< 1MB) */ + blk = htx_add_blk(htx, HTX_BLK_HDR, name.len + value.len); + if (!blk) + return NULL; - blk->info += (value.len << 8) + name.len; - memcpy(htx_get_blk_ptr(htx, blk), name.ptr, name.len); - memcpy(htx_get_blk_ptr(htx, blk) + name.len, value.ptr, value.len); - return blk; + blk->info += (value.len << 8) + name.len; + memcpy(htx_get_blk_ptr(htx, blk), name.ptr, name.len); + memcpy(htx_get_blk_ptr(htx, blk) + name.len, value.ptr, value.len); + return blk; } struct htx_blk *htx_add_all_headers(struct htx *htx, const struct http_hdr *hdrs) @@ -705,18 +705,18 @@ struct htx_blk *htx_add_all_headers(struct htx *htx, const struct http_hdr *hdrs * success. Otherwise, it returns NULL. */ struct htx_blk *htx_add_pseudo_header(struct htx *htx, enum htx_phdr_type phdr, - const struct ist value) + const struct ist value) { - struct htx_blk *blk; + struct htx_blk *blk; - /* FIXME: check value.len ( < 1MB) */ - blk = htx_add_blk(htx, HTX_BLK_PHDR, value.len); - if (!blk) - return NULL; + /* FIXME: check value.len ( < 1MB) */ + blk = htx_add_blk(htx, HTX_BLK_PHDR, value.len); + if (!blk) + return NULL; - blk->info += (value.len << 8) + phdr; - memcpy(htx_get_blk_ptr(htx, blk), value.ptr, value.len); - return blk; + blk->info += (value.len << 8) + phdr; + memcpy(htx_get_blk_ptr(htx, blk), value.ptr, value.len); + return blk; } /* Adds an HTX block of type EOH,EOD or EOM in . It returns the new block @@ -724,14 +724,14 @@ struct htx_blk *htx_add_pseudo_header(struct htx *htx, enum htx_phdr_type phdr, */ struct htx_blk *htx_add_endof(struct htx *htx, enum htx_blk_type type) { - struct htx_blk *blk; + struct htx_blk *blk; - blk = htx_add_blk(htx, type, 1); - if (!blk) - return NULL; + blk = htx_add_blk(htx, type, 1); + if (!blk) + return NULL; - blk->info += 1; - return blk; + blk->info += 1; + return blk; } @@ -740,7 +740,7 @@ struct htx_blk *htx_add_endof(struct htx *htx, enum htx_blk_type type) */ struct htx_blk *htx_add_data(struct htx *htx, const struct ist data) { - return htx_append_blk_value(htx, HTX_BLK_DATA, data); + return htx_append_blk_value(htx, HTX_BLK_DATA, data); } /* Adds an HTX block of type TLR in . It first tries to append trailers @@ -749,7 +749,7 @@ struct htx_blk *htx_add_data(struct htx *htx, const struct ist data) */ struct htx_blk *htx_add_trailer(struct htx *htx, const struct ist tlr) { - return htx_append_blk_value(htx, HTX_BLK_TLR, tlr); + return htx_append_blk_value(htx, HTX_BLK_TLR, tlr); } /* Adds an HTX block of type OOB in . It returns the new block on @@ -757,16 +757,16 @@ struct htx_blk *htx_add_trailer(struct htx *htx, const struct ist tlr) */ struct htx_blk *htx_add_oob(struct htx *htx, const struct ist oob) { - struct htx_blk *blk; + struct htx_blk *blk; - /* FIXME: check oob.len (< 256MB) */ - blk = htx_add_blk(htx, HTX_BLK_OOB, oob.len); - if (!blk) - return NULL; + /* FIXME: check oob.len (< 256MB) */ + blk = htx_add_blk(htx, HTX_BLK_OOB, oob.len); + if (!blk) + return NULL; - blk->info += oob.len; - memcpy(htx_get_blk_ptr(htx, blk), oob.ptr, oob.len); - return blk; + blk->info += oob.len; + memcpy(htx_get_blk_ptr(htx, blk), oob.ptr, oob.len); + return blk; } struct htx_blk *htx_add_data_before(struct htx *htx, const struct htx_blk *ref, @@ -775,13 +775,13 @@ struct htx_blk *htx_add_data_before(struct htx *htx, const struct htx_blk *ref, struct htx_blk *blk; int32_t prev; - /* FIXME: check data.len (< 256MB) */ - blk = htx_add_blk(htx, HTX_BLK_DATA, data.len); - if (!blk) - return NULL; + /* FIXME: check data.len (< 256MB) */ + blk = htx_add_blk(htx, HTX_BLK_DATA, data.len); + if (!blk) + return NULL; - blk->info += data.len; - memcpy(htx_get_blk_ptr(htx, blk), data.ptr, data.len); + blk->info += data.len; + memcpy(htx_get_blk_ptr(htx, blk), data.ptr, data.len); for (prev = htx_get_prev(htx, htx->tail); prev != -1; prev = htx_get_prev(htx, prev)) { struct htx_blk *pblk = htx_get_blk(htx, prev); diff --git a/src/mux_h1.c b/src/mux_h1.c index a09cac824..9449c50f4 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -498,8 +498,8 @@ static int h1_process_req_vsn(struct h1s *h1s, struct h1m *h1m, union h1_sl sl) } if ((sl.rq.v.len == 8) && - ((*(sl.rq.v.ptr + 5) > '1') || - ((*(sl.rq.v.ptr + 5) == '1') && (*(sl.rq.v.ptr + 7) >= '1')))) + ((*(sl.rq.v.ptr + 5) > '1') || + ((*(sl.rq.v.ptr + 5) == '1') && (*(sl.rq.v.ptr + 7) >= '1')))) h1m->flags |= H1_MF_VER_11; return 1; } @@ -528,8 +528,8 @@ static int h1_process_res_vsn(struct h1s *h1s, struct h1m *h1m, union h1_sl sl) } if ((sl.st.v.len == 8) && - ((*(sl.st.v.ptr + 5) > '1') || - ((*(sl.st.v.ptr + 5) == '1') && (*(sl.st.v.ptr + 7) >= '1')))) + ((*(sl.st.v.ptr + 5) > '1') || + ((*(sl.st.v.ptr + 5) == '1') && (*(sl.st.v.ptr + 7) >= '1')))) h1m->flags |= H1_MF_VER_11; return 1; @@ -773,12 +773,12 @@ static void h1_process_conn_mode(struct h1s *h1s, struct h1m *h1m, static void h1_show_error_snapshot(struct buffer *out, const struct error_snapshot *es) { chunk_appendf(out, - " H1 connection flags 0x%08x, H1 stream flags 0x%08x\n" - " H1 msg state %s(%d), H1 msg flags 0x%08x\n" - " H1 chunk len %lld bytes, H1 body len %lld bytes :\n", - es->ctx.h1.c_flags, es->ctx.h1.s_flags, - h1m_state_str(es->ctx.h1.state), es->ctx.h1.state, - es->ctx.h1.m_flags, es->ctx.h1.m_clen, es->ctx.h1.m_blen); + " H1 connection flags 0x%08x, H1 stream flags 0x%08x\n" + " H1 msg state %s(%d), H1 msg flags 0x%08x\n" + " H1 chunk len %lld bytes, H1 body len %lld bytes :\n", + es->ctx.h1.c_flags, es->ctx.h1.s_flags, + h1m_state_str(es->ctx.h1.state), es->ctx.h1.state, + es->ctx.h1.m_flags, es->ctx.h1.m_clen, es->ctx.h1.m_blen); } /* * Capture a bad request or response and archive it in the proxy's structure. @@ -809,8 +809,8 @@ static void h1_capture_bad_message(struct h1c *h1c, struct h1s *h1s, proxy_capture_error(proxy, !!(h1m->flags & H1_MF_RESP), other_end, h1c->conn->target, sess, buf, 0, 0, - (h1m->err_pos >= 0) ? h1m->err_pos : h1m->next, - &ctx, h1_show_error_snapshot); + (h1m->err_pos >= 0) ? h1m->err_pos : h1m->next, + &ctx, h1_show_error_snapshot); } /* @@ -965,8 +965,8 @@ static size_t h1_process_headers(struct h1s *h1s, struct h1m *h1m, struct htx *h * responsible to update the parser state . */ static size_t h1_process_data(struct h1s *h1s, struct h1m *h1m, struct htx *htx, - struct buffer *buf, size_t *ofs, size_t max, - struct buffer *htxbuf) + struct buffer *buf, size_t *ofs, size_t max, + struct buffer *htxbuf) { uint32_t data_space = htx_free_data_space(htx); size_t total = 0;