istream-concat.c revision 4ce6338bf945cccfff9e4ce7cc6aa2246851b84a
e59faf65ce864fe95dc00f5d52b8323cdbd0608aTimo Sirainen/* Copyright (c) 2007 Dovecot authors, see the included COPYING file */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic void i_stream_concat_close(struct iostream_private *stream)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct concat_istream *cstream = (struct concat_istream *)stream;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen unsigned int i;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic void i_stream_concat_destroy(struct iostream_private *stream)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct concat_istream *cstream = (struct concat_istream *)stream;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen unsigned int i;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Siraineni_stream_concat_set_max_buffer_size(struct iostream_private *stream,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct concat_istream *cstream = (struct concat_istream *)stream;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen unsigned int i;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen i_stream_set_max_buffer_size(cstream->input[i], max_size);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic void i_stream_concat_read_next(struct concat_istream *cstream)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const unsigned char *data;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen cstream->cur_input = cstream->input[cstream->cur_idx];
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (cstream->istream.pos == cstream->istream.skip) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* we need to keep the current data */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen data = cstream->istream.buffer + cstream->istream.skip;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen data_size = cstream->istream.pos - cstream->istream.skip;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen cstream->istream.skip = cstream->istream.pos = 0;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* we already verified that the data size is less than the
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen maximum buffer size */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (!i_stream_get_buffer_space(&cstream->istream, data_size, &size))
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen memcpy(cstream->istream.w_buffer, data, data_size);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic ssize_t i_stream_concat_read(struct istream_private *stream)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct concat_istream *cstream = (struct concat_istream *)stream;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const unsigned char *data;
e6440616c02bb1404dc35debf45d9741260c7831Timo Sirainen /* we don't need the buffer anymore */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen data = i_stream_get_data(cstream->cur_input, &pos);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* need to read more */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (ret == -1 && stream->istream.stream_errno != 0) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* we either read something or we're at EOF */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen last_stream = cstream->input[cstream->cur_idx+1] == NULL;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen stream->istream.eof = cstream->cur_input->eof && last_stream;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen data = i_stream_get_data(cstream->cur_input, &pos);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (!i_stream_get_buffer_space(stream, pos, &size))
return ret;
if (*v_offset == 0) {
static const struct stat *
unsigned int count;