[dovecot-cvs] dovecot/src/lib-index Makefile.am, 1.27, 1.28 mail-cache-fields.c, 1.22, 1.23

tss at dovecot.org tss at dovecot.org
Fri Oct 13 16:18:44 UTC 2006


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv17982

Modified Files:
	Makefile.am mail-cache-fields.c 
Log Message:
When registering fields, if they were already exited in the cache file mark
the cache file corrupted.



Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/Makefile.am,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- Makefile.am	11 Jul 2006 16:04:21 -0000	1.27
+++ Makefile.am	13 Oct 2006 15:18:39 -0000	1.28
@@ -28,7 +28,9 @@
         mail-transaction-log.c \
         mail-transaction-log-append.c \
         mail-transaction-log-view.c \
-        mail-transaction-util.c
+        mail-transaction-util.c \
+        mailbox-list-index.c \
+        mailbox-list-index-sync.c
 
 noinst_HEADERS = \
 	mail-cache.h \
@@ -41,4 +43,6 @@
 	mail-index-view-private.h \
         mail-transaction-log.h \
 	mail-transaction-log-private.h \
-        mail-transaction-util.h
+        mail-transaction-util.h \
+        mailbox-list-index.h \
+        mailbox-list-index-private.h

Index: mail-cache-fields.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-fields.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- mail-cache-fields.c	16 Jun 2006 09:26:52 -0000	1.22
+++ mail-cache-fields.c	13 Oct 2006 15:18:40 -0000	1.23
@@ -11,6 +11,40 @@
 
 #define CACHE_HDR_PREFETCH 1024
 
+static bool field_has_fixed_size(enum mail_cache_field_type type)
+{
+	switch (type) {
+	case MAIL_CACHE_FIELD_FIXED_SIZE:
+	case MAIL_CACHE_FIELD_BITMASK:
+		return TRUE;
+	case MAIL_CACHE_FIELD_VARIABLE_SIZE:
+	case MAIL_CACHE_FIELD_STRING:
+	case MAIL_CACHE_FIELD_HEADER:
+		return FALSE;
+	}
+
+	i_unreached();
+	return FALSE;
+}
+
+static int field_type_verify(struct mail_cache *cache, unsigned int idx,
+			     enum mail_cache_field_type type, unsigned int size)
+{
+	const struct mail_cache_field *field = &cache->fields[idx].field;
+
+	if (field->type != type) {
+		mail_cache_set_corrupted(cache,
+			"registered field %s type changed", field->name);
+		return -1;
+	}
+	if (field->field_size != size && field_has_fixed_size(type)) {
+		mail_cache_set_corrupted(cache,
+			"registered field %s size changed", field->name);
+		return -1;
+	}
+	return 0;
+}
+
 void mail_cache_register_fields(struct mail_cache *cache,
 				struct mail_cache_field *fields,
 				unsigned int fields_count)
@@ -26,6 +60,9 @@
 				     &orig_key, &orig_value)) {
 			fields[i].idx =
 				POINTER_CAST_TO(orig_value, unsigned int);
+			(void)field_type_verify(cache, fields[i].idx,
+						fields[i].type,
+						fields[i].field_size);
 			continue;
 		}
 
@@ -66,16 +103,8 @@
 		cache->fields[idx].field.name = name;
 		cache->field_file_map[idx] = (uint32_t)-1;
 
-		switch (cache->fields[idx].field.type) {
-		case MAIL_CACHE_FIELD_FIXED_SIZE:
-		case MAIL_CACHE_FIELD_BITMASK:
-			break;
-		case MAIL_CACHE_FIELD_VARIABLE_SIZE:
-		case MAIL_CACHE_FIELD_STRING:
-		case MAIL_CACHE_FIELD_HEADER:
+		if (!field_has_fixed_size(cache->fields[idx].field.type))
 			cache->fields[idx].field.field_size = (unsigned int)-1;
-			break;
-		}
 
 		hash_insert(cache->field_name_hash, name, POINTER_CAST(idx));
 	}
@@ -242,19 +271,9 @@
 				cache->fields[field.idx].field.decision =
 					decisions[i];
 			}
-			if (cache->fields[field.idx].field.type != types[i]) {
-				mail_cache_set_corrupted(cache,
-					"registered field %s type changed",
-					names);
-				return -1;
-			}
-			if (cache->fields[field.idx].field.field_size !=
-			    sizes[i]) {
-				mail_cache_set_corrupted(cache,
-					"registered field %s size changed",
-					names);
+			if (field_type_verify(cache, field.idx,
+					      types[i], sizes[i]) < 0)
 				return -1;
-			}
 		} else {
 			field.name = names;
 			field.type = types[i];



More information about the dovecot-cvs mailing list