]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: channel/buffer: replace b_{adv,rew} with c_{adv,rew}
authorWilly Tarreau <w@1wt.eu>
Wed, 6 Jun 2018 05:13:22 +0000 (07:13 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:40 +0000 (16:23 +0200)
These ones manipulate the output data count which will be specific to
the channel soon, so prepare the call points to use the channel only.
The b_* functions are now unused and were removed.

12 files changed:
doc/internals/filters.txt
include/common/buffer.h
include/proto/channel.h
src/backend.c
src/cache.c
src/channel.c
src/filters.c
src/flt_http_comp.c
src/flt_trace.c
src/hlua.c
src/proto_http.c
src/stream_interface.c

index 1e4d40a427681dfebeb944643be776dff2369fbe..75c640ce7e1466aa210c47ad35f40222cfb2cfd2 100644 (file)
@@ -1207,14 +1207,14 @@ data itself, i.e. the buffer offsets. For a HTTP message, you also must update
         if (avail > 10 and /* ...Some condition... */) {
             /* Move the buffer forward to have buf->p pointing on unparsed
              * data */
-            b_adv(msg->chn->buf, flt_rsp_nxt(filter));
+            c_adv(msg->chn, flt_rsp_nxt(filter));
 
             /* Skip first 10 bytes. To simplify this example, we consider a
              * non-wrapping buffer  */
             memmove(buf->p + 10, buf->p, avail - 10);
 
             /* Restore buf->p value */
-            b_rew(msg->chn->buf, flt_rsp_nxt(filter));
+            c_rew(msg->chn, flt_rsp_nxt(filter));
 
             /* Now update other filters */
             flt_change_next_size(filter, msg->chn, -10);
@@ -1240,14 +1240,14 @@ data itself, i.e. the buffer offsets. For a HTTP message, you also must update
         if (len > 10 and /* ...Some condition... */) {
             /* Move the buffer forward to have buf->p pointing on non-forwarded
              * data */
-            b_adv(msg->chn->buf, flt_rsp_fwd(filter));
+            c_adv(msg->chn, flt_rsp_fwd(filter));
 
             /* Skip first 10 bytes. To simplify this example, we consider a
              * non-wrapping buffer  */
             memmove(buf->p + 10, buf->p, len - 10);
 
             /* Restore buf->p value */
-            b_rew(msg->chn->buf, flt_rsp_fwd(filter));
+            c_rew(msg->chn, flt_rsp_fwd(filter));
 
             /* Now update other filters */
             flt_change_forward_size(filter, msg->chn, -10);
index f8e52322ab27f09e87978170094b6a2dbc1381a2..d7687f99dfe2ca36fa44e299f31ba73b78b4d405 100644 (file)
@@ -105,29 +105,6 @@ static inline void bo_del(struct buffer *b, unsigned int del)
        b->o -= del;
 }
 
-/* Advances the buffer by <adv> bytes, which means that the buffer
- * pointer advances, and that as many bytes from in are transferred
- * to out. The caller is responsible for ensuring that adv is always
- * smaller than or equal to b->i.
- */
-static inline void b_adv(struct buffer *b, unsigned int adv)
-{
-       b->i -= adv;
-       b->o += adv;
-       b->p = b_ptr(b, adv);
-}
-
-/* Rewinds the buffer by <adv> bytes, which means that the buffer pointer goes
- * backwards, and that as many bytes from out are moved to in. The caller is
- * responsible for ensuring that adv is always smaller than or equal to b->o.
- */
-static inline void b_rew(struct buffer *b, unsigned int adv)
-{
-       b->i += adv;
-       b->o -= adv;
-       b->p = b_ptr(b, (int)-adv);
-}
-
 /* Returns the start of the input data in a buffer */
 static inline char *bi_ptr(const struct buffer *b)
 {
index 4e5b90b3005ecde52a0af71e89a169ff7b7707d9..9429689ab7f3e17ade8ec642ec701c036fee2f88 100644 (file)
@@ -341,7 +341,7 @@ static inline unsigned long long channel_forward(struct channel *chn, unsigned l
 
                if (bytes32 <= chn->buf->i) {
                        /* OK this amount of bytes might be forwarded at once */
-                       b_adv(chn->buf, bytes32);
+                       c_adv(chn, bytes32);
                        return bytes;
                }
        }
@@ -351,7 +351,7 @@ static inline unsigned long long channel_forward(struct channel *chn, unsigned l
 /* Forwards any input data and marks the channel for permanent forwarding */
 static inline void channel_forward_forever(struct channel *chn)
 {
-       b_adv(chn->buf, chn->buf->i);
+       c_adv(chn, chn->buf->i);
        chn->to_forward = CHN_INFINITE_FORWARD;
 }
 
index 8473efbd80831546069e5e4736706d851a08a07a..70972b437b81decb9cd521f15126bc32b7be89e1 100644 (file)
@@ -485,12 +485,12 @@ static struct server *get_server_rch(struct stream *s)
 
        memset(&smp, 0, sizeof(smp));
 
-       b_rew(s->req.buf, rewind = s->req.buf->o);
+       c_rew(&s->req, rewind = s->req.buf->o);
 
        ret = fetch_rdp_cookie_name(s, &smp, px->hh_name, px->hh_len);
        len = smp.data.u.str.len;
 
-       b_adv(s->req.buf, rewind);
+       c_adv(&s->req, rewind);
 
        if (ret == 0 || (smp.flags & SMP_F_MAY_CHANGE) || len == 0)
                return NULL;
@@ -1020,13 +1020,13 @@ static void assign_tproxy_address(struct stream *s)
                        ((struct sockaddr_in *)&srv_conn->addr.from)->sin_port = 0;
                        ((struct sockaddr_in *)&srv_conn->addr.from)->sin_addr.s_addr = 0;
 
-                       b_rew(s->req.buf, rewind = http_hdr_rewind(&s->txn->req));
+                       c_rew(&s->req, rewind = http_hdr_rewind(&s->txn->req));
                        if (http_get_hdr(&s->txn->req, src->bind_hdr_name, src->bind_hdr_len,
                                         &s->txn->hdr_idx, src->bind_hdr_occ, NULL, &vptr, &vlen)) {
                                ((struct sockaddr_in *)&srv_conn->addr.from)->sin_addr.s_addr =
                                        htonl(inetaddr_host_lim(vptr, vptr + vlen));
                        }
-                       b_adv(s->req.buf, rewind);
+                       c_adv(&s->req, rewind);
                }
                break;
        default:
@@ -1261,12 +1261,12 @@ int connect_server(struct stream *s)
                         * output data.
                         */
                        rewind = s->txn ? http_hdr_rewind(&s->txn->req) : s->req.buf->o;
-                       b_rew(s->req.buf, rewind);
+                       c_rew(&s->req, rewind);
 
                        smp = sample_fetch_as_type(s->be, s->sess, s, SMP_OPT_DIR_REQ | SMP_OPT_FINAL, srv->ssl_ctx.sni, SMP_T_STR);
 
                        /* restore the pointers */
-                       b_adv(s->req.buf, rewind);
+                       c_adv(&s->req, rewind);
 
                        if (smp_make_safe(smp)) {
                                ssl_sock_set_servername(srv_conn, smp->data.u.str.str);
index c72d9dee9971089e8355d01055ef6bbd0d41c983..aec9ba670e96200ace0b7a9736f1957dcc09b2f2 100644 (file)
@@ -221,13 +221,13 @@ cache_store_http_forward_data(struct stream *s, struct filter *filter,
                                pool_free(pool_head_cache_st, st);
                        } else {
                                /* Skip remaining headers to fill the cache */
-                               b_adv(msg->chn->buf, st->hdrs_len);
+                               c_adv(msg->chn, st->hdrs_len);
                                ret = shctx_row_data_append(shctx,
                                                            st->first_block,
                                                            (unsigned char *)bi_ptr(msg->chn->buf),
                                                            MIN(bi_contig_data(msg->chn->buf), len - st->hdrs_len));
                                /* Rewind the buffer to forward all data */
-                               b_rew(msg->chn->buf, st->hdrs_len);
+                               c_rew(msg->chn, st->hdrs_len);
                                st->hdrs_len = 0;
                                if (ret)
                                        goto disable_cache;
index 7235ffc4b914214e2e0f96e5edc3f315f3907407..0ddfc6fa7e6fe84e404eae26f0834dc963cca0a6 100644 (file)
@@ -38,7 +38,7 @@ unsigned long long __channel_forward(struct channel *chn, unsigned long long byt
         * regular code paths.
         */
        if (unlikely(chn->to_forward == CHN_INFINITE_FORWARD)) {
-               b_adv(chn->buf, chn->buf->i);
+               c_adv(chn, chn->buf->i);
                return bytes;
        }
 
@@ -49,7 +49,7 @@ unsigned long long __channel_forward(struct channel *chn, unsigned long long byt
 
        /* transfer as much as we can of buf->i */
        forwarded = MIN(chn->buf->i, budget);
-       b_adv(chn->buf, forwarded);
+       c_adv(chn, forwarded);
        budget -= forwarded;
 
        if (!budget)
@@ -125,7 +125,7 @@ int ci_putchr(struct channel *chn, char c)
        if (chn->to_forward >= 1) {
                if (chn->to_forward != CHN_INFINITE_FORWARD)
                        chn->to_forward--;
-               b_adv(chn->buf, 1);
+               c_adv(chn, 1);
        }
 
        chn->total++;
@@ -180,7 +180,7 @@ int ci_putblk(struct channel *chn, const char *blk, int len)
                                fwd = chn->to_forward;
                        chn->to_forward -= fwd;
                }
-               b_adv(chn->buf, fwd);
+               c_adv(chn, fwd);
        }
 
        /* notify that some data was read from the SI into the buffer */
@@ -223,7 +223,7 @@ struct buffer *ci_swpbuf(struct channel *chn, struct buffer *buf)
                                fwd = chn->to_forward;
                        chn->to_forward -= fwd;
                }
-               b_adv(chn->buf, fwd);
+               c_adv(chn, fwd);
        }
 
        /* notify that some data was read from the SI into the buffer */
index 1bd50c331ff0e957663a8ec252fc22c453c91ae0..26bed64f52556d5ec2b8895a6ba5fbf95bb18463 100644 (file)
@@ -1089,7 +1089,7 @@ flt_xfer_data(struct stream *s, struct channel *chn, unsigned int an_bit)
                goto end;
 
        /* Consume data that all filters consider as forwarded. */
-       b_adv(chn->buf, ret);
+       c_adv(chn, ret);
 
        /* Stop waiting data if the input in closed and no data is pending or if
         * the output is closed. */
index ca2ab7cde2fa0f0a465d5a7024db0a92c58abc2f..df59d7d55788ba0028e21761d2db54b5efc46658 100644 (file)
@@ -177,7 +177,8 @@ static int
 comp_http_data(struct stream *s, struct filter *filter, struct http_msg *msg)
 {
        struct comp_state *st = filter->ctx;
-       struct buffer     *buf = msg->chn->buf;
+       struct channel    *chn = msg->chn;
+       struct buffer     *buf = chn->buf;
        unsigned int      *nxt = &flt_rsp_nxt(filter);
        unsigned int       len;
        int                ret;
@@ -190,9 +191,9 @@ comp_http_data(struct stream *s, struct filter *filter, struct http_msg *msg)
                unsigned int fwd = flt_rsp_fwd(filter) + st->hdrs_len;
 
                b_reset(tmpbuf);
-               b_adv(buf, fwd);
+               c_adv(chn, fwd);
                ret = http_compression_buffer_init(buf, zbuf);
-               b_rew(buf, fwd);
+               c_rew(chn, fwd);
                if (ret < 0) {
                        msg->chn->flags |= CF_WAKE_WRITE;
                        return 0;
@@ -204,20 +205,20 @@ comp_http_data(struct stream *s, struct filter *filter, struct http_msg *msg)
 
                len = MIN(tmpbuf->size - buffer_len(tmpbuf), len);
 
-               b_adv(buf, *nxt);
+               c_adv(chn, *nxt);
                block = bi_contig_data(buf);
                memcpy(bi_end(tmpbuf), bi_ptr(buf), block);
                if (len > block)
                        memcpy(bi_end(tmpbuf)+block, buf->data, len-block);
-               b_rew(buf, *nxt);
+               c_rew(chn, *nxt);
 
                tmpbuf->i += len;
                ret        = len;
        }
        else {
-               b_adv(buf, *nxt);
+               c_adv(chn, *nxt);
                ret = http_compression_buffer_add_data(st, buf, zbuf, len);
-               b_rew(buf, *nxt);
+               c_rew(chn, *nxt);
                if (ret < 0)
                        return ret;
        }
@@ -237,13 +238,13 @@ comp_http_chunk_trailers(struct stream *s, struct filter *filter,
 
        if (!st->initialized) {
                if (!st->finished) {
-                       struct buffer *buf = msg->chn->buf;
+                       struct channel *chn = msg->chn;
                        unsigned int   fwd = flt_rsp_fwd(filter) + st->hdrs_len;
 
                        b_reset(tmpbuf);
-                       b_adv(buf, fwd);
-                       http_compression_buffer_init(buf, zbuf);
-                       b_rew(buf, fwd);
+                       c_adv(chn, fwd);
+                       http_compression_buffer_init(chn->buf, zbuf);
+                       c_rew(chn, fwd);
                        st->initialized = 1;
                }
        }
@@ -305,9 +306,9 @@ comp_http_forward_data(struct stream *s, struct filter *filter,
        }
 
        st->consumed = len - st->hdrs_len - st->tlrs_len;
-       b_adv(msg->chn->buf, flt_rsp_fwd(filter) + st->hdrs_len);
+       c_adv(msg->chn, flt_rsp_fwd(filter) + st->hdrs_len);
        ret = http_compression_buffer_end(st, s, msg->chn, &zbuf, msg->msg_state >= HTTP_MSG_TRAILERS);
-       b_rew(msg->chn->buf, flt_rsp_fwd(filter) + st->hdrs_len);
+       c_rew(msg->chn, flt_rsp_fwd(filter) + st->hdrs_len);
        if (ret < 0)
                return ret;
 
@@ -762,7 +763,7 @@ http_compression_buffer_end(struct comp_state *st, struct stream *s,
        }
 
        /* copy the remaining data in the tmp buffer. */
-       b_adv(ib, st->consumed);
+       c_adv(chn, st->consumed);
        if (ib->i > 0) {
                left = bi_contig_data(ib);
                memcpy(ob->p + ob->i, bi_ptr(ib), left);
index fa26de1fd34fb3a34228efc0845cb364b7bcd199..f088340b7686d08a4018594a38451316a531f47a 100644 (file)
@@ -465,9 +465,9 @@ trace_http_forward_data(struct stream *s, struct filter *filter,
                   FLT_NXT(filter, msg->chn), FLT_FWD(filter, msg->chn), ret);
 
        if (conf->hexdump) {
-               b_adv(msg->chn->buf, FLT_FWD(filter, msg->chn));
+               c_adv(msg->chn, FLT_FWD(filter, msg->chn));
                trace_hexdump(msg->chn->buf, ret);
-               b_rew(msg->chn->buf, FLT_FWD(filter, msg->chn));
+               c_rew(msg->chn, FLT_FWD(filter, msg->chn));
        }
 
        if ((ret != len) ||
@@ -515,9 +515,9 @@ trace_tcp_forward_data(struct stream *s, struct filter *filter, struct channel *
                   FLT_FWD(filter, chn), ret);
 
        if (conf->hexdump) {
-               b_adv(chn->buf, FLT_FWD(filter, chn));
+               c_adv(chn, FLT_FWD(filter, chn));
                trace_hexdump(chn->buf, ret);
-               b_rew(chn->buf, FLT_FWD(filter, chn));
+               c_rew(chn, FLT_FWD(filter, chn));
        }
 
        if (ret != len)
index f8170062e992f09e4767e894b6eb9518f8d5b72d..967f05e3ab66592ecb544bc6703c0955d01a1367 100644 (file)
@@ -3049,7 +3049,7 @@ __LJMP static int hlua_channel_send_yield(lua_State *L, int status, lua_KContext
        /* buffer replace considers that the input part is filled.
         * so, I must forward these new data in the output part.
         */
-       b_adv(chn->buf, max);
+       c_adv(chn, max);
 
        l += max;
        lua_pop(L, 1);
index 67598e58a8cd9156be8b5236e54a9024bb11c0e0..a009d949cce3fc32095db8dff886cb38a706187f 100644 (file)
@@ -1108,12 +1108,12 @@ void http_perform_server_redirect(struct stream *s, struct stream_interface *si)
         * to temporarily rewind the buffer.
         */
        txn = s->txn;
-       b_rew(s->req.buf, rewind = http_hdr_rewind(&txn->req));
+       c_rew(&s->req, rewind = http_hdr_rewind(&txn->req));
 
        path = http_get_path(txn);
        len = buffer_count(s->req.buf, path, b_ptr(s->req.buf, txn->req.sl.rq.u + txn->req.sl.rq.u_l));
 
-       b_adv(s->req.buf, rewind);
+       c_adv(&s->req, rewind);
 
        if (!path)
                return;
@@ -4251,7 +4251,7 @@ int http_send_name_header(struct http_txn *txn, struct proxy* be, const char* sr
        old_o = http_hdr_rewind(&txn->req);
        if (old_o) {
                /* The request was already skipped, let's restore it */
-               b_rew(chn->buf, old_o);
+               c_rew(chn, old_o);
                txn->req.next += old_o;
                txn->req.sov += old_o;
        }
@@ -4278,7 +4278,7 @@ int http_send_name_header(struct http_txn *txn, struct proxy* be, const char* sr
                 * so we don't have to adjust ->sol.
                 */
                old_o += chn->buf->i - old_i;
-               b_adv(chn->buf, old_o);
+               c_adv(chn, old_o);
                txn->req.next -= old_o;
                txn->req.sov  -= old_o;
        }
@@ -6289,7 +6289,7 @@ http_msg_forward_body(struct stream *s, struct http_msg *msg)
        ret = FLT_STRM_DATA_CB(s, chn, flt_http_forward_data(s, msg, msg->next),
                               /* default_ret */ msg->next,
                               /* on_error    */ goto error);
-       b_adv(chn->buf, ret);
+       c_adv(chn, ret);
        msg->next -= ret;
        if (unlikely(!(chn->flags & CF_WROTE_DATA) || msg->sov > 0))
                msg->sov -= ret;
@@ -6309,7 +6309,7 @@ http_msg_forward_body(struct stream *s, struct http_msg *msg)
        ret = FLT_STRM_DATA_CB(s, chn, flt_http_forward_data(s, msg, msg->next),
                               /* default_ret */ msg->next,
                               /* on_error    */ goto error);
-       b_adv(chn->buf, ret);
+       c_adv(chn, ret);
        msg->next -= ret;
        if (!(chn->flags & CF_WROTE_DATA) || msg->sov > 0)
                msg->sov -= ret;
@@ -6420,7 +6420,7 @@ http_msg_forward_chunked_body(struct stream *s, struct http_msg *msg)
        ret = FLT_STRM_DATA_CB(s, chn, flt_http_forward_data(s, msg, msg->next),
                          /* default_ret */ msg->next,
                          /* on_error    */ goto error);
-       b_adv(chn->buf, ret);
+       c_adv(chn, ret);
        msg->next -= ret;
        if (unlikely(!(chn->flags & CF_WROTE_DATA) || msg->sov > 0))
                msg->sov -= ret;
@@ -6439,7 +6439,7 @@ http_msg_forward_chunked_body(struct stream *s, struct http_msg *msg)
        ret = FLT_STRM_DATA_CB(s, chn, flt_http_forward_data(s, msg, msg->next),
                          /* default_ret */ msg->next,
                          /* on_error    */ goto error);
-       b_adv(chn->buf, ret);
+       c_adv(chn, ret);
        msg->next -= ret;
        if (!(chn->flags & CF_WROTE_DATA) || msg->sov > 0)
                msg->sov -= ret;
index a78694f78454a9f8b1086420fc4e21e271f3a1dd..62cbf71f3e24ee47905704c3397c3139db0cf601 100644 (file)
@@ -1203,7 +1203,7 @@ static void si_cs_recv_cb(struct conn_stream *cs)
                                        fwd = ic->to_forward;
                                ic->to_forward -= fwd;
                        }
-                       b_adv(ic->buf, fwd);
+                       c_adv(ic, fwd);
                }
 
                ic->flags |= CF_READ_PARTIAL;