]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: use b_orig() to replace most references to b->data
authorWilly Tarreau <w@1wt.eu>
Fri, 15 Jun 2018 15:21:00 +0000 (17:21 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:42 +0000 (16:23 +0200)
This patch updates most users of b->data to use b_orig().

include/common/buf.h
include/common/buffer.h
include/proto/h1.h
src/buffer.c
src/channel.c
src/mux_h2.c
src/raw_sock.c
src/ssl_sock.c
src/stream.c

index b7a5df31774d514bb8e137c6512024683c7c8bfc..4632a3346715a42b75a4677feee6c474d82100ac 100644 (file)
@@ -364,7 +364,7 @@ static inline size_t b_getblk_nc(const struct buffer *buf, const char **blk1, si
        if (l1 < max) {
                *len1 = l1;
                *len2 = max - l1;
-               *blk2 = buf->data;
+               *blk2 = b_orig(buf);
                return 2;
        }
        *len1 = max;
index 6f3ab26a1983c526bcf61060bf87fc699e2b1cf2..e43969c54cc2c02d0ca2b15ea9dfe852d5fc2290 100644 (file)
@@ -64,7 +64,7 @@ void buffer_dump(FILE *o, struct buffer *b, int from, int to);
 /* Normalizes a pointer after an addition */
 static inline char *buffer_wrap_add(const struct buffer *buf, char *ptr)
 {
-       if (ptr - buf->size >= buf->data)
+       if (ptr - buf->size >= b_orig(buf))
                ptr -= buf->size;
        return ptr;
 }
@@ -77,9 +77,9 @@ static inline char *buffer_wrap_add(const struct buffer *buf, char *ptr)
  */
 static inline const char *buffer_pointer(const struct buffer *buf, const char *ptr)
 {
-       if (ptr < buf->data)
+       if (ptr < b_orig(buf))
                ptr += buf->size;
-       else if (ptr - buf->size >= buf->data)
+       else if (ptr - buf->size >= b_orig(buf))
                ptr -= buf->size;
        return ptr;
 }
@@ -405,7 +405,7 @@ static inline int b_isteq(const struct buffer *b, unsigned int o, size_t n, cons
                if (*p++ != *r.ptr++)
                        return -1;
                if (unlikely(p == end))
-                       p = b->data;
+                       p = b_orig(b);
        }
        return ist.len;
 }
@@ -447,7 +447,7 @@ static inline int bi_istput(struct buffer *b, const struct ist ist)
        while (r.len--) {
                *p++ = *r.ptr++;
                if (unlikely(p == end))
-                       p = b->data;
+                       p = b_orig(b);
        }
        return ist.len;
 }
@@ -477,7 +477,7 @@ static inline int bo_istput(struct buffer *b, const struct ist ist)
        while (r.len--) {
                *p++ = *r.ptr++;
                if (unlikely(p == end))
-                       p = b->data;
+                       p = b_orig(b);
        }
        return ist.len;
 }
index 943ac0fe5e82f835d7d5048b8ee8de17640dbd63..eef310f8f6bb625e6dd823d753bf95dacd854cc5 100644 (file)
@@ -163,7 +163,7 @@ static inline int h1_skip_chunk_crlf(const struct buffer *buf, int start, int st
                bytes++;
                ptr++;
                if (ptr >= b_wrap(buf))
-                       ptr = buf->data;
+                       ptr = b_orig(buf);
        }
 
        if (bytes > stop - start)
@@ -210,7 +210,7 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s
                if (c < 0) /* not a hex digit anymore */
                        break;
                if (unlikely(++ptr >= end))
-                       ptr = buf->data;
+                       ptr = b_orig(buf);
                if (unlikely(chunk & 0xF8000000)) /* integer overflow will occur if result >= 2GB */
                        goto error;
                chunk = (chunk << 4) + c;
@@ -223,7 +223,7 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s
 
        while (HTTP_IS_SPHT(*ptr)) {
                if (++ptr >= end)
-                       ptr = buf->data;
+                       ptr = b_orig(buf);
                if (--stop == 0)
                        return 0;
        }
@@ -236,7 +236,7 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s
                        /* we now have a CR or an LF at ptr */
                        if (likely(*ptr == '\r')) {
                                if (++ptr >= end)
-                                       ptr = buf->data;
+                                       ptr = b_orig(buf);
                                if (--stop == 0)
                                        return 0;
                        }
