istream-limit.c revision bdcb00145ad87765e3fd22d4ebc4d2c029a326b9
e59faf65ce864fe95dc00f5d52b8323cdbd0608aTimo Sirainen/* Copyright (c) 2003-2012 Dovecot authors, see the included COPYING file */
c99fe55d4535d839a6ad0735c4719e076a1adb2cTimo Sirainenstatic void i_stream_limit_destroy(struct iostream_private *stream)
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen struct limit_istream *lstream = (struct limit_istream *) stream;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen v_offset = lstream->istream.parent_start_offset +
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen v_offset > lstream->istream.parent->v_offset) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* get to same position in parent stream */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen i_stream_seek(lstream->istream.parent, v_offset);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstatic ssize_t i_stream_limit_read(struct istream_private *stream)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct limit_istream *lstream = (struct limit_istream *) stream;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen i_stream_seek(stream->parent, lstream->istream.parent_start_offset +
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen (stream->pos - stream->skip) >= lstream->v_size) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen stream->buffer = i_stream_get_data(stream->parent, &pos);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen if ((ret = i_stream_read(stream->parent)) == -2)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen stream->istream.stream_errno = stream->parent->stream_errno;
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainen stream->buffer = i_stream_get_data(stream->parent, &pos);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen left = lstream->v_size - stream->istream.v_offset;
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainen ret = pos > stream->pos ? (ssize_t)(pos - stream->pos) :
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstatic const struct stat *
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Siraineni_stream_limit_stat(struct istream_private *stream, bool exact)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct limit_istream *lstream = (struct limit_istream *) stream;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstatic int i_stream_limit_get_size(struct istream_private *stream,
a3fe8c0c54d87822f4b4f8f0d10caac611861b2bTimo Sirainen struct limit_istream *lstream = (struct limit_istream *) stream;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct istream *i_stream_create_limit(struct istream *input, uoff_t v_size)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen lstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
40a8e6948d662339c0c5e2c7abfb84ae7c1803fdTimo Sirainen lstream->istream.iostream.destroy = i_stream_limit_destroy;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen lstream->istream.get_size = i_stream_limit_get_size;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen lstream->istream.istream.readable_fd = input->readable_fd;
cd2ed64888b42b481cde6bb9548c8520516fa3e9Timo Sirainen lstream->istream.istream.blocking = input->blocking;
a3fe8c0c54d87822f4b4f8f0d10caac611861b2bTimo Sirainen lstream->istream.istream.seekable = input->seekable;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen return i_stream_create(&lstream->istream, input,