[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-expunge.c,1.22,1.23 mbox-save.c,1.25,1.26 mbox-storage.h,1.9,1.10

cras at procontrol.fi cras at procontrol.fi
Fri Dec 6 03:09:25 EET 2002


Update of /home/cvs/dovecot/src/lib-storage/index/mbox
In directory danu:/tmp/cvs-serv6082/lib-storage/index/mbox

Modified Files:
	mbox-expunge.c mbox-save.c mbox-storage.h 
Log Message:
Renamed IBuffer and OBuffer to IStream and OStream which describes their
functionality better. I tried to keep the variable names and comments also
sensible.



Index: mbox-expunge.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-expunge.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- mbox-expunge.c	13 Nov 2002 01:36:16 -0000	1.22
+++ mbox-expunge.c	6 Dec 2002 01:09:23 -0000	1.23
@@ -1,8 +1,8 @@
 /* Copyright (C) 2002 Timo Sirainen */
 
 #include "lib.h"
-#include "ibuffer.h"
-#include "obuffer.h"
+#include "istream.h"
+#include "ostream.h"
 #include "mbox-index.h"
 #include "mbox-storage.h"
 #include "mbox-lock.h"
@@ -11,7 +11,7 @@
 #include <unistd.h>
 
 static int expunge_real(IndexMailbox *ibox, MailIndexRecord *rec,
-			unsigned int seq, IBuffer *inbuf, OBuffer *outbuf,
+			unsigned int seq, IStream *input, OStream *output,
 			int notify)
 {
 	uoff_t offset, hdr_size, body_size;
@@ -36,7 +36,7 @@
 		rec = ibox->index->next(ibox->index, rec);
 	}
 
-	old_limit = inbuf->v_limit;
+	old_limit = input->v_limit;
 
 	expunges = FALSE;
 	while (rec != NULL) {
@@ -55,33 +55,33 @@
 			if (!expunges) {
 				/* first expunged record, seek to position
 				   where we want to begin writing */
-				if (!o_buffer_seek(outbuf, from_offset))
+				if (!o_stream_seek(output, from_offset))
 					return FALSE;
 				expunges = TRUE;
 			}
 		} else if (expunges) {
 			/* seek to wanted input position, and copy
 			   this messages */
-			i_assert(inbuf->v_offset <= from_offset);
-			i_buffer_skip(inbuf, from_offset - inbuf->v_offset);
+			i_assert(input->v_offset <= from_offset);
+			i_stream_skip(input, from_offset - input->v_offset);
 
-			if (outbuf->offset == 0) {
+			if (output->offset == 0) {
 				/* we're writing to beginning of mbox, so we
 				   don't want the [\r]\n there */
-				(void)i_buffer_read_data(inbuf, &data,
+				(void)i_stream_read_data(input, &data,
 							 &size, 1);
 				if (size > 0 && data[0] == '\n')
-					i_buffer_skip(inbuf, 1);
+					i_stream_skip(input, 1);
 				else if (size > 1 && data[0] == '\r' &&
 					 data[1] == '\n')
-					i_buffer_skip(inbuf, 2);
+					i_stream_skip(input, 2);
 			}
 
-			i_buffer_set_read_limit(inbuf, end_offset);
-			failed = o_buffer_send_ibuffer(outbuf, inbuf) < 0;
-			i_buffer_set_read_limit(inbuf, old_limit);
+			i_stream_set_read_limit(input, end_offset);
+			failed = o_stream_send_istream(output, input) < 0;
+			i_stream_set_read_limit(input, old_limit);
 
-			if (failed || inbuf->v_offset != end_offset)
+			if (failed || input->v_offset != end_offset)
 				return FALSE;
 		}
 
@@ -89,23 +89,23 @@
 		seq++;
 	}
 
-	i_buffer_skip(inbuf, end_offset - inbuf->v_offset);
+	i_stream_skip(input, end_offset - input->v_offset);
 
 	/* copy the rest as well, should be only \n but someone might
 	   as well just appended more data.. but if we've deleted all mail,
 	   don't write the only \n there. */
-	copy_size = inbuf->v_size - inbuf->v_offset;
-	if (outbuf->offset == 0 && copy_size == 1)
+	copy_size = input->v_size - input->v_offset;
+	if (output->offset == 0 && copy_size == 1)
 		return TRUE;
 
-	return o_buffer_send_ibuffer(outbuf, inbuf) >= 0;
+	return o_stream_send_istream(output, input) >= 0;
 }
 
 int mbox_expunge_locked(IndexMailbox *ibox, int notify)
 {
 	MailIndexRecord *rec;
-	IBuffer *inbuf;
-	OBuffer *outbuf;
+	IStream *input;
+	OStream *output;
 	unsigned int seq;
 	int failed;
 
@@ -118,35 +118,35 @@
 	}
 
 	/* mbox must be already opened, synced and locked at this point.
-	   we just want the IBuffer. */
-	inbuf = mbox_get_inbuf(ibox->index, 0, MAIL_LOCK_EXCLUSIVE);
-	if (inbuf == NULL)
+	   we just want the IStream. */
+	input = mbox_get_stream(ibox->index, 0, MAIL_LOCK_EXCLUSIVE);
+	if (input == NULL)
 		return FALSE;
 
 	i_assert(ibox->index->mbox_sync_counter ==
 		 ibox->index->mbox_lock_counter);
 
 	t_push();
-	outbuf = o_buffer_create_file(ibox->index->mbox_fd, data_stack_pool,
+	output = o_stream_create_file(ibox->index->mbox_fd, data_stack_pool,
 				      4096, 0, FALSE);
-	o_buffer_set_blocking(outbuf, 60000, NULL, NULL);
+	o_stream_set_blocking(output, 60000, NULL, NULL);
 
-	failed = !expunge_real(ibox, rec, seq, inbuf, outbuf, notify);
+	failed = !expunge_real(ibox, rec, seq, input, output, notify);
 
-	if (failed && outbuf->offset > 0) {
+	if (failed && output->offset > 0) {
 		/* we moved some of the data. move the rest as well so there
 		   won't be invalid holes in mbox file */
-		(void)o_buffer_send_ibuffer(outbuf, inbuf);
+		(void)o_stream_send_istream(output, input);
 	}
 
-	if (ftruncate(ibox->index->mbox_fd, (off_t)outbuf->offset) < 0) {
+	if (ftruncate(ibox->index->mbox_fd, (off_t)output->offset) < 0) {
 		mail_storage_set_error(ibox->box.storage, "ftruncate() failed "
 				       "for mbox file %s: %m",
 				       ibox->index->mbox_path);
 		failed = TRUE;
 	}
 
-	o_buffer_unref(outbuf);
+	o_stream_unref(output);
 	t_pop();
 
 	return !failed;

Index: mbox-save.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-save.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- mbox-save.c	25 Nov 2002 19:02:50 -0000	1.25
+++ mbox-save.c	6 Dec 2002 01:09:23 -0000	1.26
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "hostpid.h"
-#include "obuffer.h"
+#include "ostream.h"
 #include "write-full.h"
 #include "mbox-index.h"
 #include "mbox-lock.h"
@@ -65,16 +65,16 @@
 	return TRUE;
 }
 
-static int mbox_append_lf(MailStorage *storage, OBuffer *outbuf,
+static int mbox_append_lf(MailStorage *storage, OStream *output,
 			  const char *mbox_path)
 {
-	if (o_buffer_send(outbuf, "\n", 1) < 0)
+	if (o_stream_send(output, "\n", 1) < 0)
 		return write_error(storage, mbox_path);
 
 	return TRUE;
 }
 
-static int write_from_line(MailStorage *storage, OBuffer *outbuf,
+static int write_from_line(MailStorage *storage, OStream *output,
 			   const char *mbox_path, time_t internal_date)
 {
 	const char *sender, *line, *name;
@@ -102,13 +102,13 @@
 	line = mbox_from_create(sender, internal_date);
 	len = strlen(line);
 
-	if (o_buffer_send(outbuf, line, len) < 0)
+	if (o_stream_send(output, line, len) < 0)
 		return write_error(storage, mbox_path);
 
 	return TRUE;
 }
 
-static int write_flags(MailStorage *storage, OBuffer *outbuf,
+static int write_flags(MailStorage *storage, OStream *output,
 		       const char *mbox_path,
 		       MailFlags flags, const char *custom_flags[])
 {
@@ -120,7 +120,7 @@
 		return TRUE;
 
 	if (flags & MAIL_SEEN) {
-		if (o_buffer_send(outbuf, "Status: R\n", 10) < 0)
+		if (o_stream_send(output, "Status: R\n", 10) < 0)
 			return write_error(storage, mbox_path);
 	}
 
@@ -132,27 +132,27 @@
 				  (flags & MAIL_DELETED) ? "T" : "",
 				  "\n", NULL);
 
-		if (o_buffer_send(outbuf, str, strlen(str)) < 0)
+		if (o_stream_send(output, str, strlen(str)) < 0)
 			return write_error(storage, mbox_path);
 	}
 
 	if (flags & MAIL_CUSTOM_FLAGS_MASK) {
-		if (o_buffer_send(outbuf, "X-Keywords:", 11) < 0)
+		if (o_stream_send(output, "X-Keywords:", 11) < 0)
 			return write_error(storage, mbox_path);
 
 		field = 1 << MAIL_CUSTOM_FLAG_1_BIT;
 		for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++, field <<= 1) {
 			if ((flags & field) && custom_flags[i] != NULL) {
-				if (o_buffer_send(outbuf, " ", 1) < 0)
+				if (o_stream_send(output, " ", 1) < 0)
 					return write_error(storage, mbox_path);
 
-				if (o_buffer_send(outbuf, custom_flags[i],
+				if (o_stream_send(output, custom_flags[i],
 						  strlen(custom_flags[i])) < 0)
 					return write_error(storage, mbox_path);
 			}
 		}
 
-		if (o_buffer_send(outbuf, "\n", 1) < 0)
+		if (o_stream_send(output, "\n", 1) < 0)
 			return write_error(storage, mbox_path);
 	}
 
@@ -161,13 +161,13 @@
 
 int mbox_storage_save(Mailbox *box, MailFlags flags, const char *custom_flags[],
 		      time_t internal_date, int timezone_offset __attr_unused__,
-		      IBuffer *data, uoff_t data_size)
+		      IStream *data, uoff_t data_size)
 {
 	IndexMailbox *ibox = (IndexMailbox *) box;
 	MailIndex *index;
 	MailFlags real_flags;
 	const char *mbox_path;
-	OBuffer *outbuf;
+	OStream *output;
 	int failed;
 	off_t pos;
 
@@ -193,26 +193,26 @@
 		failed = FALSE;
 
 		t_push();
-		outbuf = o_buffer_create_file(index->mbox_fd,
+		output = o_stream_create_file(index->mbox_fd,
 					      data_stack_pool, 4096,
 					      0, FALSE);
-		o_buffer_set_blocking(outbuf, 60000, NULL, NULL);
+		o_stream_set_blocking(output, 60000, NULL, NULL);
 
-		if (!write_from_line(box->storage, outbuf, mbox_path,
+		if (!write_from_line(box->storage, output, mbox_path,
 				     internal_date) ||
-		    !write_flags(box->storage, outbuf, mbox_path, flags,
+		    !write_flags(box->storage, output, mbox_path, flags,
 				 custom_flags) ||
 		    !index_storage_save(box->storage, mbox_path,
-					data, outbuf, data_size) ||
-		    !mbox_append_lf(box->storage, outbuf, mbox_path)) {
+					data, output, data_size) ||
+		    !mbox_append_lf(box->storage, output, mbox_path)) {
 			/* failed, truncate file back to original size.
-			   output buffer needs to be flushed before truncating
+			   output stream needs to be flushed before truncating
 			   so unref() won't write anything. */
-			o_buffer_flush(outbuf);
+			o_stream_flush(output);
 			(void)ftruncate(index->mbox_fd, pos);
 			failed = TRUE;
 		}
-		o_buffer_unref(outbuf);
+		o_stream_unref(output);
 		t_pop();
 	}
 

Index: mbox-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- mbox-storage.h	3 Dec 2002 23:29:09 -0000	1.9
+++ mbox-storage.h	6 Dec 2002 01:09:23 -0000	1.10
@@ -7,7 +7,7 @@
 		      const char *messageset, int uidset);
 int mbox_storage_save(Mailbox *box, MailFlags flags, const char *custom_flags[],
 		      time_t internal_date, int timezone_offset,
-		      IBuffer *data, uoff_t data_size);
+		      IStream *data, uoff_t data_size);
 
 int mbox_find_mailboxes(MailStorage *storage, const char *mask,
 			MailboxFunc func, void *context);




More information about the dovecot-cvs mailing list