dovecot-2.2: istreams: Added default stat() implementation for f...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jun 29 09:15:33 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/89e0aad6ba88
changeset: 14701:89e0aad6ba88
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jun 29 09:15:26 2012 +0300
description:
istreams: Added default stat() implementation for filter streams.

diffstat:

 src/lib-mail/istream-attachment-extractor.c |   7 -------
 src/lib-mail/istream-binary-converter.c     |   7 -------
 src/lib-mail/istream-dot.c                  |   8 --------
 src/lib-mail/istream-nonuls.c               |   8 +-------
 src/lib-storage/index/istream-mail.c        |   9 +--------
 src/lib/istream-base64-encoder.c            |  13 -------------
 src/lib/istream-crlf.c                      |   8 --------
 src/lib/istream-limit.c                     |   1 -
 src/lib/istream-private.h                   |   1 +
 src/lib/istream-rawlog.c                    |   9 ++-------
 src/lib/istream-sized.c                     |   3 +--
 src/lib/istream.c                           |  11 +++++++++--
 12 files changed, 15 insertions(+), 70 deletions(-)

diffs (281 lines):

diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib-mail/istream-attachment-extractor.c
--- a/src/lib-mail/istream-attachment-extractor.c	Fri Jun 29 09:01:56 2012 +0300
+++ b/src/lib-mail/istream-attachment-extractor.c	Fri Jun 29 09:15:26 2012 +0300
@@ -619,12 +619,6 @@
 	return ret;
 }
 
-static const struct stat *
-i_stream_attachment_stat(struct istream_private *stream, bool exact)
-{
-	return i_stream_stat(stream->parent, exact);
-}
-
 static void i_stream_attachment_close(struct iostream_private *stream)
 {
 	struct attachment_istream *astream =
@@ -665,7 +659,6 @@
 	astream->istream.max_buffer_size = input->real_stream->max_buffer_size;
 
 	astream->istream.read = i_stream_attachment_read;
-	astream->istream.stat = i_stream_attachment_stat;
 	astream->istream.iostream.close = i_stream_attachment_close;
 
 	astream->istream.istream.readable_fd = FALSE;
diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib-mail/istream-binary-converter.c
--- a/src/lib-mail/istream-binary-converter.c	Fri Jun 29 09:01:56 2012 +0300
+++ b/src/lib-mail/istream-binary-converter.c	Fri Jun 29 09:15:26 2012 +0300
@@ -260,12 +260,6 @@
 	return new_size - old_size;
 }
 
-static const struct stat *
-i_stream_binary_converter_stat(struct istream_private *stream, bool exact)
-{
-	return i_stream_stat(stream->parent, exact);
-}
-
 static void i_stream_binary_converter_close(struct iostream_private *stream)
 {
 	struct binary_converter_istream *bstream =
@@ -286,7 +280,6 @@
 	bstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
 
 	bstream->istream.read = i_stream_binary_converter_read;
-	bstream->istream.stat = i_stream_binary_converter_stat;
 	bstream->istream.iostream.close = i_stream_binary_converter_close;
 
 	bstream->istream.istream.readable_fd = FALSE;
diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib-mail/istream-dot.c
--- a/src/lib-mail/istream-dot.c	Fri Jun 29 09:01:56 2012 +0300
+++ b/src/lib-mail/istream-dot.c	Fri Jun 29 09:15:26 2012 +0300
@@ -211,21 +211,13 @@
 	return ret;
 }
 
-static const struct stat *
-i_stream_dot_stat(struct istream_private *stream, bool exact)
-{
-	return i_stream_stat(stream->parent, exact);
-}
-
 struct istream *i_stream_create_dot(struct istream *input, bool send_last_lf)
 {
 	struct dot_istream *dstream;
 
 	dstream = i_new(struct dot_istream, 1);
 	dstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
-
 	dstream->istream.read = i_stream_dot_read;
-	dstream->istream.stat = i_stream_dot_stat;
 
 	dstream->istream.istream.readable_fd = FALSE;
 	dstream->istream.istream.blocking = input->blocking;
diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib-mail/istream-nonuls.c
--- a/src/lib-mail/istream-nonuls.c	Fri Jun 29 09:01:56 2012 +0300
+++ b/src/lib-mail/istream-nonuls.c	Fri Jun 29 09:15:26 2012 +0300
@@ -60,21 +60,15 @@
 	return size;
 }
 
