istream-metawrap.c revision 2c0f1cb7a0564d48ec43c7315ea46ea38d2abd19
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync/* Copyright (c) 2007-2015 Dovecot authors, see the included COPYING file */
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsyncstatic int metadata_header_read(struct metawrap_istream *mstream)
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync while ((line = i_stream_read_next_line(mstream->istream.parent)) != NULL) {
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync if (p == NULL) {
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync "Metadata header line is missing ':'");
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync *p++ = '\0';
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncstatic ssize_t i_stream_metawrap_read(struct istream_private *stream)
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync struct metawrap_istream *mstream = (struct metawrap_istream *)stream;
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync i_stream_seek(stream->parent, mstream->start_offset +
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync /* this stream is kind of silently skipping over the metadata */
319b6c2f1a5b5420b0a7fbef89477984cec16007vboxsync i_stream_seek(&stream->istream, mstream->pending_seek);
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync /* after metadata header it's all just passthrough */
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync return i_stream_read_copy_from_parent(&stream->istream);
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsynci_stream_metawrap_seek(struct istream_private *stream,
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync struct metawrap_istream *mstream = (struct metawrap_istream *)stream;
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync /* already read through metadata. we can skip directly. */
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync /* we need to read through the metadata first */
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsyncstatic int i_stream_metawrap_stat(struct istream_private *stream, bool exact)
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync struct metawrap_istream *mstream = (struct metawrap_istream *)stream;
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync if (i_stream_stat(stream->parent, exact, &st) < 0) {
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync stream->istream.stream_errno = stream->parent->stream_errno;
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync if (ret == 0) {
3b0af6c6de3509194973be62078331fc930175f7vboxsync i_assert((uoff_t)stream->statbuf.st_size >= mstream->start_offset);
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync mstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync mstream->istream.stat = input->seekable ? i_stream_metawrap_stat : NULL;
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync mstream->istream.istream.readable_fd = input->readable_fd;
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync mstream->istream.istream.blocking = input->blocking;