[dovecot-cvs] dovecot/src/lib-index/mbox mbox-append.c,1.32,1.33 mbox-index.c,1.52,1.53 mbox-index.h,1.20,1.21 mbox-lock.c,1.17,1.18 mbox-open.c,1.18,1.19 mbox-rebuild.c,1.19,1.20 mbox-rewrite.c,1.41,1.42 mbox-sync-full.c,1.4,1.5 mbox-sync.c,1.25,1.26
cras at procontrol.fi
cras at procontrol.fi
Fri Dec 6 03:09:25 EET 2002
- Previous message: [dovecot-cvs] dovecot/src/lib-imap imap-bodystructure.c,1.19,1.20 imap-bodystructure.h,1.4,1.5 imap-envelope.c,1.12,1.13 imap-message-cache.c,1.24,1.25 imap-message-cache.h,1.12,1.13 imap-parser.c,1.22,1.23 imap-parser.h,1.4,1.5
- Next message: [dovecot-cvs] dovecot/src/lib-storage mail-sort.c,1.2,1.3 mail-storage.h,1.21,1.22
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/dovecot/src/lib-index/mbox
In directory danu:/tmp/cvs-serv6082/lib-index/mbox
Modified Files:
mbox-append.c mbox-index.c mbox-index.h mbox-lock.c
mbox-open.c mbox-rebuild.c mbox-rewrite.c mbox-sync-full.c
mbox-sync.c
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-append.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-append.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- mbox-append.c 27 Oct 2002 06:37:18 -0000 1.32
+++ mbox-append.c 6 Dec 2002 01:09:23 -0000 1.33
@@ -2,13 +2,13 @@
#include "lib.h"
#include "ioloop.h"
-#include "ibuffer.h"
+#include "istream.h"
#include "hex-binary.h"
#include "md5.h"
#include "mbox-index.h"
#include "mail-index-util.h"
-static int mbox_index_append_next(MailIndex *index, IBuffer *inbuf)
+static int mbox_index_append_next(MailIndex *index, IStream *input)
{
MailIndexRecord *rec;
MailIndexUpdate *update;
@@ -22,7 +22,7 @@
/* get the From-line */
pos = 0;
- while (i_buffer_read_data(inbuf, &data, &size, pos) > 0) {
+ while (i_stream_read_data(input, &data, &size, pos) > 0) {
for (; pos < size; pos++) {
if (data[pos] == '\n')
break;
@@ -48,13 +48,13 @@
if (internal_date == (time_t)-1)
internal_date = ioloop_time;
- i_buffer_skip(inbuf, pos+1);
- abs_start_offset = inbuf->start_offset + inbuf->v_offset;
+ i_stream_skip(input, pos+1);
+ abs_start_offset = input->start_offset + input->v_offset;
/* now, find the end of header. also stops at "\nFrom " if it's
found (broken messages) */
- mbox_skip_header(inbuf);
- eoh_offset = inbuf->v_offset;
+ mbox_skip_header(input);
+ eoh_offset = input->v_offset;
/* add message to index */
rec = index->append_begin(index);
@@ -71,22 +71,22 @@
&abs_start_offset, sizeof(uoff_t));
/* parse the header and cache wanted fields. get the message flags
- from Status and X-Status fields. temporarily limit the buffer size
+ from Status and X-Status fields. temporarily limit the stream length
so the message body is parsed properly.
- the buffer limit is raised again by mbox_header_func after reading
- the headers. it uses Content-Length if available or finds the next
- From-line. */
- mbox_header_init_context(&ctx, index, inbuf);
+ the stream length limit is raised again by mbox_header_func after
+ reading the headers. it uses Content-Length if available or finds
+ the next From-line. */
+ mbox_header_init_context(&ctx, index, input);
ctx.set_read_limit = TRUE;
- i_buffer_seek(inbuf, abs_start_offset - inbuf->start_offset);
+ i_stream_seek(input, abs_start_offset - input->start_offset);
- i_buffer_set_read_limit(inbuf, eoh_offset);
- mail_index_update_headers(update, inbuf, 0, mbox_header_func, &ctx);
+ i_stream_set_read_limit(input, eoh_offset);
+ mail_index_update_headers(update, input, 0, mbox_header_func, &ctx);
- i_buffer_seek(inbuf, inbuf->v_limit);
- i_buffer_set_read_limit(inbuf, 0);
+ i_stream_seek(input, input->v_limit);
+ i_stream_set_read_limit(input, 0);
/* save MD5 */
md5_final(&ctx.md5, md5_digest);
@@ -110,9 +110,9 @@
return !failed;
}
-int mbox_index_append(MailIndex *index, IBuffer *inbuf)
+int mbox_index_append(MailIndex *index, IStream *input)
{
- if (inbuf->v_offset == inbuf->v_size) {
+ if (input->v_offset == input->v_size) {
/* no new data */
return TRUE;
}
@@ -121,10 +121,10 @@
return FALSE;
for (;;) {
- if (inbuf->start_offset + inbuf->v_offset != 0) {
+ if (input->start_offset + input->v_offset != 0) {
/* we're at the [\r]\n before the From-line,
skip it */
- if (!mbox_skip_crlf(inbuf)) {
+ if (!mbox_skip_crlf(input)) {
index_set_error(index,
"Error indexing mbox file %s: "
"LF not found where expected",
@@ -135,10 +135,10 @@
}
}
- if (inbuf->v_offset == inbuf->v_size)
+ if (input->v_offset == input->v_size)
break;
- if (!mbox_index_append_next(index, inbuf))
+ if (!mbox_index_append_next(index, input))
return FALSE;
}
Index: mbox-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-index.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- mbox-index.c 1 Dec 2002 14:19:07 -0000 1.52
+++ mbox-index.c 6 Dec 2002 01:09:23 -0000 1.53
@@ -1,7 +1,7 @@
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
-#include "ibuffer.h"
+#include "istream.h"
#include "rfc822-tokenize.h"
#include "mbox-index.h"
#include "mbox-lock.h"
@@ -49,7 +49,8 @@
return TRUE;
}
-IBuffer *mbox_get_inbuf(MailIndex *index, uoff_t offset, MailLockType lock_type)
+IStream *mbox_get_stream(MailIndex *index, uoff_t offset,
+ MailLockType lock_type)
{
i_assert(offset < OFF_T_MAX);
@@ -70,11 +71,11 @@
break;
}
- if (index->mbox_inbuf == NULL) {
+ if (index->mbox_stream == NULL) {
/* FIXME: breaks expunge */
/*if (index->mail_read_mmaped) {*/
- index->mbox_inbuf =
- i_buffer_create_mmap(index->mbox_fd,
+ index->mbox_stream =
+ i_stream_create_mmap(index->mbox_fd,
default_pool,
MAIL_MMAP_BLOCK_SIZE,
0, 0, FALSE);
@@ -84,34 +85,34 @@
return NULL;
}
- index->mbox_inbuf =
- i_buffer_create_file(index->mbox_fd,
+ index->mbox_stream =
+ i_stream_create_file(index->mbox_fd,
default_pool,
MAIL_READ_BLOCK_SIZE,
FALSE);
}*/
}
- i_buffer_set_read_limit(index->mbox_inbuf, 0);
- i_buffer_set_start_offset(index->mbox_inbuf, (uoff_t)offset);
- i_buffer_seek(index->mbox_inbuf, 0);
+ i_stream_set_read_limit(index->mbox_stream, 0);
+ i_stream_set_start_offset(index->mbox_stream, (uoff_t)offset);
+ i_stream_seek(index->mbox_stream, 0);
- i_buffer_ref(index->mbox_inbuf);
- return index->mbox_inbuf;
+ i_stream_ref(index->mbox_stream);
+ return index->mbox_stream;
}
-void mbox_file_close_inbuf(MailIndex *index)
+void mbox_file_close_stream(MailIndex *index)
{
- if (index->mbox_inbuf != NULL) {
- i_buffer_close(index->mbox_inbuf);
- i_buffer_unref(index->mbox_inbuf);
- index->mbox_inbuf = NULL;
+ if (index->mbox_stream != NULL) {
+ i_stream_close(index->mbox_stream);
+ i_stream_unref(index->mbox_stream);
+ index->mbox_stream = NULL;
}
}
void mbox_file_close_fd(MailIndex *index)
{
- mbox_file_close_inbuf(index);
+ mbox_file_close_stream(index);
if (index->mbox_fd != -1) {
close(index->mbox_fd);
@@ -120,13 +121,13 @@
}
void mbox_header_init_context(MboxHeaderContext *ctx, MailIndex *index,
- IBuffer *inbuf)
+ IStream *input)
{
memset(ctx, 0, sizeof(MboxHeaderContext));
md5_init(&ctx->md5);
ctx->index = index;
- ctx->inbuf = inbuf;
+ ctx->input = input;
ctx->custom_flags = mail_custom_flags_list_get(index->custom_flags);
}
@@ -261,21 +262,21 @@
break;
/* a) use Content-Length, b) search for "From "-line */
- start_offset = ctx->inbuf->v_offset;
- i_buffer_set_read_limit(ctx->inbuf, 0);
+ start_offset = ctx->input->v_offset;
+ i_stream_set_read_limit(ctx->input, 0);
end_offset = start_offset + ctx->content_length;
if (ctx->content_length == 0 ||
- !mbox_verify_end_of_body(ctx->inbuf, end_offset)) {
+ !mbox_verify_end_of_body(ctx->input, end_offset)) {
if (ctx->content_length != 0)
- i_buffer_seek(ctx->inbuf, start_offset);
- mbox_skip_message(ctx->inbuf);
- end_offset = ctx->inbuf->v_offset;
+ i_stream_seek(ctx->input, start_offset);
+ mbox_skip_message(ctx->input);
+ end_offset = ctx->input->v_offset;
ctx->content_length = end_offset - start_offset;
}
- i_buffer_seek(ctx->inbuf, start_offset);
- i_buffer_set_read_limit(ctx->inbuf, end_offset);
+ i_stream_seek(ctx->input, start_offset);
+ i_stream_set_read_limit(ctx->input, end_offset);
break;
case 'R':
@@ -420,16 +421,16 @@
}
}
-int mbox_skip_crlf(IBuffer *inbuf)
+int mbox_skip_crlf(IStream *input)
{
const unsigned char *data;
size_t size, pos;
pos = 0;
- while (i_buffer_read_data(inbuf, &data, &size, pos) > 0) {
+ while (i_stream_read_data(input, &data, &size, pos) > 0) {
if (pos == 0) {
if (data[0] == '\n') {
- i_buffer_skip(inbuf, 1);
+ i_stream_skip(input, 1);
return TRUE;
}
if (data[0] != '\r')
@@ -442,7 +443,7 @@
if (data[1] != '\n')
return FALSE;
- i_buffer_skip(inbuf, 2);
+ i_stream_skip(input, 2);
return TRUE;
}
}
@@ -451,32 +452,32 @@
return TRUE;
}
-void mbox_skip_empty_lines(IBuffer *inbuf)
+void mbox_skip_empty_lines(IStream *input)
{
const unsigned char *data;
size_t i, size;
/* skip empty lines at beginning */
- while (i_buffer_read_data(inbuf, &data, &size, 0) > 0) {
+ while (i_stream_read_data(input, &data, &size, 0) > 0) {
for (i = 0; i < size; i++) {
if (data[i] != '\r' && data[i] != '\n')
break;
}
- i_buffer_skip(inbuf, i);
+ i_stream_skip(input, i);
if (i < size)
break;
}
}
-static int mbox_is_valid_from(IBuffer *inbuf, size_t startpos)
+static int mbox_is_valid_from(IStream *input, size_t startpos)
{
const unsigned char *msg;
size_t i, size;
i = startpos;
- while (i_buffer_read_data(inbuf, &msg, &size, i) > 0) {
+ while (i_stream_read_data(input, &msg, &size, i) > 0) {
for (; i < size; i++) {
if (msg[i] == '\n') {
msg += startpos;
@@ -490,7 +491,7 @@
return FALSE;
}
-static void mbox_skip_forward(IBuffer *inbuf, int header)
+static void mbox_skip_forward(IStream *input, int header)
{
const unsigned char *msg;
size_t i, size, startpos, eoh;
@@ -500,7 +501,7 @@
buffer */
startpos = i = 0; eoh = 0; lastmsg = TRUE;
state = '\n';
- while (i_buffer_read_data(inbuf, &msg, &size, startpos) > 0) {
+ while (i_stream_read_data(input, &msg, &size, startpos) > 0) {
for (i = startpos; i < size; i++) {
new_state = 0;
switch (state) {
@@ -544,7 +545,7 @@
break;
case 'm':
if (msg[i] == ' ') {
- if (mbox_is_valid_from(inbuf, i+1)) {
+ if (mbox_is_valid_from(input, i+1)) {
/* Go back "From" */
i -= 4;
@@ -557,7 +558,7 @@
if (i > 0 && msg[i-1] == '\r')
i--;
- i_buffer_skip(inbuf, i);
+ i_stream_skip(input, i);
return;
}
}
@@ -570,7 +571,7 @@
state = msg[i] == '\n' ? '\n' : 0;
else {
/* end of header position confirmed */
- i_buffer_skip(inbuf, eoh);
+ i_stream_skip(input, eoh);
return;
}
}
@@ -585,20 +586,20 @@
eoh -= i;
}
- i_buffer_skip(inbuf, i);
+ i_stream_skip(input, i);
}
if (eoh != 0) {
/* make sure we didn't end with \n\n or \n\r\n. In these
cases the last [\r]\n doesn't belong to our message. */
if (eoh < size && (msg[eoh] != '\r' || eoh < size-1)) {
- i_buffer_skip(inbuf, eoh);
+ i_stream_skip(input, eoh);
return;
}
}
/* end of file, leave the last [\r]\n */
- msg = i_buffer_get_data(inbuf, &size);
+ msg = i_stream_get_data(input, &size);
if (size == startpos && startpos > 0) {
if (msg[startpos-1] == '\n')
startpos--;
@@ -606,39 +607,39 @@
startpos--;
}
- i_buffer_skip(inbuf, startpos);
+ i_stream_skip(input, startpos);
}
-void mbox_skip_header(IBuffer *inbuf)
+void mbox_skip_header(IStream *input)
{
- mbox_skip_forward(inbuf, TRUE);
+ mbox_skip_forward(input, TRUE);
}
-void mbox_skip_message(IBuffer *inbuf)
+void mbox_skip_message(IStream *input)
{
- mbox_skip_forward(inbuf, FALSE);
+ mbox_skip_forward(input, FALSE);
}
-int mbox_verify_end_of_body(IBuffer *inbuf, uoff_t end_offset)
+int mbox_verify_end_of_body(IStream *input, uoff_t end_offset)
{
const unsigned char *data;
size_t size;
- if (end_offset > inbuf->v_size) {
+ if (end_offset > input->v_size) {
/* missing data */
return FALSE;
}
- i_buffer_seek(inbuf, end_offset);
+ i_stream_seek(input, end_offset);
- if (inbuf->v_offset == inbuf->v_size) {
+ if (input->v_offset == input->v_size) {
/* end of file. a bit unexpected though,
since \n is missing. */
return TRUE;
}
/* read forward a bit */
- if (i_buffer_read_data(inbuf, &data, &size, 6) < 0)
+ if (i_stream_read_data(input, &data, &size, 6) < 0)
return FALSE;
/* either there should be the next From-line,
Index: mbox-index.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-index.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- mbox-index.h 2 Nov 2002 20:10:20 -0000 1.20
+++ mbox-index.h 6 Dec 2002 01:09:23 -0000 1.21
@@ -11,7 +11,7 @@
MD5Context md5;
int received;
- IBuffer *inbuf;
+ IStream *input;
uoff_t content_length;
int set_read_limit;
} MboxHeaderContext;
@@ -22,13 +22,13 @@
which is useful when you want to be sure you're not accessing a deleted
mbox file. */
int mbox_file_open(MailIndex *index);
-IBuffer *mbox_get_inbuf(MailIndex *index, uoff_t offset,
- MailLockType lock_type);
-void mbox_file_close_inbuf(MailIndex *index);
+IStream *mbox_get_stream(MailIndex *index, uoff_t offset,
+ MailLockType lock_type);
+void mbox_file_close_stream(MailIndex *index);
void mbox_file_close_fd(MailIndex *index);
void mbox_header_init_context(MboxHeaderContext *ctx, MailIndex *index,
- IBuffer *inbuf);
+ IStream *input);
void mbox_header_free_context(MboxHeaderContext *ctx);
void mbox_header_func(MessagePart *part __attr_unused__,
const char *name, size_t name_len,
@@ -38,11 +38,11 @@
const char *custom_flags[MAIL_CUSTOM_FLAGS_COUNT],
void (*func)(const char *, size_t, int, void *),
void *context);
-int mbox_skip_crlf(IBuffer *inbuf);
-void mbox_skip_empty_lines(IBuffer *inbuf);
-void mbox_skip_header(IBuffer *inbuf);
-void mbox_skip_message(IBuffer *inbuf);
-int mbox_verify_end_of_body(IBuffer *inbuf, uoff_t end_offset);
+int mbox_skip_crlf(IStream *input);
+void mbox_skip_empty_lines(IStream *input);
+void mbox_skip_header(IStream *input);
+void mbox_skip_message(IStream *input);
+int mbox_verify_end_of_body(IStream *input, uoff_t end_offset);
int mbox_mail_get_location(MailIndex *index, MailIndexRecord *rec,
uoff_t *offset, uoff_t *hdr_size, uoff_t *body_size);
@@ -50,10 +50,10 @@
int mbox_index_rebuild(MailIndex *index);
int mbox_index_sync(MailIndex *index, MailLockType lock_type, int *changes);
int mbox_sync_full(MailIndex *index);
-IBuffer *mbox_open_mail(MailIndex *index, MailIndexRecord *rec,
+IStream *mbox_open_mail(MailIndex *index, MailIndexRecord *rec,
time_t *internal_date, int *deleted);
-int mbox_index_append(MailIndex *index, IBuffer *inbuf);
+int mbox_index_append(MailIndex *index, IStream *input);
time_t mbox_from_parse_date(const char *msg, size_t size);
const char *mbox_from_create(const char *sender, time_t time);
Index: mbox-lock.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-lock.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- mbox-lock.c 26 Nov 2002 19:01:24 -0000 1.17
+++ mbox-lock.c 6 Dec 2002 01:09:23 -0000 1.18
@@ -390,7 +390,7 @@
been changes to file size which would break things. or actually
it'd break only if file was shrinked+grown back to exact size,
but still possible :) */
- mbox_file_close_inbuf(index);
+ mbox_file_close_stream(index);
index->mbox_lock_type = MAIL_LOCK_UNLOCK;
return !failed;
Index: mbox-open.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-open.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- mbox-open.c 27 Oct 2002 06:37:18 -0000 1.18
+++ mbox-open.c 6 Dec 2002 01:09:23 -0000 1.19
@@ -1,7 +1,7 @@
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
-#include "ibuffer.h"
+#include "istream.h"
#include "mbox-index.h"
#include "mail-index-data.h"
#include "mail-index-util.h"
@@ -10,10 +10,10 @@
#include <unistd.h>
#include <fcntl.h>
-IBuffer *mbox_open_mail(MailIndex *index, MailIndexRecord *rec,
+IStream *mbox_open_mail(MailIndex *index, MailIndexRecord *rec,
time_t *internal_date, int *deleted)
{
- IBuffer *inbuf;
+ IStream *input;
uoff_t offset, hdr_size, body_size;
i_assert(index->lock_type != MAIL_LOCK_UNLOCK);
@@ -27,8 +27,8 @@
if (!mbox_mail_get_location(index, rec, &offset, &hdr_size, &body_size))
return NULL;
- inbuf = mbox_get_inbuf(index, offset, MAIL_LOCK_SHARED);
- if (inbuf == NULL)
+ input = mbox_get_stream(index, offset, MAIL_LOCK_SHARED);
+ if (input == NULL)
return NULL;
if (internal_date != NULL)
@@ -36,6 +36,6 @@
i_assert(index->mbox_sync_counter == index->mbox_lock_counter);
- i_buffer_set_read_limit(inbuf, hdr_size + body_size);
- return inbuf;
+ i_stream_set_read_limit(input, hdr_size + body_size);
+ return input;
}
Index: mbox-rebuild.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-rebuild.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- mbox-rebuild.c 2 Nov 2002 22:47:33 -0000 1.19
+++ mbox-rebuild.c 6 Dec 2002 01:09:23 -0000 1.20
@@ -1,7 +1,7 @@
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
-#include "ibuffer.h"
+#include "istream.h"
#include "mbox-index.h"
#include "mbox-lock.h"
#include "mail-index-data.h"
@@ -14,7 +14,7 @@
int mbox_index_rebuild(MailIndex *index)
{
- IBuffer *inbuf;
+ IStream *input;
struct stat st;
int failed;
@@ -43,14 +43,14 @@
if (!mail_index_data_reset(index->data))
return FALSE;
- inbuf = mbox_get_inbuf(index, 0, MAIL_LOCK_SHARED);
- if (inbuf == NULL)
+ input = mbox_get_stream(index, 0, MAIL_LOCK_SHARED);
+ if (input == NULL)
return FALSE;
- mbox_skip_empty_lines(inbuf);
- failed = !mbox_index_append(index, inbuf);
+ mbox_skip_empty_lines(input);
+ failed = !mbox_index_append(index, input);
- i_buffer_unref(inbuf);
+ i_stream_unref(input);
if (failed)
return FALSE;
Index: mbox-rewrite.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-rewrite.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- mbox-rewrite.c 26 Nov 2002 13:07:53 -0000 1.41
+++ mbox-rewrite.c 6 Dec 2002 01:09:23 -0000 1.42
@@ -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 "temp-string.h"
#include "write-full.h"
#include "mbox-index.h"
@@ -16,7 +16,7 @@
#include <fcntl.h>
typedef struct {
- OBuffer *outbuf;
+ OStream *output;
int failed;
uoff_t content_length;
@@ -49,21 +49,22 @@
MAIL_INDEX_FLAG_DIRTY_CUSTOMFLAGS);
}
-static int mbox_write(MailIndex *index, IBuffer *inbuf, OBuffer *outbuf,
+static int mbox_write(MailIndex *index, IStream *input, OStream *output,
uoff_t end_offset)
{
uoff_t old_limit;
int failed;
- i_assert(inbuf->v_offset <= end_offset);
+ i_assert(input->v_offset <= end_offset);
- old_limit = inbuf->v_limit;
- i_buffer_set_read_limit(inbuf, end_offset);
- if (o_buffer_send_ibuffer(outbuf, inbuf) < 0) {
+ old_limit = input->v_limit;
+ i_stream_set_read_limit(input, end_offset);
+ if (o_stream_send_istream(output, input) < 0) {
index_set_error(index, "Error rewriting mbox file %s: %s",
- index->mbox_path, strerror(outbuf->buf_errno));
+ index->mbox_path,
+ strerror(output->stream_errno));
failed = TRUE;
- } else if (inbuf->v_offset < end_offset) {
+ } else if (input->v_offset < end_offset) {
/* fsck should have noticed it.. */
index_set_error(index, "Error rewriting mbox file %s: "
"Unexpected end of file", index->mbox_path);
@@ -72,7 +73,7 @@
failed = FALSE;
}
- i_buffer_set_read_limit(inbuf, old_limit);
+ i_stream_set_read_limit(input, old_limit);
return !failed;
}
@@ -83,21 +84,21 @@
str = t_strdup_printf("X-IMAPbase: %u %u",
ctx->uid_validity, ctx->uid_last);
- if (o_buffer_send(ctx->outbuf, str, strlen(str)) < 0)
+ if (o_stream_send(ctx->output, str, strlen(str)) < 0)
return FALSE;
for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++) {
if (ctx->custom_flags[i] != NULL) {
- if (o_buffer_send(ctx->outbuf, " ", 1) < 0)
+ if (o_stream_send(ctx->output, " ", 1) < 0)
return FALSE;
- if (o_buffer_send(ctx->outbuf, ctx->custom_flags[i],
+ if (o_stream_send(ctx->output, ctx->custom_flags[i],
strlen(ctx->custom_flags[i])) < 0)
return FALSE;
}
}
- if (o_buffer_send(ctx->outbuf, "\n", 1) < 0)
+ if (o_stream_send(ctx->output, "\n", 1) < 0)
return FALSE;
return TRUE;
@@ -112,16 +113,16 @@
x_keywords == NULL)
return TRUE;
- if (o_buffer_send(ctx->outbuf, "X-Keywords:", 11) < 0)
+ if (o_stream_send(ctx->output, "X-Keywords:", 11) < 0)
return FALSE;
field = 1 << MAIL_CUSTOM_FLAG_1_BIT;
for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++, field <<= 1) {
if ((ctx->msg_flags & field) && ctx->custom_flags[i] != NULL) {
- if (o_buffer_send(ctx->outbuf, " ", 1) < 0)
+ if (o_stream_send(ctx->output, " ", 1) < 0)
return FALSE;
- if (o_buffer_send(ctx->outbuf, ctx->custom_flags[i],
+ if (o_stream_send(ctx->output, ctx->custom_flags[i],
strlen(ctx->custom_flags[i])) < 0)
return FALSE;
}
@@ -129,15 +130,15 @@
if (x_keywords != NULL) {
/* X-Keywords that aren't custom flags */
- if (o_buffer_send(ctx->outbuf, " ", 1) < 0)
+ if (o_stream_send(ctx->output, " ", 1) < 0)
return FALSE;
- if (o_buffer_send(ctx->outbuf, x_keywords,
+ if (o_stream_send(ctx->output, x_keywords,
strlen(x_keywords)) < 0)
return FALSE;
}
- if (o_buffer_send(ctx->outbuf, "\n", 1) < 0)
+ if (o_stream_send(ctx->output, "\n", 1) < 0)
return FALSE;
return TRUE;
@@ -151,9 +152,9 @@
if (status != NULL)
str = t_strconcat(str, status, NULL);
- if (o_buffer_send(ctx->outbuf, str, strlen(str)) < 0)
+ if (o_stream_send(ctx->output, str, strlen(str)) < 0)
return FALSE;
- if (o_buffer_send(ctx->outbuf, "\n", 1) < 0)
+ if (o_stream_send(ctx->output, "\n", 1) < 0)
return FALSE;
return TRUE;
@@ -175,9 +176,9 @@
(ctx->msg_flags & MAIL_DELETED) ? "T" : "",
x_status, NULL);
- if (o_buffer_send(ctx->outbuf, str, strlen(str)) < 0)
+ if (o_stream_send(ctx->output, str, strlen(str)) < 0)
return FALSE;
- if (o_buffer_send(ctx->outbuf, "\n", 1) < 0)
+ if (o_stream_send(ctx->output, "\n", 1) < 0)
return FALSE;
return TRUE;
@@ -190,7 +191,7 @@
i_snprintf(str, sizeof(str), "Content-Length: %"PRIuUOFF_T"\n",
ctx->content_length);
- if (o_buffer_send(ctx->outbuf, str, strlen(str)) < 0)
+ if (o_stream_send(ctx->output, str, strlen(str)) < 0)
return FALSE;
return TRUE;
}
@@ -283,19 +284,19 @@
(void)mbox_write_content_length(ctx);
} else if (name_len > 0) {
/* save this header */
- (void)o_buffer_send(ctx->outbuf, name, name_len);
- (void)o_buffer_send(ctx->outbuf, ": ", 2);
- (void)o_buffer_send(ctx->outbuf, value, value_len);
- (void)o_buffer_send(ctx->outbuf, "\n", 1);
+ (void)o_stream_send(ctx->output, name, name_len);
+ (void)o_stream_send(ctx->output, ": ", 2);
+ (void)o_stream_send(ctx->output, value, value_len);
+ (void)o_stream_send(ctx->output, "\n", 1);
}
- if (ctx->outbuf->closed)
+ if (ctx->output->closed)
ctx->failed = TRUE;
}
static int mbox_write_header(MailIndex *index,
MailIndexRecord *rec, unsigned int seq,
- IBuffer *inbuf, OBuffer *outbuf, uoff_t end_offset,
+ IStream *input, OStream *output, uoff_t end_offset,
uoff_t hdr_size, uoff_t body_size)
{
/* We need to update fields that define message flags. Standard fields
@@ -312,7 +313,7 @@
MboxRewriteContext ctx;
MessageSize hdr_parsed_size;
- if (inbuf->v_offset >= end_offset) {
+ if (input->v_offset >= end_offset) {
/* fsck should have noticed it.. */
index_set_error(index, "Error rewriting mbox file %s: "
"Unexpected end of file", index->mbox_path);
@@ -323,16 +324,16 @@
/* parse the header, write the fields we don't want to change */
memset(&ctx, 0, sizeof(ctx));
- ctx.outbuf = outbuf;
+ ctx.output = output;
ctx.seq = seq;
ctx.content_length = body_size;
ctx.msg_flags = rec->msg_flags;
ctx.uid_validity = index->header->uid_validity-1;
ctx.custom_flags = mail_custom_flags_list_get(index->custom_flags);
- i_buffer_set_read_limit(inbuf, inbuf->v_offset + hdr_size);
- message_parse_header(NULL, inbuf, &hdr_parsed_size, header_func, &ctx);
- i_buffer_set_read_limit(inbuf, 0);
+ i_stream_set_read_limit(input, input->v_offset + hdr_size);
+ message_parse_header(NULL, input, &hdr_parsed_size, header_func, &ctx);
+ i_stream_set_read_limit(input, 0);
i_assert(hdr_parsed_size.physical_size == hdr_size);
@@ -354,15 +355,15 @@
t_pop();
/* empty line ends headers */
- (void)o_buffer_send(outbuf, "\n", 1);
+ (void)o_stream_send(output, "\n", 1);
return TRUE;
}
static int fd_copy(int in_fd, int out_fd, uoff_t out_offset)
{
- IBuffer *inbuf;
- OBuffer *outbuf;
+ IStream *input;
+ OStream *output;
int ret;
i_assert(out_offset <= OFF_T_MAX);
@@ -372,22 +373,22 @@
t_push();
- inbuf = i_buffer_create_mmap(in_fd, data_stack_pool,
+ input = i_stream_create_mmap(in_fd, data_stack_pool,
1024*256, 0, 0, FALSE);
- outbuf = o_buffer_create_file(out_fd, data_stack_pool, 1024, 0, FALSE);
- o_buffer_set_blocking(outbuf, 60000, NULL, NULL);
+ output = o_stream_create_file(out_fd, data_stack_pool, 1024, 0, FALSE);
+ o_stream_set_blocking(output, 60000, NULL, NULL);
- ret = o_buffer_send_ibuffer(outbuf, inbuf);
+ ret = o_stream_send_istream(output, input);
if (ret < 0)
- errno = outbuf->buf_errno;
+ errno = output->stream_errno;
else {
/* we may have shrinked the file */
- i_assert(out_offset + inbuf->v_size <= OFF_T_MAX);
- ret = ftruncate(out_fd, (off_t) (out_offset + inbuf->v_size));
+ i_assert(out_offset + input->v_size <= OFF_T_MAX);
+ ret = ftruncate(out_fd, (off_t) (out_offset + input->v_size));
}
- o_buffer_unref(outbuf);
- i_buffer_unref(inbuf);
+ o_stream_unref(output);
+ i_stream_unref(input);
t_pop();
return ret;
@@ -403,8 +404,8 @@
interrupted (see below). This rewriting relies quite a lot on
valid header/body sizes which fsck() should have ensured. */
MailIndexRecord *rec;
- IBuffer *inbuf;
- OBuffer *outbuf;
+ IStream *input;
+ OStream *output;
uoff_t offset, hdr_size, body_size, dirty_offset;
const char *path;
unsigned int seq;
@@ -426,7 +427,7 @@
return TRUE;
}
- tmp_fd = -1; inbuf = NULL;
+ tmp_fd = -1; input = NULL;
failed = TRUE; rewrite = FALSE;
do {
if (!index->set_lock(index, MAIL_LOCK_EXCLUSIVE))
@@ -435,8 +436,8 @@
if (!index->sync_and_lock(index, MAIL_LOCK_EXCLUSIVE, NULL))
break;
- inbuf = mbox_get_inbuf(index, 0, MAIL_LOCK_EXCLUSIVE);
- if (inbuf == NULL)
+ input = mbox_get_stream(index, 0, MAIL_LOCK_EXCLUSIVE);
+ if (input == NULL)
break;
if ((index->header->flags & INDEX_DIRTY_FLAGS) == 0) {
@@ -456,8 +457,8 @@
if (!rewrite) {
if (!index->set_lock(index, MAIL_LOCK_UNLOCK))
failed = TRUE;
- if (inbuf != NULL)
- i_buffer_unref(inbuf);
+ if (input != NULL)
+ i_stream_unref(input);
return !failed;
}
@@ -469,10 +470,10 @@
}
dirty_offset = 0;
- /* note: we can't use data_stack_pool with outbuf because it's
+ /* note: we can't use data_stack_pool with output stream because it's
being written to inside t_push() .. t_pop() calls */
- outbuf = o_buffer_create_file(tmp_fd, system_pool, 8192, 0, FALSE);
- o_buffer_set_blocking(outbuf, 60000, NULL, NULL);
+ output = o_stream_create_file(tmp_fd, system_pool, 8192, 0, FALSE);
+ o_stream_set_blocking(output, 60000, NULL, NULL);
failed = FALSE; seq = 1;
rec = index->lookup(index, 1);
@@ -486,14 +487,14 @@
break;
}
- if (offset < inbuf->v_offset) {
+ if (offset < input->v_offset) {
index_set_corrupted(index,
"Invalid message offset");
failed = TRUE;
break;
}
- if (offset + hdr_size + body_size > inbuf->v_size) {
+ if (offset + hdr_size + body_size > input->v_size) {
index_set_corrupted(index,
"Invalid message size");
failed = TRUE;
@@ -507,19 +508,19 @@
dirty_found = TRUE;
dirty_offset = offset;
- i_buffer_seek(inbuf, dirty_offset);
+ i_stream_seek(input, dirty_offset);
}
if (dirty_found) {
/* write the From-line */
- if (!mbox_write(index, inbuf, outbuf, offset)) {
+ if (!mbox_write(index, input, output, offset)) {
failed = TRUE;
break;
}
/* write header, updating flag fields */
offset += hdr_size;
- if (!mbox_write_header(index, rec, seq, inbuf, outbuf,
+ if (!mbox_write_header(index, rec, seq, input, output,
offset, hdr_size, body_size)) {
failed = TRUE;
break;
@@ -527,7 +528,7 @@
/* write body */
offset += body_size;
- if (!mbox_write(index, inbuf, outbuf, offset)) {
+ if (!mbox_write(index, input, output, offset)) {
failed = TRUE;
break;
}
@@ -545,17 +546,17 @@
if (!failed) {
/* always end with a \n */
- (void)o_buffer_send(outbuf, "\n", 1);
+ (void)o_stream_send(output, "\n", 1);
}
- if (outbuf->closed) {
- errno = outbuf->buf_errno;
+ if (output->closed) {
+ errno = output->stream_errno;
mbox_set_syscall_error(index, "write()");
failed = TRUE;
}
- i_buffer_unref(inbuf);
- o_buffer_unref(outbuf);
+ i_stream_unref(input);
+ o_stream_unref(output);
if (!failed) {
/* POSSIBLE DATA LOSS HERE. We're writing to the mbox file,
Index: mbox-sync-full.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-sync-full.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mbox-sync-full.c 4 Nov 2002 04:47:40 -0000 1.4
+++ mbox-sync-full.c 6 Dec 2002 01:09:23 -0000 1.5
@@ -1,7 +1,7 @@
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
-#include "ibuffer.h"
+#include "istream.h"
#include "hex-binary.h"
#include "message-parser.h"
#include "message-part-serialize.h"
@@ -12,20 +12,20 @@
#include <unistd.h>
#include <fcntl.h>
-static void skip_line(IBuffer *inbuf)
+static void skip_line(IStream *input)
{
const unsigned char *msg;
size_t i, size;
- while (i_buffer_read_data(inbuf, &msg, &size, 0) > 0) {
+ while (i_stream_read_data(input, &msg, &size, 0) > 0) {
for (i = 0; i < size; i++) {
if (msg[i] == '\n') {
- i_buffer_skip(inbuf, i+1);
+ i_stream_skip(input, i+1);
return;
}
}
- i_buffer_skip(inbuf, i);
+ i_stream_skip(input, i);
}
}
@@ -90,7 +90,7 @@
}
static int match_next_record(MailIndex *index, MailIndexRecord *rec,
- unsigned int seq, IBuffer *inbuf,
+ unsigned int seq, IStream *input,
MailIndexRecord **next_rec, int *dirty)
{
MailIndexUpdate *update;
@@ -102,8 +102,8 @@
*next_rec = NULL;
/* skip the From-line */
- skip_line(inbuf);
- header_offset = inbuf->v_offset;
+ skip_line(input);
+ header_offset = input->v_offset;
if (!mbox_mail_get_location(index, rec, NULL, &hdr_size, &body_size))
return FALSE;
@@ -111,25 +111,25 @@
if (body_size == 0) {
/* possibly broken message, find the next From-line and make
sure header parser won't pass it. */
- mbox_skip_header(inbuf);
- i_buffer_set_read_limit(inbuf, inbuf->v_offset);
- i_buffer_seek(inbuf, header_offset);
+ mbox_skip_header(input);
+ i_stream_set_read_limit(input, input->v_offset);
+ i_stream_seek(input, header_offset);
}
/* get the MD5 sum of fixed headers and the current message flags
in Status and X-Status fields */
- mbox_header_init_context(&ctx, index, inbuf);
- message_parse_header(NULL, inbuf, &hdr_parsed_size,
+ mbox_header_init_context(&ctx, index, input);
+ message_parse_header(NULL, input, &hdr_parsed_size,
mbox_header_func, &ctx);
md5_final(&ctx.md5, current_digest);
mbox_header_free_context(&ctx);
- i_buffer_set_read_limit(inbuf, 0);
+ i_stream_set_read_limit(input, 0);
- body_offset = inbuf->v_offset;
+ body_offset = input->v_offset;
do {
if (verify_header_md5sum(index, rec, current_digest) &&
- mbox_verify_end_of_body(inbuf, body_offset + body_size)) {
+ mbox_verify_end_of_body(input, body_offset + body_size)) {
/* valid message */
update = index->update_begin(index, rec);
@@ -179,7 +179,7 @@
return TRUE;
}
-static int mbox_sync_buf(MailIndex *index, IBuffer *inbuf)
+static int mbox_sync_from_stream(MailIndex *index, IStream *input)
{
MailIndexRecord *rec;
uoff_t from_offset;
@@ -188,11 +188,11 @@
unsigned int seq;
int dirty;
- mbox_skip_empty_lines(inbuf);
+ mbox_skip_empty_lines(input);
/* first make sure we start with a "From " line. If file is too
small, we'll just treat it as empty mbox file. */
- if (i_buffer_read_data(inbuf, &data, &size, 5) > 0 &&
+ if (i_stream_read_data(input, &data, &size, 5) > 0 &&
strncmp((const char *) data, "From ", 5) != 0) {
index_set_error(index, "File isn't in mbox format: %s",
index->mbox_path);
@@ -212,11 +212,11 @@
dirty = FALSE;
while (rec != NULL) {
- from_offset = inbuf->v_offset;
- if (inbuf->v_offset != 0) {
+ from_offset = input->v_offset;
+ if (input->v_offset != 0) {
/* we're at the [\r]\n before the From-line,
skip it */
- if (!mbox_skip_crlf(inbuf)) {
+ if (!mbox_skip_crlf(input)) {
/* they just went and broke it, even while
we had it locked. */
index_set_error(index,
@@ -227,15 +227,15 @@
}
}
- if (inbuf->v_offset == inbuf->v_size)
+ if (input->v_offset == input->v_size)
break;
- if (!match_next_record(index, rec, seq, inbuf, &rec, &dirty))
+ if (!match_next_record(index, rec, seq, input, &rec, &dirty))
return FALSE;
if (rec == NULL) {
/* Get back to line before From */
- i_buffer_seek(inbuf, from_offset);
+ i_stream_seek(input, from_offset);
break;
}
@@ -255,25 +255,25 @@
index->header->flags &= ~MAIL_INDEX_FLAG_DIRTY_MESSAGES;
}
- if (inbuf->v_offset == inbuf->v_size)
+ if (input->v_offset == input->v_size)
return TRUE;
else
- return mbox_index_append(index, inbuf);
+ return mbox_index_append(index, input);
}
int mbox_sync_full(MailIndex *index)
{
- IBuffer *inbuf;
+ IStream *input;
int failed;
i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
- inbuf = mbox_get_inbuf(index, 0, MAIL_LOCK_SHARED);
- if (inbuf == NULL)
+ input = mbox_get_stream(index, 0, MAIL_LOCK_SHARED);
+ if (input == NULL)
return FALSE;
- failed = !mbox_sync_buf(index, inbuf);
- i_buffer_unref(inbuf);
+ failed = !mbox_sync_from_stream(index, input);
+ i_stream_unref(input);
return !failed;
}
Index: mbox-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-sync.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- mbox-sync.c 26 Nov 2002 19:01:24 -0000 1.25
+++ mbox-sync.c 6 Dec 2002 01:09:23 -0000 1.26
@@ -119,7 +119,7 @@
}
if (index_mtime != st.st_mtime || index->mbox_size != filesize) {
- mbox_file_close_inbuf(index);
+ mbox_file_close_stream(index);
index->mbox_size = get_indexed_mbox_size(index);
if (index->file_sync_stamp == 0 &&
- Previous message: [dovecot-cvs] dovecot/src/lib-imap imap-bodystructure.c,1.19,1.20 imap-bodystructure.h,1.4,1.5 imap-envelope.c,1.12,1.13 imap-message-cache.c,1.24,1.25 imap-message-cache.h,1.12,1.13 imap-parser.c,1.22,1.23 imap-parser.h,1.4,1.5
- Next message: [dovecot-cvs] dovecot/src/lib-storage mail-sort.c,1.2,1.3 mail-storage.h,1.21,1.22
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the dovecot-cvs
mailing list