bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2011-2018 Dovecot authors, see the included COPYING file */
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainenstatic void i_stream_rawlog_close(struct iostream_private *stream,
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen struct rawlog_istream *rstream = (struct rawlog_istream *)stream;
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainenstatic void i_stream_rawlog_destroy(struct iostream_private *stream)
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen struct rawlog_istream *rstream = (struct rawlog_istream *)stream;
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen v_offset = rstream->istream.parent_start_offset +
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen v_offset > rstream->istream.parent->v_offset) {
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen /* get to same position in parent stream */
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen i_stream_seek(rstream->istream.parent, v_offset);
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainenstatic ssize_t i_stream_rawlog_read(struct istream_private *stream)
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen struct rawlog_istream *rstream = (struct rawlog_istream *)stream;
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen i_stream_seek(stream->parent, rstream->istream.parent_start_offset +
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen stream->buffer = i_stream_get_data(stream->parent, &pos);
bcd286622779a93f809b11993db0550f8c7cc9b5Timo Sirainen if ((ret = i_stream_read_memarea(stream->parent)) == -2)
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen stream->istream.stream_errno = stream->parent->stream_errno;
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen stream->buffer = i_stream_get_data(stream->parent, &pos);
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Siraineni_stream_create_rawlog(struct istream *input, const char *rawlog_path,
f1ed4fa248aaf6841ba638b9d66b2738d9f7aa18Timo Sirainen int rawlog_fd, enum iostream_rawlog_flags flags)
76d4ff1c1b31a1a09f6cbfe613a8d0efe62cbfd2Timo Sirainen bool autoclose_fd = (flags & IOSTREAM_RAWLOG_FLAG_AUTOCLOSE) != 0;
e93184a9055c2530366dfe617e07199603c399ddMartti Rannanjärvi o_stream_create_fd_autoclose(&rawlog_fd, 0) :
76d4ff1c1b31a1a09f6cbfe613a8d0efe62cbfd2Timo Sirainen return i_stream_create_rawlog_from_stream(input, rawlog_output, flags);
76d4ff1c1b31a1a09f6cbfe613a8d0efe62cbfd2Timo Siraineni_stream_create_rawlog_from_stream(struct istream *input,
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen rstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
5df8396a7cbad0b38b83a86667fb3d4c223f6f7cTimo Sirainen rstream->istream.stream_size_passthrough = TRUE;
76d4ff1c1b31a1a09f6cbfe613a8d0efe62cbfd2Timo Sirainen rstream->riostream.rawlog_output = rawlog_output;
f1ed4fa248aaf6841ba638b9d66b2738d9f7aa18Timo Sirainen iostream_rawlog_init(&rstream->riostream, flags, TRUE);
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen rstream->istream.iostream.close = i_stream_rawlog_close;
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen rstream->istream.iostream.destroy = i_stream_rawlog_destroy;
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen rstream->istream.istream.readable_fd = input->readable_fd;
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen rstream->istream.istream.blocking = input->blocking;
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen rstream->istream.istream.seekable = input->seekable;