dovecot: Removed CRLF/LF output streams. They're no longer needed.

dovecot at dovecot.org dovecot at dovecot.org
Sat Oct 6 01:50:58 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/2f397bc2cc0c
changeset: 6530:2f397bc2cc0c
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Oct 06 01:50:52 2007 +0300
description:
Removed CRLF/LF output streams. They're no longer needed.

diffstat:

3 files changed, 400 deletions(-)
src/lib/Makefile.am    |    2 
src/lib/ostream-crlf.c |  389 ------------------------------------------------
src/lib/ostream-crlf.h |    9 -

diffs (truncated from 425 to 300 lines):

diff -r aee441840b5a -r 2f397bc2cc0c src/lib/Makefile.am
--- a/src/lib/Makefile.am	Sat Oct 06 01:49:41 2007 +0300
+++ b/src/lib/Makefile.am	Sat Oct 06 01:50:52 2007 +0300
@@ -73,7 +73,6 @@ liblib_a_SOURCES = \
 	nfs-workarounds.c \
 	ostream.c \
 	ostream-file.c \
-	ostream-crlf.c \
 	primes.c \
 	printf-format-fix.c \
 	process-title.c \
@@ -154,7 +153,6 @@ headers = \
 	network.h \
 	nfs-workarounds.h \
 	ostream.h \
-	ostream-crlf.h \
 	ostream-internal.h \
 	primes.h \
 	printf-format-fix.h \
