[dovecot-cvs] dovecot/src/lib-storage/index index-mail-headers.c, 1.22, 1.23 index-mail.c, 1.39, 1.40 index-mail.h, 1.14, 1.15

cras at procontrol.fi cras at procontrol.fi
Mon Jul 5 00:07:45 EEST 2004


Update of /home/cvs/dovecot/src/lib-storage/index
In directory talvi:/tmp/cvs-serv30743/lib-storage/index

Modified Files:
	index-mail-headers.c index-mail.c index-mail.h 
Log Message:
Cache API updates. Don't return direct pointers to mmaped cache file anymore.



Index: index-mail-headers.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-mail-headers.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- index-mail-headers.c	4 Jul 2004 20:00:47 -0000	1.22
+++ index-mail-headers.c	4 Jul 2004 21:07:43 -0000	1.23
@@ -419,30 +419,29 @@
 	struct message_header_parser_ctx *hdr_ctx;
 	struct message_header_line *hdr;
 	struct istream *istream;
-	const char *str, *const *idx_headers;
+	const char *const *idx_headers;
+	string_t *str;
 
-	t_push();
 	if (idx < data->header_data_cached) {
 		/* it's already in header_data. */
-		istream = i_stream_create_from_data(pool_datastack_create(),
+		istream = i_stream_create_from_data(mail->pool,
 						    str_data(data->header_data),
 						    str_len(data->header_data));
 		/* we might be parsing a bit more.. */
 		idx = data->header_data_cached-1;
 		data->header_stream = istream;
 	} else {
-		str = mail_cache_lookup_string_field(
-			mail->trans->cache_view, data->seq,
-			mail_cache_header_fields[idx]);
-		if (str == NULL) {
+		str = str_new(mail->pool, 32);
+		if (!mail_cache_lookup_string_field(
+				mail->trans->cache_view, str, data->seq,
+				mail_cache_header_fields[idx])) {
 			/* broken - we expected the header to exist */
-			t_pop();
 			return FALSE;
 		}
 
 		data->header_data_cached_partial = TRUE;
-		istream = i_stream_create_from_data(pool_datastack_create(),
-						    str, strlen(str));
+		istream = i_stream_create_from_data(mail->pool, str_data(str),
+						    str_len(str));
 	}
 
 	idx_headers = mail_cache_get_header_fields(mail->trans->cache_view,
@@ -450,7 +449,6 @@
 	if (idx_headers == NULL) {
 		mail_cache_set_corrupted(mail->ibox->cache,
 			"Headers %d names not found", idx);
-		t_pop();
 		return FALSE;
 	}
 
@@ -466,7 +464,6 @@
 
 	data->header_stream = NULL;
 	i_stream_unref(istream);
-	t_pop();
 
 	return TRUE;
 }
@@ -485,7 +482,7 @@
 int index_mail_parse_headers(struct index_mail *mail)
 {
 	struct index_mail_data *data = &mail->data;
-	const char *str, *const *headers;
+	const char *const *headers;
 	int idx, max;
 
 	if (data->stream == NULL) {
@@ -508,14 +505,12 @@
 		/* add all cached headers to beginning of header_data */
                 idx = data->header_data_cached; max = idx-1;
 		for (; idx < MAIL_CACHE_HEADERS_COUNT; idx++) {
-			str = mail_cache_lookup_string_field(
-				mail->trans->cache_view, mail->data.seq,
-				mail_cache_header_fields[idx]);
-			if (str == NULL)
+			if (!mail_cache_lookup_string_field(
+				mail->trans->cache_view, mail->data.header_data,
+				mail->data.seq, mail_cache_header_fields[idx]))
 				continue;
 
 			max = idx;
-			str_append(mail->data.header_data, str);
 		}
 		data->header_data_cached = max+1;
 		data->header_data_uncached_offset =
@@ -635,7 +630,7 @@
 	struct index_mail *mail = (struct index_mail *) _mail;
 	struct index_mail_data *data = &mail->data;
 	struct cached_header *hdr;
-	const char *const *tmp, *str;
+	const char *const *tmp;
 	int i, idx, all_saved;
 
 	i_assert(*minimum_fields != NULL);
@@ -652,13 +647,9 @@
 			trash_partial_headers(mail);
 		}
 		for (i = data->header_data_cached; i <= idx; i++) {
-			str = mail_cache_lookup_string_field(
-					mail->trans->cache_view, data->seq,
-					mail_cache_header_fields[i]);
-			if (str == NULL)
-				continue;
-
-			str_append(data->header_data, str);
+			(void)mail_cache_lookup_string_field(
+				mail->trans->cache_view, data->header_data,
+				data->seq, mail_cache_header_fields[i]);
 		}
 		data->header_data_cached = idx+1;
 		data->header_data_uncached_offset = str_len(data->header_data);

Index: index-mail.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-mail.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- index-mail.c	4 Jul 2004 20:00:47 -0000	1.39
+++ index-mail.c	4 Jul 2004 21:07:43 -0000	1.40
@@ -18,9 +18,8 @@
 static struct message_part *get_cached_parts(struct index_mail *mail)
 {
 	struct message_part *part;
-	const void *part_data;
+	buffer_t *part_buf;
 	const char *error;
-	size_t part_size;
 
 	if ((mail->data.cached_fields & MAIL_CACHE_MESSAGEPART) == 0) {
 		mail_cache_mark_missing(mail->trans->cache_view, mail->data.seq,
@@ -28,14 +27,17 @@
 		return NULL;
 	}
 
-	if (!mail_cache_lookup_field(mail->trans->cache_view, mail->data.seq,
-				     MAIL_CACHE_MESSAGEPART,
-				     &part_data, &part_size)) {
+	part_buf = buffer_create_dynamic(pool_datastack_create(),
+					 128, (size_t)-1);
+	if (!mail_cache_lookup_field(mail->trans->cache_view, part_buf,
+				     mail->data.seq, MAIL_CACHE_MESSAGEPART)) {
 		/* unexpected - must be an error */
 		return NULL;
 	}
 
-	part = message_part_deserialize(mail->pool, part_data, part_size,
+	part = message_part_deserialize(mail->pool,
+					buffer_get_data(part_buf, NULL),
+					buffer_get_used_size(part_buf),
 					&error);
 	if (part == NULL) {
 		mail_cache_set_corrupted(mail->ibox->cache,
@@ -55,10 +57,10 @@
 	return part;
 }
 
-char *index_mail_get_cached_string(struct index_mail *mail,
-				   enum mail_cache_field field)
+const char *index_mail_get_cached_string(struct index_mail *mail,
+					 enum mail_cache_field field)
 {
-	const char *ret;
+	string_t *str;
 
 	if ((mail->data.cached_fields & field) == 0) {
 		mail_cache_mark_missing(mail->trans->cache_view,
@@ -66,9 +68,35 @@
 		return NULL;
 	}
 
-	ret = mail_cache_lookup_string_field(mail->trans->cache_view,
-					     mail->data.seq, field);
-	return p_strdup(mail->pool, ret);
+	str = str_new(mail->pool, 32);
+	if (!mail_cache_lookup_string_field(mail->trans->cache_view, str,
+					    mail->data.seq, field))
+		return NULL;
+
+	return str_c(str);
+}
+
+static int index_mail_get_fixed_field(struct index_mail *mail,
+				      enum mail_cache_field field,
+				      void *data, size_t data_size)
+{
+	buffer_t *buf;
+	int ret;
+
+	t_push();
+	buf = buffer_create_data(pool_datastack_create(), data, data_size);
+	if (!mail_cache_lookup_field(mail->trans->cache_view, buf,
+				     mail->data.seq, field)) {
+		mail_cache_mark_missing(mail->trans->cache_view,
+					mail->data.seq, field);
+		ret = FALSE;
+	} else {
+		i_assert(buffer_get_used_size(buf) == data_size);
+		ret = TRUE;
+	}
+	t_pop();
+
+	return ret;
 }
 
 uoff_t index_mail_get_cached_uoff_t(struct index_mail *mail,
@@ -76,13 +104,8 @@
 {
 	uoff_t uoff;
 
-	if (!mail_cache_copy_fixed_field(mail->trans->cache_view,
-					 mail->data.seq, field,
-					 &uoff, sizeof(uoff))) {
-		mail_cache_mark_missing(mail->trans->cache_view,
-					mail->data.seq, field);
+	if (!index_mail_get_fixed_field(mail, field, &uoff, sizeof(uoff)))
 		uoff = (uoff_t)-1;
-	}
 
 	return uoff;
 }
@@ -96,28 +119,17 @@
 {
 	time_t t;
 
-	if (!mail_cache_copy_fixed_field(mail->trans->cache_view,
-					 mail->data.seq,
-					 MAIL_CACHE_RECEIVED_DATE,
-					 &t, sizeof(t))) {
-		mail_cache_mark_missing(mail->trans->cache_view, mail->data.seq,
-					MAIL_CACHE_RECEIVED_DATE);
+	if (!index_mail_get_fixed_field(mail, MAIL_CACHE_RECEIVED_DATE,
+					&t, sizeof(t)))
 		t = (time_t)-1;
-	}
-
 	return t;
 }
 
 static void get_cached_sent_date(struct index_mail *mail,
 				 struct mail_sent_date *sent_date)
 {
-	if (!mail_cache_copy_fixed_field(mail->trans->cache_view,
-					 mail->data.seq,
-					 MAIL_CACHE_SENT_DATE,
-					 sent_date, sizeof(*sent_date))) {
-		mail_cache_mark_missing(mail->trans->cache_view, mail->data.seq,
-					MAIL_CACHE_SENT_DATE);
-
+	if (!index_mail_get_fixed_field(mail, MAIL_CACHE_SENT_DATE,
+					sent_date, sizeof(*sent_date))) {
 		sent_date->time = (time_t)-1;
 		sent_date->timezone = 0;
 	}

Index: index-mail.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-mail.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- index-mail.h	4 Jul 2004 20:00:47 -0000	1.14
+++ index-mail.h	4 Jul 2004 21:07:43 -0000	1.15
@@ -109,8 +109,8 @@
 			    enum modify_type modify_type);
 int index_mail_expunge(struct mail *mail);
 
-char *index_mail_get_cached_string(struct index_mail *mail,
-				   enum mail_cache_field field);
+const char *index_mail_get_cached_string(struct index_mail *mail,
+					 enum mail_cache_field field);
 uoff_t index_mail_get_cached_uoff_t(struct index_mail *mail,
 				    enum mail_cache_field field);
 uoff_t index_mail_get_cached_virtual_size(struct index_mail *mail);



More information about the dovecot-cvs mailing list