dovecot-2.2: Renamed istream-attachment to istream-sized.
dovecot at dovecot.org
dovecot at dovecot.org
Thu Jun 28 01:02:11 EEST 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/9774ae8fff97
changeset: 14692:9774ae8fff97
user: Timo Sirainen <tss at iki.fi>
date: Thu Jun 28 01:01:58 2012 +0300
description:
Renamed istream-attachment to istream-sized.
The code didn't really assume anything about the input being an attachment,
so this allows reusing the stream for other purposes.
diffstat:
src/lib-storage/index/Makefile.am | 2 -
src/lib-storage/index/dbox-common/dbox-attachment.c | 4 +-
src/lib-storage/index/istream-attachment.c | 124 --------------------
src/lib-storage/index/istream-attachment.h | 6 -
src/lib/Makefile.am | 2 +
src/lib/istream-sized.c | 121 +++++++++++++++++++
src/lib/istream-sized.h | 8 +
7 files changed, 133 insertions(+), 134 deletions(-)
diffs (truncated from 334 to 300 lines):
diff -r 3945a3646c67 -r 9774ae8fff97 src/lib-storage/index/Makefile.am
--- a/src/lib-storage/index/Makefile.am Thu Jun 28 00:27:13 2012 +0300
+++ b/src/lib-storage/index/Makefile.am Thu Jun 28 01:01:58 2012 +0300
@@ -12,7 +12,6 @@
-I$(top_srcdir)/src/lib-storage
libstorage_index_la_SOURCES = \
- istream-attachment.c \
istream-mail.c \
index-attachment.c \
index-mail.c \
@@ -34,7 +33,6 @@
index-transaction.c
headers = \
- istream-attachment.h \
istream-mail.h \
index-attachment.h \
index-mail.h \
diff -r 3945a3646c67 -r 9774ae8fff97 src/lib-storage/index/dbox-common/dbox-attachment.c
--- a/src/lib-storage/index/dbox-common/dbox-attachment.c Thu Jun 28 00:27:13 2012 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-attachment.c Thu Jun 28 01:01:58 2012 +0300
@@ -4,7 +4,7 @@
#include "istream.h"
#include "istream-concat.h"
#include "str.h"
-#include "istream-attachment.h"
+#include "istream-sized.h"
#include "istream-base64-encoder.h"
#include "dbox-file.h"
#include "dbox-save.h"
@@ -195,7 +195,7 @@
input2 = input;
}
- input = i_stream_create_attachment(input2, extref->size);
+ input = i_stream_create_sized(input2, extref->size);
i_stream_unref(&input2);
array_append(&streams, &input, 1);
}
diff -r 3945a3646c67 -r 9774ae8fff97 src/lib-storage/index/istream-attachment.c
--- a/src/lib-storage/index/istream-attachment.c Thu Jun 28 00:27:13 2012 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,124 +0,0 @@
-/* Copyright (c) 2003-2012 Dovecot authors, see the included COPYING file */
-
-#include "lib.h"
-#include "istream-private.h"
-#include "istream-attachment.h"
-
-struct attachment_istream {
- struct istream_private istream;
-
- uoff_t size;
-};
-
-static ssize_t i_stream_attachment_read(struct istream_private *stream)
-{
- struct attachment_istream *astream =
- (struct attachment_istream *)stream;
- uoff_t left;
- ssize_t ret;
- size_t pos;
-
- if (stream->istream.v_offset +
- (stream->pos - stream->skip) >= astream->size) {
- stream->istream.eof = TRUE;
- return -1;
- }
-
- i_stream_seek(stream->parent, astream->istream.parent_start_offset +
- stream->istream.v_offset);
-
- stream->pos -= stream->skip;
- stream->skip = 0;
-
- stream->buffer = i_stream_get_data(stream->parent, &pos);
- if (pos > stream->pos)
- ret = 0;
- else do {
- if ((ret = i_stream_read(stream->parent)) == -2)
- return -2;
-
- stream->istream.stream_errno = stream->parent->stream_errno;
- stream->istream.eof = stream->parent->eof;
- stream->buffer = i_stream_get_data(stream->parent, &pos);
- } while (pos <= stream->pos && ret > 0);
-
- left = astream->size - stream->istream.v_offset;
- if (pos == left)
- stream->istream.eof = TRUE;
- else if (pos > left) {
- i_error("Attachment file %s larger than expected "
- "(%"PRIuUOFF_T")", i_stream_get_name(stream->parent),
- astream->size);
- pos = left;
- stream->istream.eof = TRUE;
- } else if (!stream->istream.eof) {
- /* still more to read */
- } else if (stream->istream.stream_errno == ENOENT) {
- /* lost the file */
- } else {
- i_error("Attachment file %s smaller than expected "
- "(%"PRIuUOFF_T" < %"PRIuUOFF_T")",
- i_stream_get_name(stream->parent),
- stream->istream.v_offset, astream->size);
- stream->istream.stream_errno = EIO;
- }
-
- ret = pos > stream->pos ? (ssize_t)(pos - stream->pos) :
- (ret == 0 ? 0 : -1);
- stream->pos = pos;
- i_assert(ret != -1 || stream->istream.eof ||
- stream->istream.stream_errno != 0);
- return ret;
-}
-
-static void
-i_stream_attachment_seek(struct istream_private *stream,
- uoff_t v_offset, bool mark ATTR_UNUSED)
-{
- struct attachment_istream *astream =
- (struct attachment_istream *)stream;
-
- i_assert(v_offset <= astream->size);
-
- stream->istream.v_offset = v_offset;
- stream->skip = stream->pos = 0;
-}
-
-static const struct stat *
-i_stream_attachment_stat(struct istream_private *stream, bool exact ATTR_UNUSED)
-{
- struct attachment_istream *astream =
- (struct attachment_istream *)stream;
- const struct stat *st;
-
- /* parent stream may be base64-decoder. don't waste time decoding the
- entire stream, since we already know what the size is supposed
- to be. */
- st = i_stream_stat(stream->parent, FALSE);
- if (st == NULL)
- return NULL;
-
- stream->statbuf = *st;
- stream->statbuf.st_size = astream->size;
- return &stream->statbuf;
-}
-
-struct istream *i_stream_create_attachment(struct istream *input, uoff_t size)
-{
- struct attachment_istream *astream;
-
- astream = i_new(struct attachment_istream, 1);
- astream->size = size;
- astream->istream.max_buffer_size = input->real_stream->max_buffer_size;
-
- astream->istream.parent = input;
- astream->istream.read = i_stream_attachment_read;
- astream->istream.seek = i_stream_attachment_seek;
- astream->istream.stat = i_stream_attachment_stat;
-
- astream->istream.istream.readable_fd = input->readable_fd;
- astream->istream.istream.blocking = input->blocking;
- astream->istream.istream.seekable = input->seekable;
- return i_stream_create(&astream->istream, input,
- i_stream_get_fd(input));
-}
diff -r 3945a3646c67 -r 9774ae8fff97 src/lib-storage/index/istream-attachment.h
--- a/src/lib-storage/index/istream-attachment.h Thu Jun 28 00:27:13 2012 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-#ifndef ISTREAM_ATTACHMENT_H
-#define ISTREAM_ATTACHMENT_H
-
-struct istream *i_stream_create_attachment(struct istream *input, uoff_t size);
-
-#endif
diff -r 3945a3646c67 -r 9774ae8fff97 src/lib/Makefile.am
--- a/src/lib/Makefile.am Thu Jun 28 00:27:13 2012 +0300
+++ b/src/lib/Makefile.am Thu Jun 28 01:01:58 2012 +0300
@@ -63,6 +63,7 @@
istream-mmap.c \
istream-rawlog.c \
istream-seekable.c \
+ istream-sized.c \
istream-tee.c \
ioloop.c \
ioloop-iolist.c \
@@ -181,6 +182,7 @@
istream-private.h \
istream-rawlog.h \
istream-seekable.h \
+ istream-sized.h \
istream-tee.h \
ioloop.h \
ioloop-iolist.h \
diff -r 3945a3646c67 -r 9774ae8fff97 src/lib/istream-sized.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/istream-sized.c Thu Jun 28 01:01:58 2012 +0300
@@ -0,0 +1,121 @@
+/* Copyright (c) 2003-2012 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "istream-private.h"
+#include "istream-sized.h"
+
+struct sized_istream {
+ struct istream_private istream;
+
+ uoff_t size;
+};
+
+static ssize_t i_stream_sized_read(struct istream_private *stream)
+{
+ struct sized_istream *sstream =
+ (struct sized_istream *)stream;
+ uoff_t left;
+ ssize_t ret;
+ size_t pos;
+
+ if (stream->istream.v_offset +
+ (stream->pos - stream->skip) >= sstream->size) {
+ stream->istream.eof = TRUE;
+ return -1;
+ }
+
+ i_stream_seek(stream->parent, sstream->istream.parent_start_offset +
+ stream->istream.v_offset);
+
+ stream->pos -= stream->skip;
+ stream->skip = 0;
+
+ stream->buffer = i_stream_get_data(stream->parent, &pos);
+ if (pos > stream->pos)
+ ret = 0;
+ else do {
+ if ((ret = i_stream_read(stream->parent)) == -2)
+ return -2;
+
+ stream->istream.stream_errno = stream->parent->stream_errno;
+ stream->istream.eof = stream->parent->eof;
+ stream->buffer = i_stream_get_data(stream->parent, &pos);
+ } while (pos <= stream->pos && ret > 0);
+
+ left = sstream->size - stream->istream.v_offset;
+ if (pos == left)
+ stream->istream.eof = TRUE;
+ else if (pos > left) {
+ i_error("%s is larger than expected (%"PRIuUOFF_T")",
+ i_stream_get_name(stream->parent), sstream->size);
+ pos = left;
+ stream->istream.eof = TRUE;
+ } else if (!stream->istream.eof) {
+ /* still more to read */
+ } else if (stream->istream.stream_errno == ENOENT) {
+ /* lost the file */
+ } else {
+ i_error("%s smaller than expected "
+ "(%"PRIuUOFF_T" < %"PRIuUOFF_T")",
+ i_stream_get_name(stream->parent),
+ stream->istream.v_offset, sstream->size);
+ stream->istream.stream_errno = EIO;
+ }
+
+ ret = pos > stream->pos ? (ssize_t)(pos - stream->pos) :
+ (ret == 0 ? 0 : -1);
+ stream->pos = pos;
+ i_assert(ret != -1 || stream->istream.eof ||
+ stream->istream.stream_errno != 0);
+ return ret;
+}
+
+static void
+i_stream_sized_seek(struct istream_private *stream,
+ uoff_t v_offset, bool mark ATTR_UNUSED)
+{
+ struct sized_istream *sstream = (struct sized_istream *)stream;
+
+ i_assert(v_offset <= sstream->size);
+
+ stream->istream.v_offset = v_offset;
+ stream->skip = stream->pos = 0;
+}
+
+static const struct stat *
+i_stream_sized_stat(struct istream_private *stream, bool sized ATTR_UNUSED)
+{
+ struct sized_istream *sstream = (struct sized_istream *)stream;
+ const struct stat *st;
+
+ /* parent stream may be base64-decoder. don't waste time decoding the
+ entire stream, since we already know what the size is supposed
+ to be. */
+ st = i_stream_stat(stream->parent, FALSE);
+ if (st == NULL)
+ return NULL;
+
+ stream->statbuf = *st;
+ stream->statbuf.st_size = sstream->size;
More information about the dovecot-cvs
mailing list