-static const struct stat *
-i_stream_nonuls_stat(struct istream_private *stream, bool exact)
-{
-	return i_stream_stat(stream->parent, exact);
-}
-
 struct istream *i_stream_create_nonuls(struct istream *input, char replace_chr)
 {
 	struct nonuls_istream *nstream;
 
 	nstream = i_new(struct nonuls_istream, 1);
 	nstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
+	nstream->istream.stream_size_passthrough = TRUE;
 
 	nstream->istream.read = i_stream_nonuls_read;
-	nstream->istream.stat = i_stream_nonuls_stat;
 
 	nstream->istream.istream.readable_fd = FALSE;
 	nstream->istream.istream.blocking = input->blocking;
diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib-storage/index/istream-mail.c
--- a/src/lib-storage/index/istream-mail.c	Fri Jun 29 09:01:56 2012 +0300
+++ b/src/lib-storage/index/istream-mail.c	Fri Jun 29 09:15:26 2012 +0300
@@ -93,12 +93,6 @@
 	return ret;
 }
 
-static const struct stat *
-i_stream_mail_stat(struct istream_private *stream, bool exact)
-{
-	return i_stream_stat(stream->parent, exact);
-}
-
 struct istream *i_stream_create_mail(struct mail *mail, struct istream *input,
 				     bool input_has_body)
 {
@@ -110,10 +104,9 @@
 	mstream->expected_size = (uoff_t)-1;
 	(void)i_stream_mail_try_get_cached_size(mstream);
 	mstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
+	mstream->istream.stream_size_passthrough = TRUE;
 
-	mstream->istream.parent = input;
 	mstream->istream.read = i_stream_mail_read;
-	mstream->istream.stat = i_stream_mail_stat;
 
 	mstream->istream.istream.blocking = input->blocking;
 	mstream->istream.istream.seekable = input->seekable;
diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib/istream-base64-encoder.c
--- a/src/lib/istream-base64-encoder.c	Fri Jun 29 09:01:56 2012 +0300
+++ b/src/lib/istream-base64-encoder.c	Fri Jun 29 09:15:26 2012 +0300
@@ -120,17 +120,6 @@
 	return post_count - pre_count;
 }
 
-static const struct stat *
-i_stream_base64_encoder_stat(struct istream_private *stream, bool exact)
-{
-	if (exact) {
-		/* too much trouble to implement until it's actually needed */
-		i_panic("istream-base64-encoder: "
-			"stat() doesn't support getting exact size");
-	}
-	return i_stream_stat(stream->parent, exact);
-}
-
 static void
 i_stream_base64_encoder_seek(struct istream_private *stream,
 			     uoff_t v_offset, bool mark)
@@ -163,9 +152,7 @@
 	bstream->crlf = crlf;
 	bstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
 
-	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;
diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib/istream-crlf.c
--- a/src/lib/istream-crlf.c	Fri Jun 29 09:01:56 2012 +0300
+++ b/src/lib/istream-crlf.c	Fri Jun 29 09:15:26 2012 +0300
@@ -172,12 +172,6 @@
 	return ret;
 }
 