diff -r aee441840b5a -r 2f397bc2cc0c src/lib/ostream-crlf.c
--- a/src/lib/ostream-crlf.c	Sat Oct 06 01:49:41 2007 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,389 +0,0 @@
-/* Copyright (c) 2004-2007 Dovecot authors, see the included COPYING file */
-
-/* The code is quite ugly because we want the send functions to return correcly
-   the number of input bytes consumed, not number of bytes actually sent. */
-
-#include "lib.h"
-#include "buffer.h"
-#include "istream.h"
-#include "ostream-internal.h"
-#include "ostream-crlf.h"
-
-#define IOVBUF_COUNT 64
-
-struct crlf_ostream {
-	struct ostream_private ostream;
-
-        struct ostream *output;
-	bool last_cr;
-};
-
-static const struct const_iovec cr_iov = { "\r", 1 };
-
-static void o_stream_crlf_destroy(struct iostream_private *stream)
-{
-	struct crlf_ostream *cstream = (struct crlf_ostream *)stream;
-
-	o_stream_unref(&cstream->output);
-}
-
-static void
-o_stream_crlf_set_max_buffer_size(struct iostream_private *stream,
-				  size_t max_size)
-{
-	struct crlf_ostream *cstream = (struct crlf_ostream *)stream;
-
-	o_stream_set_max_buffer_size(cstream->output, max_size);
-}
-
-static void o_stream_crlf_cork(struct ostream_private *stream, bool set)
-{
-	struct crlf_ostream *cstream = (struct crlf_ostream *)stream;
-
-	if (set)
-		o_stream_cork(cstream->output);
-	else
-		o_stream_uncork(cstream->output);
-}
-
-static int o_stream_crlf_flush(struct ostream_private *stream)
-{
-	struct crlf_ostream *cstream = (struct crlf_ostream *)stream;
-
-	return o_stream_flush(cstream->output);
-}
-
-static void
-o_stream_crlf_flush_pending(struct ostream_private *stream, bool set)
-{
-	struct crlf_ostream *cstream = (struct crlf_ostream *)stream;
-
-	o_stream_set_flush_pending(cstream->output, set);
-}
-
-static size_t o_stream_crlf_get_used_size(struct ostream_private *stream)
-{
-	struct crlf_ostream *cstream = (struct crlf_ostream *)stream;
-
-	return o_stream_get_buffer_used_size(cstream->output);
-}
-
-static int o_stream_crlf_seek(struct ostream_private *stream, uoff_t offset)
-{
-	struct crlf_ostream *cstream = (struct crlf_ostream *)stream;
-	int ret;
-
-	cstream->last_cr = FALSE;
-	ret = o_stream_seek(cstream->output, offset);
-	stream->ostream.offset = cstream->output->offset;
-	return ret;
-}
-
-static ssize_t
-sendv_crlf(struct crlf_ostream *cstream, const struct const_iovec *iov,
-	   size_t iov_count, const char *diff, ssize_t *total_r)
-{
-	ssize_t ret;
-	size_t i, pos;
-
-	ret = o_stream_sendv(cstream->output, iov, iov_count);
-	if (ret > 0) {
-		pos = (size_t)ret - 1;
-		for (i = 0; i < iov_count && pos >= iov[i].iov_len; i++) {
-			*total_r += iov[i].iov_len + diff[i];
-			pos -= iov[i].iov_len;
-		}
-
-		cstream->last_cr =
-			*((const char *)iov[i].iov_base + pos) == '\r';
-
-		if (pos + 1 == iov[i].iov_len)
-			*total_r += iov[i].iov_len + diff[i];
-		else
-			*total_r += pos;
-	}
-	cstream->ostream.ostream.offset = cstream->output->offset;
-	cstream->ostream.ostream.stream_errno = cstream->output->stream_errno;
-	return ret;
-}
-
-static ssize_t
-o_stream_crlf_sendv_crlf(struct ostream_private *stream,
-			 const struct const_iovec *iov,
-			 unsigned int iov_count)
-{
-	struct crlf_ostream *cstream = (struct crlf_ostream *)stream;
-	buffer_t *iov_buf, *diff_buf;
-	const unsigned char *data;
-	struct const_iovec new_iov;
-	unsigned int vec, i, len, start, new_iov_count = 0, new_iov_size = 0;
-	ssize_t ret, total;
-	bool last_cr;
-
-	last_cr = cstream->last_cr;
-
-	t_push();
-	iov_buf = buffer_create_dynamic(unsafe_data_stack_pool,
-					sizeof(struct const_iovec *) *
-					IOVBUF_COUNT);
-	diff_buf = buffer_create_dynamic(unsafe_data_stack_pool, IOVBUF_COUNT);
-	total = 0;
-	for (vec = 0; vec < iov_count; vec++) {
-		data = iov[vec].iov_base;
-		len = iov[vec].iov_len;
-
-		for (i = start = 0;; i++) {
-			if (i != len) {
-				if (data[i] != '\n')
-					continue;
-
-				if (i > 0) {
-					if (data[i-1] == '\r')
-						continue;
-				} else {
-					if (last_cr)
-						continue;
-				}
-
-				/* need to insert CR */
-			}
-
-			if (i != start) {
-				new_iov.iov_base = data + start;
-				new_iov.iov_len = i - start;
-
-				buffer_append(iov_buf, &new_iov,
-					      sizeof(new_iov));
-				buffer_append_c(diff_buf, 0);
-				new_iov_count++;
-				new_iov_size += new_iov.iov_len;
-			}
-			start = i;
-
-			if (i != len) {
-				buffer_append(iov_buf, &cr_iov, sizeof(cr_iov));
-				buffer_append_c(diff_buf, -1);
-				new_iov_count++;
-				new_iov_size++;
-			}
-
-			if (new_iov_count >= IOVBUF_COUNT-1) {
-				ret = sendv_crlf(cstream, iov_buf->data,
-						 new_iov_count, diff_buf->data,
-						 &total);
-				if (ret != (ssize_t)new_iov_size) {
-					t_pop();
-					return ret < 0 ? ret : total;
-				}
-
-				buffer_set_used_size(iov_buf, 0);
-				buffer_set_used_size(diff_buf, 0);
-				new_iov_count = 0;
-				new_iov_size = 0;
-			}
-
-			if (i == len)
-				break;
-		}
-
-		if (len != 0)
-			last_cr = data[len-1] == '\r';
-	}
-
-	ret = sendv_crlf(cstream, iov_buf->data, new_iov_count,
-			 diff_buf->data, &total);
-	t_pop();
-	return ret < 0 ? ret : total;
-}
-
-static ssize_t
-sendv_lf(struct crlf_ostream *cstream, const struct const_iovec *iov,
-	 size_t iov_count, const char *diff, ssize_t *total_r)
-{
-	ssize_t ret;
-	size_t i, left;
-
-	ret = o_stream_sendv(cstream->output, iov, iov_count);
-	if (ret >= 0) {
-		left = (size_t)ret;
-		for (i = 0; i < iov_count && left >= iov[i].iov_len; i++) {
-			*total_r += iov[i].iov_len + diff[i];
-			left -= iov[i].iov_len;
-		}
-		*total_r += left;
-	}
-	cstream->ostream.ostream.stream_errno = cstream->output->stream_errno;
-	cstream->ostream.ostream.offset = cstream->output->offset;
-	return ret;
-}
-
-static ssize_t
-o_stream_crlf_sendv_lf(struct ostream_private *stream,
-		       const struct const_iovec *iov,
-		       unsigned int iov_count)
-{
-	struct crlf_ostream *cstream = (struct crlf_ostream *)stream;
-	buffer_t *iov_buf, *diff_buf;
-	const unsigned char *data;
-	struct const_iovec new_iov;
-	unsigned int vec, i, len, start, next;
-	unsigned int new_iov_count = 0, new_iov_size = 0;
-	ssize_t ret, total;
-	int diff;
-
-	t_push();
-	iov_buf = buffer_create_dynamic(unsafe_data_stack_pool,
-					sizeof(struct const_iovec *) *
-					IOVBUF_COUNT);
-	diff_buf = buffer_create_dynamic(unsafe_data_stack_pool, IOVBUF_COUNT);
-	total = 0;
-	for (vec = 0; vec < iov_count; vec++) {
-		data = iov[vec].iov_base;
-		len = iov[vec].iov_len;
-
-		for (i = start = 0;; i++) {
-			if (i != len) {
-				if (data[i] != '\n' || i == 0 ||
-				    data[i-1] != '\r')
-					continue;
-			}
-
-			if (start == 0 && i > 0 && data[0] != '\n' &&
-			    cstream->last_cr) {
-				/* bare CR, keep it */
-				buffer_append(iov_buf, &cr_iov, sizeof(cr_iov));
-				buffer_append_c(diff_buf, -1);
-				new_iov_count++;
-				new_iov_size++;
-			}
-
-			next = i;
-			if (i != len) {
-				/* skipping an CR */
-				i--;
-				cstream->last_cr = FALSE;
-				diff = 1;
-			} else if (i != start && data[i-1] == '\r') {
-				/* data ends with CR, don't add it yet */
-				i--;
-				cstream->last_cr = TRUE;
-				diff = 1;
-			} else {
-				/* data doesn't end with CR */
-				cstream->last_cr = FALSE;
-				diff = 0;
-			}
-
-			new_iov.iov_base = data + start;


More information about the dovecot-cvs mailing list