bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2003-2018 Dovecot authors, see the included COPYING file */
4aa7fe81503a20bc972ae625da4dd9e6996fbdbfTimo Sirainenstatic void i_stream_limit_destroy(struct iostream_private *stream)
4aa7fe81503a20bc972ae625da4dd9e6996fbdbfTimo Sirainen struct limit_istream *lstream = (struct limit_istream *) stream;
4aa7fe81503a20bc972ae625da4dd9e6996fbdbfTimo Sirainen v_offset = lstream->istream.parent_start_offset +
4aa7fe81503a20bc972ae625da4dd9e6996fbdbfTimo Sirainen v_offset > lstream->istream.parent->v_offset) {
4aa7fe81503a20bc972ae625da4dd9e6996fbdbfTimo Sirainen /* get to same position in parent stream */
4aa7fe81503a20bc972ae625da4dd9e6996fbdbfTimo Sirainen i_stream_seek(lstream->istream.parent, v_offset);
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainenstatic ssize_t i_stream_limit_read(struct istream_private *stream)
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen struct limit_istream *lstream = (struct limit_istream *) stream;
3f8303bae0f70df6db9337ad1d1476d290f9b1a3Timo Sirainen i_stream_seek(stream->parent, lstream->istream.parent_start_offset +
8887a9bb6d2e3f664cf741b763643a0e5610fa4dTimo Sirainen (stream->pos - stream->skip) >= lstream->v_size) {
8887a9bb6d2e3f664cf741b763643a0e5610fa4dTimo Sirainen stream->buffer = i_stream_get_data(stream->parent, &pos);
bcd286622779a93f809b11993db0550f8c7cc9b5Timo Sirainen if ((ret = i_stream_read_memarea(stream->parent)) == -2)
8887a9bb6d2e3f664cf741b763643a0e5610fa4dTimo Sirainen stream->istream.stream_errno = stream->parent->stream_errno;
8887a9bb6d2e3f664cf741b763643a0e5610fa4dTimo Sirainen stream->buffer = i_stream_get_data(stream->parent, &pos);
8887a9bb6d2e3f664cf741b763643a0e5610fa4dTimo Sirainen left = lstream->v_size - stream->istream.v_offset;
8887a9bb6d2e3f664cf741b763643a0e5610fa4dTimo Sirainen ret = pos > stream->pos ? (ssize_t)(pos - stream->pos) :
a94936bafd127680184da114c6a177b37ff656e5Timo Siraineni_stream_limit_stat(struct istream_private *stream, bool exact)
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen struct limit_istream *lstream = (struct limit_istream *) stream;
2c0f1cb7a0564d48ec43c7315ea46ea38d2abd19Timo Sirainen if (i_stream_stat(stream->parent, exact, &st) < 0) {
2c0f1cb7a0564d48ec43c7315ea46ea38d2abd19Timo Sirainen stream->istream.stream_errno = stream->parent->stream_errno;
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainenstatic int i_stream_limit_get_size(struct istream_private *stream,
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainen struct limit_istream *lstream = (struct limit_istream *) stream;
01f4ee4a0243f3fe9af763e1a540cd5cff0d63f5Timo Sirainen if (i_stream_stat(&stream->istream, exact, &st) < 0)
10c96a244935de4add8213ba0b894178dfb889a5Timo Sirainenstruct istream *i_stream_create_limit(struct istream *input, uoff_t v_size)
597dba3488c648ffb375ee4a552bd52ac4346979Timo Sirainen lstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
4aa7fe81503a20bc972ae625da4dd9e6996fbdbfTimo Sirainen lstream->istream.iostream.destroy = i_stream_limit_destroy;
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainen lstream->istream.get_size = i_stream_limit_get_size;
da2aa032ccfa8e7e4a4380ef738014549f4d2c2dTimo Sirainen lstream->istream.istream.readable_fd = input->readable_fd;
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen lstream->istream.istream.blocking = input->blocking;
411d6baa37f31d90730e90c4a28c43e1974bbe58Timo Sirainen lstream->istream.istream.seekable = input->seekable;
9511a40d933181045343110c8101b75887062aaeTimo Sirainen return i_stream_create(&lstream->istream, input,