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);
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);
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)
{
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;
}
}
/* 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;
}
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;
((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:
* 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);
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;
* 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;
}
/* 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)
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++;
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 */
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 */
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. */
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;
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;
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;
}
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;
}
}
}
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;
}
/* 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);
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) ||
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)
/* 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);
* 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;
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;
}
* 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;
}
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;
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;
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;
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;
fwd = ic->to_forward;
ic->to_forward -= fwd;
}
- b_adv(ic->buf, fwd);
+ c_adv(ic, fwd);
}
ic->flags |= CF_READ_PARTIAL;