@@ -244,7 +244,7 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s
                        if (*ptr != '\n')
                                goto error;
                        if (++ptr >= end)
-                               ptr = buf->data;
+                               ptr = b_orig(buf);
                        --stop;
                        /* done */
                        break;
@@ -252,13 +252,13 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s
                else if (likely(*ptr == ';')) {
                        /* chunk extension, ends at next CRLF */
                        if (++ptr >= end)
-                               ptr = buf->data;
+                               ptr = b_orig(buf);
                        if (--stop == 0)
                                return 0;
 
                        while (!HTTP_IS_CRLF(*ptr)) {
                                if (++ptr >= end)
-                                       ptr = buf->data;
+                                       ptr = b_orig(buf);
                                if (--stop == 0)
                                        return 0;
                        }
index 16372bf07cb1e5805f2e81d9abde03dbe30e9ca7..fe756f781b3e00a2517ae3ba9fafeec6348b3a24 100644 (file)
@@ -86,7 +86,7 @@ int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int
 
        delta = len - (end - pos);
 
-       if (b_tail(b) + delta > b->data + b->size)
+       if (b_tail(b) + delta > b_wrap(b))
                return 0;  /* no space left */
 
        if (b_data(b) &&
@@ -123,7 +123,7 @@ int buffer_insert_line2(struct buffer *b, char *pos, const char *str, int len)
 
        delta = len + 2;
 
-       if (b_tail(b) + delta >= b->data + b->size)
+       if (b_tail(b) + delta >= b_wrap(b))
                return 0;  /* no space left */
 
        if (b_data(b) &&
index 1efab9c95ca0a0ff535e6aaf4ab066c5a0bb6c22..024f2744407734cb48a9b522fea59dc5b940f576 100644 (file)
@@ -169,7 +169,7 @@ int ci_putblk(struct channel *chn, const char *blk, int len)
        max = b_contig_space(chn->buf);
        memcpy(ci_tail(chn), blk, MIN(len, max));
        if (len > max)
-               memcpy(chn->buf->data, blk + max, len - max);
+               memcpy(b_orig(chn->buf), blk + max, len - max);
 
        chn->buf->i += len;
        chn->total += len;
@@ -386,10 +386,10 @@ int ci_getblk_nc(const struct channel *chn,
                return 0;
        }
 
-       if (unlikely(chn->buf->p + chn->buf->i > chn->buf->data + chn->buf->size)) {
+       if (unlikely(chn->buf->p + chn->buf->i > b_wrap(chn->buf))) {
                *blk1 = chn->buf->p;
-               *len1 = chn->buf->data + chn->buf->size - chn->buf->p;
-               *blk2 = chn->buf->data;
+               *len1 = b_wrap(chn->buf) - chn->buf->p;
+               *blk2 = b_orig(chn->buf);
                *len2 = chn->buf->i - *len1;
                return 2;
        }
index 207589b55be5c528028c0353c67fd6bd11dca73a..81772dbbcaa0154d7625b835ab3477e663bc2f4d 100644 (file)
@@ -516,22 +516,22 @@ static inline __maybe_unused void h2_set_frame_size(void *frame, uint32_t len)
 static inline __maybe_unused void h2_get_buf_bytes(void *dst, size_t bytes,
                                     const struct buffer *b, int o)
 {
-       readv_bytes(dst, bytes, b_peek(b, o), b_wrap(b) - b_peek(b, o), b->data);
+       readv_bytes(dst, bytes, b_peek(b, o), b_wrap(b) - b_peek(b, o), b_orig(b));
 }
 
 static inline __maybe_unused uint16_t h2_get_n16(const struct buffer *b, int o)
 {
-       return readv_n16(b_peek(b, o), b_wrap(b) - b_peek(b, o), b->data);
+       return readv_n16(b_peek(b, o), b_wrap(b) - b_peek(b, o), b_orig(b));
 }
 
 static inline __maybe_unused uint32_t h2_get_n32(const struct buffer *b, int o)
 {
-       return readv_n32(b_peek(b, o), b_wrap(b) - b_peek(b, o), b->data);
+       return readv_n32(b_peek(b, o), b_wrap(b) - b_peek(b, o), b_orig(b));
 }
 
 static inline __maybe_unused uint64_t h2_get_n64(const struct buffer *b, int o)
 {
-       return readv_n64(b_peek(b, o), b_wrap(b) - b_peek(b, o), b->data);
+       return readv_n64(b_peek(b, o), b_wrap(b) - b_peek(b, o), b_orig(b));
 }
 
 
index 3ae76562ed87b6a5cd0d15873294fc60912a48d5..e0bfd1d995cc724aaefc1f1f5e2240c08f43e81c 100644 (file)
@@ -284,14 +284,10 @@ static size_t raw_sock_to_buf(struct connection *conn, struct buffer *buf, size_
         * EINTR too.
         */
        while (count > 0) {
-               /* first check if we have some room after p+i */
-               try = buf->data + buf->size - (buf->p + buf->i);
-               /* otherwise continue between data and p-o */
-               if (try <= 0) {
-                       try = buf->p - (buf->data + buf->o);
-                       if (try <= 0)
-                               break;
-               }
+               try = b_contig_space(buf);
+               if (!try)
+                       break;
+
                if (try > count)
                        try = count;
 
index 9aa101b2ba090e609e6fc9bad24da17475d0a8fe..b4730271726a1079dc42afd9d19706fc2cf66f7c 100644 (file)
@@ -5361,16 +5361,13 @@ static size_t ssl_sock_to_buf(struct connection *conn, struct buffer *buf, size_
        while (count > 0) {
                int need_out = 0;
 
-               /* first check if we have some room after p+i */
-               try = buf->data + buf->size - (buf->p + buf->i);
-               /* otherwise continue between data and p-o */
-               if (try <= 0) {
-                       try = buf->p - (buf->data + buf->o);
-                       if (try <= 0)
-                               break;
-               }
+               try = b_contig_space(buf);
+               if (!try)
+                       break;
+
                if (try > count)
                        try = count;
+
                if (((conn->flags & (CO_FL_EARLY_SSL_HS | CO_FL_EARLY_DATA)) == CO_FL_EARLY_SSL_HS) &&
                    conn->tmp_early_data != -1) {
                        *b_tail(buf) = conn->tmp_early_data;
index d6e28646322e717a7ff2aa614c2d0404014cbd80..204d1f2c0e10765e544038874ebdc0e0a8362fed 100644 (file)
@@ -2979,9 +2979,9 @@ static int stats_dump_full_strm_to_buffer(struct stream_interface *si, struct st
                             human_time(TICKS_TO_MS(strm->req.wex - now_ms),
                                        TICKS_TO_MS(1000)) : "<NEVER>",
                             strm->req.buf,
-                            strm->req.buf->data, (unsigned int)strm->req.buf->o,
-                            (int)(strm->req.buf->p - strm->req.buf->data),
-                            strm->txn ? strm->txn->req.next : 0, (unsigned int)strm->req.buf->i,
+                            b_orig(strm->req.buf), (unsigned int)co_data(&strm->req),
+                            (int)(strm->req.buf->p - b_orig(strm->req.buf)),
+                            strm->txn ? strm->txn->req.next : 0, (unsigned int)ci_data(&strm->req),
                             (unsigned int)strm->req.buf->size);
 
                chunk_appendf(&trash,
@@ -3008,9 +3008,9 @@ static int stats_dump_full_strm_to_buffer(struct stream_interface *si, struct st
                             human_time(TICKS_TO_MS(strm->res.wex - now_ms),
                                        TICKS_TO_MS(1000)) : "<NEVER>",
                             strm->res.buf,
-                            strm->res.buf->data, (unsigned int)strm->res.buf->o,
-                            (int)(strm->res.buf->p - strm->res.buf->data),
-                            strm->txn ? strm->txn->rsp.next : 0, (unsigned int)strm->res.buf->i,
+                            b_orig(strm->res.buf), (unsigned int)co_data(&strm->res),
+                            (int)(strm->res.buf->p - b_orig(strm->res.buf)),
+                            strm->txn ? strm->txn->rsp.next : 0, (unsigned int)ci_data(&strm->res),
                             (unsigned int)strm->res.buf->size);
 
                if (ci_putchk(si_ic(si), &trash) == -1) {