dovecot-2.2: Added i_stream_alloc()

dovecot at dovecot.org dovecot at dovecot.org
Thu Jun 28 03:20:55 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/8909e8428b82
changeset: 14694:8909e8428b82
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jun 28 03:18:55 2012 +0300
description:
Added i_stream_alloc()

diffstat:

 src/lib-mail/istream-binary-converter.c |  38 ++++++++------------------------
 src/lib/istream-private.h               |   1 +
 src/lib/istream.c                       |  17 ++++++++++++++
 3 files changed, 28 insertions(+), 28 deletions(-)

diffs (126 lines):

diff -r d7d1f24dde34 -r 8909e8428b82 src/lib-mail/istream-binary-converter.c
--- a/src/lib-mail/istream-binary-converter.c	Thu Jun 28 01:30:50 2012 +0300
+++ b/src/lib-mail/istream-binary-converter.c	Thu Jun 28 03:18:55 2012 +0300
@@ -30,25 +30,6 @@
 static void stream_add_data(struct binary_converter_istream *bstream,
 			    const void *data, size_t size);
 
-static void *
-stream_alloc_data(struct binary_converter_istream *bstream, size_t size)
-{
-	struct istream_private *stream = &bstream->istream;
-	size_t old_size, avail_size;
-
-	i_stream_try_alloc(stream, size, &avail_size);
-	if (avail_size < size) {
-		old_size = stream->buffer_size;
-		stream->buffer_size = nearest_power(stream->pos + size);
-		stream->w_buffer = i_realloc(stream->w_buffer, old_size,
-					     stream->buffer_size);
-		stream->buffer = stream->w_buffer;
-		i_stream_try_alloc(stream, size, &avail_size);
-		i_assert(avail_size >= size);
-	}
-	return stream->w_buffer + stream->pos;
-}
-
 static bool part_can_convert(const struct message_part *part)
 {
 	/* some MUAs use "c-t-e: binary" for multiparts.
@@ -92,13 +73,14 @@
 		stream_finish_convert_decision(bstream);
 	}
 
-	memcpy(stream_alloc_data(bstream, size), data, size);
+	memcpy(i_stream_alloc(&bstream->istream, size), data, size);
 	bstream->istream.pos += size;
 }
 
 static void stream_encode_base64(struct binary_converter_istream *bstream,
 				 const void *_data, size_t size)
 {
+	struct istream_private *stream = &bstream->istream;
 	const unsigned char *data = _data;
 	buffer_t buf;
 	void *dest;
@@ -128,23 +110,23 @@
 		}
 
 		if (bstream->base64_block_pos == BASE64_BLOCKS_PER_LINE) {
-			memcpy(stream_alloc_data(bstream, 2), "\r\n", 2);
-			bstream->istream.pos += 2;
+			memcpy(i_stream_alloc(stream, 2), "\r\n", 2);
+			stream->pos += 2;
 			bstream->base64_block_pos = 0;
 		}
 
-		dest = stream_alloc_data(bstream, BASE64_BLOCK_SIZE);
+		dest = i_stream_alloc(stream, BASE64_BLOCK_SIZE);
 		buffer_create_data(&buf, dest, BASE64_BLOCK_SIZE);
 		base64_encode(base64_block, base64_block_len, &buf);
-		bstream->istream.pos += buf.used;
+		stream->pos += buf.used;
 		bstream->base64_block_pos++;
 		bstream->base64_delayed_len = 0;
 	}
 
 	while (size >= BASE64_BLOCK_INPUT_SIZE) {
 		if (bstream->base64_block_pos == BASE64_BLOCKS_PER_LINE) {
-			memcpy(stream_alloc_data(bstream, 2), "\r\n", 2);
-			bstream->istream.pos += 2;
+			memcpy(i_stream_alloc(stream, 2), "\r\n", 2);
+			stream->pos += 2;
 			bstream->base64_block_pos = 0;
 		}
 
@@ -160,10 +142,10 @@
 		}
 
 		max_encoded_size = MAX_BASE64_ENCODED_SIZE(encode_size);
-		dest = stream_alloc_data(bstream, max_encoded_size);
+		dest = i_stream_alloc(stream, max_encoded_size);
 		buffer_create_data(&buf, dest, max_encoded_size);
 		base64_encode(data, encode_size, &buf);
-		bstream->istream.pos += buf.used;
+		stream->pos += buf.used;
 		bstream->base64_block_pos += encode_blocks;
 
 		data += encode_size;
diff -r d7d1f24dde34 -r 8909e8428b82 src/lib/istream-private.h
--- a/src/lib/istream-private.h	Thu Jun 28 01:30:50 2012 +0300
+++ b/src/lib/istream-private.h	Thu Jun 28 03:18:55 2012 +0300
@@ -56,6 +56,7 @@
 bool ATTR_NOWARN_UNUSED_RESULT
 i_stream_try_alloc(struct istream_private *stream,
 		   size_t wanted_size, size_t *size_r);
+void *i_stream_alloc(struct istream_private *stream, size_t size);
 ssize_t i_stream_read_copy_from_parent(struct istream *istream);
 void i_stream_default_seek(struct istream_private *stream,
 			   uoff_t v_offset, bool mark);
diff -r d7d1f24dde34 -r 8909e8428b82 src/lib/istream.c
--- a/src/lib/istream.c	Thu Jun 28 01:30:50 2012 +0300
+++ b/src/lib/istream.c	Thu Jun 28 03:18:55 2012 +0300
@@ -515,6 +515,23 @@
 	return stream->pos != stream->buffer_size;
 }
 
+void *i_stream_alloc(struct istream_private *stream, size_t size)
+{
+	size_t old_size, avail_size;
+
+	i_stream_try_alloc(stream, size, &avail_size);
+	if (avail_size < size) {
+		old_size = stream->buffer_size;
+		stream->buffer_size = nearest_power(stream->pos + size);
+		stream->w_buffer = i_realloc(stream->w_buffer, old_size,
+					     stream->buffer_size);
+		stream->buffer = stream->w_buffer;
+		i_stream_try_alloc(stream, size, &avail_size);
+		i_assert(avail_size >= size);
+	}
+	return stream->w_buffer + stream->pos;
+}
+
 bool i_stream_add_data(struct istream *_stream, const unsigned char *data,
 		       size_t size)
 {


More information about the dovecot-cvs mailing list