istream-qp-encoder.c revision 869e8af5b722032920698743b27e89e6abd170e7
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny/* Copyright (c) 2017 Dovecot authors, see the included COPYING file */
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zelenystatic void i_stream_qp_encoder_close(struct iostream_private *stream,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozekstatic ssize_t i_stream_qp_encoder_read(struct istream_private *stream)
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek const unsigned char *data;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (stream->pos >= bstream->istream.max_buffer_size) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek /* stream buffer still at maximum */
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek /* if something is already interpolated, return as much of it as
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek /* only return up to max_buffer_size bytes, even when buffer
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek actually has more, as not to confuse the caller */
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (bstream->buf->used <= bstream->istream.max_buffer_size) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek /* need to read more input */
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek ret = i_stream_read_more(stream->parent, &data, &size);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozeki_stream_qp_encoder_seek(struct istream_private *stream,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek /* seeking backwards - go back to beginning and seek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek forward from there. */
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek stream->parent_expected_offset = stream->parent_start_offset;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek i_stream_default_seek_nonseekable(stream, v_offset, mark);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozekstruct istream *i_stream_create_qp_encoder(struct istream *input,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek bstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek bstream->buf = buffer_create_dynamic(default_pool, 128);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek bstream->qp = qp_encoder_init(bstream->buf, ISTREAM_QP_ENCODER_MAX_LINE_LENGTH, flags);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek bstream->istream.iostream.close = i_stream_qp_encoder_close;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek bstream->istream.read = i_stream_qp_encoder_read;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek bstream->istream.seek = i_stream_qp_encoder_seek;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek bstream->istream.istream.blocking = input->blocking;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek bstream->istream.istream.seekable = input->seekable;