dovecot-2.0: stream-base64-encoder: Added support for seeking ba...

dovecot at dovecot.org dovecot at dovecot.org
Mon Nov 15 17:31:30 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/eb08ed7c6a7b
changeset: 12416:eb08ed7c6a7b
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Nov 15 15:31:26 2010 +0000
description:
stream-base64-encoder: Added support for seeking backwards in stream.

diffstat:

 src/lib/istream-base64-encoder.c |  19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diffs (36 lines):

diff -r 236ed6d5b391 -r eb08ed7c6a7b src/lib/istream-base64-encoder.c
--- a/src/lib/istream-base64-encoder.c	Mon Nov 15 15:31:02 2010 +0000
+++ b/src/lib/istream-base64-encoder.c	Mon Nov 15 15:31:26 2010 +0000
@@ -128,6 +128,24 @@
 	return i_stream_stat(stream->parent, exact);
 }
 
+static void
+i_stream_base64_encoder_seek(struct istream_private *stream,
+			     uoff_t v_offset, bool mark)
+{
+	struct base64_encoder_istream *bstream =
+		(struct base64_encoder_istream *)stream;
+
+	if (v_offset < stream->istream.v_offset) {
+		/* seeking backwards - go back to beginning and seek
+		   forward from there. */
+		stream->parent_expected_offset = stream->parent_start_offset;
+		stream->skip = stream->pos = 0;
+		stream->istream.v_offset = 0;
+		bstream->cur_line_len = 0;
+	}
+	i_stream_default_seek(stream, v_offset, mark);
+}
+
 struct istream *
 i_stream_create_base64_encoder(struct istream *input,
 			       unsigned int chars_per_line, bool crlf)
@@ -144,6 +162,7 @@
 	bstream->istream.parent = input;
 	bstream->istream.read = i_stream_base64_encoder_read;
 	bstream->istream.stat = i_stream_base64_encoder_stat;
+	bstream->istream.seek = i_stream_base64_encoder_seek;
 
 	bstream->istream.istream.readable_fd = FALSE;
 	bstream->istream.istream.blocking = input->blocking;


More information about the dovecot-cvs mailing list