]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: Use b_add()/bo_add() instead of accessing b->i/b->o.
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 28 Jun 2018 16:17:23 +0000 (18:17 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:42 +0000 (16:23 +0200)
Use the newly available functions instead of using the buffer fields directly.

src/buffer.c
src/cache.c
src/channel.c
src/compression.c
src/flt_http_comp.c
src/mux_h2.c
src/raw_sock.c
src/ssl_sock.c

index fe756f781b3e00a2517ae3ba9fafeec6348b3a24..b4b6e1a1e9888207800662d2d5828d65a878bf16 100644 (file)
@@ -101,7 +101,7 @@ int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int
        if (len)
                memcpy(pos, str, len);
 
-       b->i += delta;
+       b_add(b, delta);
        b_realign_if_empty(b);
 
        return delta;
@@ -141,7 +141,7 @@ int buffer_insert_line2(struct buffer *b, char *pos, const char *str, int len)
                pos[len + 1] = '\n';
        }
 
-       b->i += delta;
+       b_add(b, delta);
        return delta;
 }
 
index f66106d2dfe1e3dddc50c6562cca58b9db4329af..b86d7bdec522f9afaac505cc67db80c0132017c1 100644 (file)
@@ -560,7 +560,7 @@ static void http_cache_io_handler(struct appctx *appctx)
                        si_applet_cant_put(si);
                        goto out;
                }
-               res->buf->i += len;
+               b_add(res->buf, len);
                res->total += len;
                appctx->st0 = HTTP_CACHE_FWD;
        }
index 024f2744407734cb48a9b522fea59dc5b940f576..2a75042b74f4530118b922162b37bace8d61aace 100644 (file)
@@ -96,9 +96,9 @@ int co_inject(struct channel *chn, const char *msg, int len)
        if (len > max)
                return max;
 
-       memcpy(chn->buf->p, msg, len);
-       chn->buf->o += len;
-       chn->buf->p = c_ptr(chn, len);
+       memcpy(b_tail(chn->buf), msg, len);
+       b_add(chn->buf, len);
+       c_adv(chn, len);
        chn->total += len;
        return -1;
 }
@@ -171,7 +171,7 @@ int ci_putblk(struct channel *chn, const char *blk, int len)
        if (len > max)
                memcpy(b_orig(chn->buf), blk + max, len - max);
 