-static const struct stat *
-i_stream_crlf_stat(struct istream_private *stream, bool exact)
-{
-	return i_stream_stat(stream->parent, exact);
-}
-
 static struct istream *
 i_stream_create_crlf_full(struct istream *input, bool crlf)
 {
@@ -185,10 +179,8 @@
 
 	cstream = i_new(struct crlf_istream, 1);
 	cstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
-
 	cstream->istream.read = crlf ? i_stream_crlf_read_crlf :
 		i_stream_crlf_read_lf;
-	cstream->istream.stat = i_stream_crlf_stat;
 
 	cstream->istream.istream.readable_fd = FALSE;
 	cstream->istream.istream.blocking = input->blocking;
diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib/istream-limit.c
--- a/src/lib/istream-limit.c	Fri Jun 29 09:01:56 2012 +0300
+++ b/src/lib/istream-limit.c	Fri Jun 29 09:15:26 2012 +0300
@@ -117,7 +117,6 @@
 	lstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
 
 	lstream->istream.iostream.destroy = i_stream_limit_destroy;
-	lstream->istream.parent = input;
 	lstream->istream.read = i_stream_limit_read;
 	lstream->istream.stat = i_stream_limit_stat;
 	lstream->istream.get_size = i_stream_limit_get_size;
diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib/istream-private.h
--- a/src/lib/istream-private.h	Fri Jun 29 09:01:56 2012 +0300
+++ b/src/lib/istream-private.h	Fri Jun 29 09:15:26 2012 +0300
@@ -45,6 +45,7 @@
 
 	string_t *line_str; /* for i_stream_next_line() if w_buffer == NULL */
 	unsigned int return_nolf_line:1;
+	unsigned int stream_size_passthrough:1; /* stream is parent's size */
 };
 
 struct istream * ATTR_NOWARN_UNUSED_RESULT
diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib/istream-rawlog.c
--- a/src/lib/istream-rawlog.c	Fri Jun 29 09:01:56 2012 +0300
+++ b/src/lib/istream-rawlog.c	Fri Jun 29 09:15:26 2012 +0300
@@ -69,12 +69,6 @@
 	return ret;
 }
 
-static const struct stat *
-i_stream_rawlog_stat(struct istream_private *stream, bool exact)
-{
-	return i_stream_stat(stream->parent, exact);
-}
-
 struct istream *
 i_stream_create_rawlog(struct istream *input, const char *rawlog_path,
 		       int rawlog_fd, bool autoclose_fd)
@@ -86,13 +80,14 @@
 
 	rstream = i_new(struct rawlog_istream, 1);
 	rstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
+	rstream->istream.stream_size_passthrough = TRUE;
+
 	rstream->riostream.rawlog_path = i_strdup(rawlog_path);
 	rstream->riostream.rawlog_fd = rawlog_fd;
 	rstream->riostream.autoclose_fd = autoclose_fd;
 	rstream->riostream.write_timestamp = TRUE;
 
 	rstream->istream.read = i_stream_rawlog_read;
-	rstream->istream.stat = i_stream_rawlog_stat;
 	rstream->istream.iostream.close = i_stream_rawlog_close;
 	rstream->istream.iostream.destroy = i_stream_rawlog_destroy;
 
diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib/istream-sized.c
--- a/src/lib/istream-sized.c	Fri Jun 29 09:01:56 2012 +0300
+++ b/src/lib/istream-sized.c	Fri Jun 29 09:15:26 2012 +0300
@@ -71,7 +71,7 @@
 }
 
 static const struct stat *
-i_stream_sized_stat(struct istream_private *stream, bool sized ATTR_UNUSED)
+i_stream_sized_stat(struct istream_private *stream, bool exact ATTR_UNUSED)
 {
 	struct sized_istream *sstream = (struct sized_istream *)stream;
 	const struct stat *st;
@@ -96,7 +96,6 @@
 	sstream->size = size;
 	sstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
 
-	sstream->istream.parent = input;
 	sstream->istream.read = i_stream_sized_read;
 	sstream->istream.stat = i_stream_sized_stat;
 
diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib/istream.c
--- a/src/lib/istream.c	Fri Jun 29 09:01:56 2012 +0300
+++ b/src/lib/istream.c	Fri Jun 29 09:15:26 2012 +0300
@@ -601,9 +601,16 @@
 }
 
 static const struct stat *
-i_stream_default_stat(struct istream_private *stream, bool exact ATTR_UNUSED)
+i_stream_default_stat(struct istream_private *stream, bool exact)
 {
-	return &stream->statbuf;
+	if (stream->parent == NULL)
+		return &stream->statbuf;
+
+	if (exact && !stream->stream_size_passthrough) {
+		i_panic("istream %s: stat() doesn't support getting exact size",
+			i_stream_get_name(&stream->istream));
+	}
+	return i_stream_stat(stream->parent, exact);
 }
 
 static int


More information about the dovecot-cvs mailing list