b->o -= del;
}
-/* Returns the end of the input data in a buffer (pointer to next
- * insertion point).
- */
-static inline char *bi_end(const struct buffer *b)
-{
- char *ret = b->p + b->i;
-
- if (ret >= b->data + b->size)
- ret -= b->size;
- return ret;
-}
-
/* Returns the amount of output data that can contiguously be read at once */
static inline int bo_contig_data(const struct buffer *b)
{
{
if (buffer_len(b) == b->size)
return;
- *bi_end(b) = c;
+ *b_tail(b) = c;
b->i++;
}
if (half > len)
half = len;
- memcpy(bi_end(b), blk, half);
+ memcpy(b_tail(b), blk, half);
if (len > half)
memcpy(b_ptr(b, b->i + half), blk + half, len - half);
b->i += len;
delta = len - (end - pos);
- if (bi_end(b) + delta > b->data + b->size)
+ if (b_tail(b) + delta > b->data + b->size)
return 0; /* no space left */
if (buffer_not_empty(b) &&
- bi_end(b) + delta > b_head(b) &&
- b_head(b) >= bi_end(b))
+ b_tail(b) + delta > b_head(b) &&
+ b_head(b) >= b_tail(b))
return 0; /* no space left before wrapping data */
/* first, protect the end of the buffer */
- memmove(end + delta, end, bi_end(b) - end);
+ memmove(end + delta, end, b_tail(b) - end);
/* now, copy str over pos */
if (len)
delta = len + 2;
- if (bi_end(b) + delta >= b->data + b->size)
+ if (b_tail(b) + delta >= b->data + b->size)
return 0; /* no space left */
if (buffer_not_empty(b) &&
- bi_end(b) + delta > b_head(b) &&
- b_head(b) >= bi_end(b))
+ b_tail(b) + delta > b_head(b) &&
+ b_head(b) >= b_tail(b))
return 0; /* no space left before wrapping data */
/* first, protect the end of the buffer */
- memmove(pos + delta, pos, bi_end(b) - pos);
+ memmove(pos + delta, pos, b_tail(b) - pos);
/* now, copy str over pos */
if (len && str) {
/* buffer are aligned there, should be fine */
if (appctx->st0 == HTTP_CACHE_INIT) {
int len = first->len - sizeof(struct cache_entry);
- if ((shctx_row_data_get(shctx, first, (unsigned char *)bi_end(res->buf), sizeof(struct cache_entry), len)) != 0) {
+ if ((shctx_row_data_get(shctx, first, (unsigned char *)ci_tail(res), sizeof(struct cache_entry), len)) != 0) {
/* should never get there, because at the moment, a
* cache object can never be bigger than a buffer */
abort();
if (!channel_may_recv(chn))
return -1;
- *bi_end(chn->buf) = c;
+ *ci_tail(chn) = c;
chn->buf->i++;
chn->flags |= CF_READ_PARTIAL;
/* OK so the data fits in the buffer in one or two blocks */
max = bi_contig_space(chn->buf);
- memcpy(bi_end(chn->buf), blk, MIN(len, max));
+ memcpy(ci_tail(chn), blk, MIN(len, max));
if (len > max)
memcpy(chn->buf->data, blk + max, len - max);
*/
static int identity_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out)
{
- char *out_data = bi_end(out);
+ char *out_data = b_tail(out);
int out_len = out->size - buffer_len(out);
if (out_len < in_len)
return -1; /* no memory */
}
b_reset(tmpbuf);
- memcpy(bi_end(tmpbuf), comp_ctx->direct_ptr, comp_ctx->direct_len);
+ memcpy(b_tail(tmpbuf), comp_ctx->direct_ptr, comp_ctx->direct_len);
tmpbuf->i += comp_ctx->direct_len;
comp_ctx->direct_ptr = NULL;
comp_ctx->direct_len = 0;
if (comp_ctx->queued) {
/* data already pending */
- memcpy(bi_end(comp_ctx->queued), in_data, in_len);
+ memcpy(b_tail(comp_ctx->queued), in_data, in_len);
comp_ctx->queued->i += in_len;
return in_len;
}
out_len = out->i;
if (in_ptr)
- out->i += slz_encode(strm, bi_end(out), in_ptr, in_len, !finish);
+ out->i += slz_encode(strm, b_tail(out), in_ptr, in_len, !finish);
if (finish)
- out->i += slz_finish(strm, bi_end(out));
+ out->i += slz_finish(strm, b_tail(out));
out_len = out->i - out_len;
{
int ret;
z_stream *strm = &comp_ctx->strm;
- char *out_data = bi_end(out);
+ char *out_data = b_tail(out);
int out_len = out->size - buffer_len(out);
if (in_len <= 0)
strm->next_in = NULL;
strm->avail_in = 0;
- strm->next_out = (unsigned char *)bi_end(out);
+ strm->next_out = (unsigned char *)b_tail(out);
strm->avail_out = out->size - buffer_len(out);
ret = deflate(strm, flag);
c_adv(chn, *nxt);
block = ci_contig_data(chn);
- memcpy(bi_end(tmpbuf), ci_head(chn), block);
+ memcpy(b_tail(tmpbuf), ci_head(chn), block);
if (len > block)
- memcpy(bi_end(tmpbuf)+block, buf->data, len-block);
+ memcpy(b_tail(tmpbuf)+block, buf->data, len-block);
c_rew(chn, *nxt);
tmpbuf->i += len;
while (1) {
const char *p1 = NULL, *p2 = NULL;
const char *start = b_ptr(buf, msg->next + msg->sol);
- const char *stop = bi_end(buf);
+ const char *stop = b_tail(buf);
const char *ptr = start;
int bytes = 0;
/* OK now we have our header list in <list> */
msgf = (h2c->dff & H2_F_DATA_END_STREAM) ? 0 : H2_MSGF_BODY;
- outlen = h2_make_h1_request(list, bi_end(buf), try, &msgf);
+ outlen = h2_make_h1_request(list, b_tail(buf), try, &msgf);
if (outlen < 0) {
h2c_error(h2c, H2_ERR_COMPRESSION_ERROR);
req->flags |= CF_WAKE_WRITE;
return 0;
}
- if (unlikely(bi_end(req->buf) < b_ptr(req->buf, msg->next) ||
- bi_end(req->buf) > req->buf->data + req->buf->size - global.tune.maxrewrite))
+ if (unlikely(ci_tail(req) < b_ptr(req->buf, msg->next) ||
+ ci_tail(req) > req->buf->data + req->buf->size - global.tune.maxrewrite))
channel_slow_realign(req, trash.str);
}
return 0;
}
- if (unlikely(bi_end(rep->buf) < b_ptr(rep->buf, msg->next) ||
- bi_end(rep->buf) > rep->buf->data + rep->buf->size - global.tune.maxrewrite))
+ if (unlikely(ci_tail(rep) < b_ptr(rep->buf, msg->next) ||
+ ci_tail(rep) > rep->buf->data + rep->buf->size - global.tune.maxrewrite))
channel_slow_realign(rep, trash.str);
if (likely(msg->next < rep->buf->i))
if (try > count)
try = count;
- ret = recv(conn->handle.fd, bi_end(buf), try, 0);
+ ret = recv(conn->handle.fd, b_tail(buf), try, 0);
if (ret > 0) {
buf->i += ret;
try = count;
if (((conn->flags & (CO_FL_EARLY_SSL_HS | CO_FL_EARLY_DATA)) == CO_FL_EARLY_SSL_HS) &&
conn->tmp_early_data != -1) {
- *bi_end(buf) = conn->tmp_early_data;
+ *b_tail(buf) = conn->tmp_early_data;
done++;
try--;
count--;
size_t read_length;
ret = SSL_read_early_data(conn->xprt_ctx,
- bi_end(buf), try, &read_length);
+ b_tail(buf), try, &read_length);
if (ret == SSL_READ_EARLY_DATA_SUCCESS &&
read_length > 0)
conn->flags |= CO_FL_EARLY_DATA;
}
} else
#endif
- ret = SSL_read(conn->xprt_ctx, bi_end(buf), try);
+ ret = SSL_read(conn->xprt_ctx, b_tail(buf), try);
#ifdef OPENSSL_IS_BORINGSSL
if (conn->flags & CO_FL_EARLY_SSL_HS) {
if (SSL_in_early_data(conn->xprt_ctx)) {