-       chn->buf->i += len;
+       b_add(chn->buf, len);
        chn->total += len;
        if (chn->to_forward) {
                unsigned long fwd = len;
index 397fd94268f9b067db8f39f57df0de635d356d2f..2abe9043a145103b0771d1c6611aa2a68f073027 100644 (file)
@@ -229,7 +229,7 @@ static int identity_add_data(struct comp_ctx *comp_ctx, const char *in_data, int
 
        memcpy(out_data, in_data, in_len);
 
-       out->i += in_len;
+       b_add(out, in_len);
 
        return in_len;
 }
@@ -308,7 +308,7 @@ static int rfc195x_add_data(struct comp_ctx *comp_ctx, const char *in_data, int
                }
                b_reset(tmpbuf);
                memcpy(b_tail(tmpbuf), comp_ctx->direct_ptr, comp_ctx->direct_len);
-               tmpbuf->i += comp_ctx->direct_len;
+               b_add(tmpbuf, comp_ctx->direct_len);
                comp_ctx->direct_ptr = NULL;
                comp_ctx->direct_len = 0;
                comp_ctx->queued = tmpbuf;
@@ -318,7 +318,7 @@ static int rfc195x_add_data(struct comp_ctx *comp_ctx, const char *in_data, int
        if (comp_ctx->queued) {
                /* data already pending */
                memcpy(b_tail(comp_ctx->queued), in_data, in_len);
-               comp_ctx->queued->i += in_len;
+               b_add(comp_ctx->queued, in_len);
                return in_len;
        }
 
@@ -350,10 +350,10 @@ static int rfc195x_flush_or_finish(struct comp_ctx *comp_ctx, struct buffer *out
        out_len = out->i;
 
        if (in_ptr)
-               out->i += slz_encode(strm, b_tail(out), in_ptr, in_len, !finish);
+               b_add(out, slz_encode(strm, b_tail(out), in_ptr, in_len, !finish));
 
        if (finish)
-               out->i += slz_finish(strm, b_tail(out));
+               b_add(out, slz_finish(strm, b_tail(out)));
 
        out_len = out->i - out_len;
 
@@ -589,7 +589,7 @@ static int deflate_add_data(struct comp_ctx *comp_ctx, const char *in_data, int
                return -1;
 
        /* deflate update the available data out */
-       out->i += out_len - strm->avail_out;
+       b_add(out, out_len - strm->avail_out);
 
        return in_len - strm->avail_in;
 }
@@ -610,7 +610,7 @@ static int deflate_flush_or_finish(struct comp_ctx *comp_ctx, struct buffer *out
                return -1;
 
        out_len = b_room(out) - strm->avail_out;
-       out->i += out_len;
+       b_add(out, out_len);
 
        /* compression limit */
        if ((global.comp_rate_lim > 0 && (read_freq_ctr(&global.comp_bps_out) > global.comp_rate_lim)) ||    /* rate */
index 93653641ff5732950b7f21ad0ae00b6845a9a138..85abb8466d4907e75fed8e5d33a857564ad84790 100644 (file)
@@ -212,7 +212,7 @@ comp_http_data(struct stream *s, struct filter *filter, struct http_msg *msg)
                        memcpy(b_tail(tmpbuf)+block, buf->data, len-block);
                c_rew(chn, *nxt);
 
-               tmpbuf->i += len;
+               b_add(tmpbuf, len);
                ret        = len;
        }
        else {
@@ -770,10 +770,10 @@ http_compression_buffer_end(struct comp_state *st, struct stream *s,
        if (ib->i > 0) {
                left = ci_contig_data(chn);
                memcpy(ob->p + ob->i, ci_head(chn), left);
-               ob->i += left;
+               b_add(ob, left);
                if (ib->i - left) {
                        memcpy(ob->p + ob->i, ib->data, ib->i - left);
-                       ob->i += ib->i - left;
+                       b_add(ob, ib->i - left);
                }
        }
 
index 81772dbbcaa0154d7625b835ab3477e663bc2f4d..934c949b933572e4635684bf861d02c742146202 100644 (file)
@@ -2742,7 +2742,7 @@ static int h2_frt_decode_headers(struct h2s *h2s, struct buffer *buf, int count,
        /* now consume the input data */
        b_del(h2c->dbuf, h2c->dfl);
        h2c->st0 = H2_CS_FRAME_H;
-       buf->i += outlen;
+       b_add(buf, outlen);
 
        /* don't send it before returning data!
         * FIXME: should we instead try to send it much later, after the
@@ -3091,7 +3091,7 @@ static size_t h2s_frt_make_resp_headers(struct h2s *h2s, const struct buffer *bu
 
        /* commit the H2 response */
        h2c->mbuf->p = b_peek(h2c->mbuf, h2c->mbuf->o + outbuf.len);
-       h2c->mbuf->o += outbuf.len;
+       bo_add(h2c->mbuf, outbuf.len);
        h2s->flags |= H2_SF_HEADERS_SENT;
 
        /* for now we don't implemented CONTINUATION, so we wait for a
@@ -3337,7 +3337,7 @@ static size_t h2s_frt_make_resp_data(struct h2s *h2s, const struct buffer *buf,
 
        /* commit the H2 response */
        h2c->mbuf->p = b_peek(h2c->mbuf, h2c->mbuf->o + size + 9);
-       h2c->mbuf->o += size + 9;
+       bo_add(h2c->mbuf, size + 9);
 
        /* consume incoming H1 response */
        if (size > 0) {
index e0bfd1d995cc724aaefc1f1f5e2240c08f43e81c..375c453c5d429dc536d352ac4cc4e36a1540e058 100644 (file)
@@ -294,7 +294,7 @@ static size_t raw_sock_to_buf(struct connection *conn, struct buffer *buf, size_
                ret = recv(conn->handle.fd, b_tail(buf), try, 0);
 
                if (ret > 0) {
-                       buf->i += ret;
+                       b_add(buf, ret);
                        done += ret;
                        if (ret < try) {
                                /* unfortunately, on level-triggered events, POLL_HUP
index b4730271726a1079dc42afd9d19706fc2cf66f7c..9e3341a31b6b881cdc29d4cd1c82e97835dce435 100644 (file)
@@ -5374,7 +5374,7 @@ static size_t ssl_sock_to_buf(struct connection *conn, struct buffer *buf, size_
                        done++;
                        try--;
                        count--;
-                       buf->i++;
+                       b_add(buf, 1);
                        conn->tmp_early_data = -1;
                        continue;
                }
@@ -5421,7 +5421,7 @@ static size_t ssl_sock_to_buf(struct connection *conn, struct buffer *buf, size_
                        goto out_error;
                }
                if (ret > 0) {
-                       buf->i += ret;
+                       b_add(buf, ret);
                        done += ret;
                        count -= ret;
                }