dovecot: idxview rewrite. It now uses lib-index functions to rea...

dovecot at dovecot.org dovecot at dovecot.org
Sun Nov 4 14:48:20 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/294af3a8d974
changeset: 6687:294af3a8d974
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Nov 04 14:48:16 2007 +0200
description:
idxview rewrite. It now uses lib-index functions to read the files.

diffstat:

2 files changed, 247 insertions(+), 362 deletions(-)
src/util/Makefile.am |    1 
src/util/idxview.c   |  608 ++++++++++++++++++++------------------------------

diffs (truncated from 731 to 300 lines):

diff -r 610f3d9813b5 -r 294af3a8d974 src/util/Makefile.am
--- a/src/util/Makefile.am	Sun Nov 04 14:47:01 2007 +0200
+++ b/src/util/Makefile.am	Sun Nov 04 14:48:16 2007 +0200
@@ -22,6 +22,7 @@ gdbhelper_SOURCES = \
 	gdbhelper.c
 
 idxview_LDADD = \
+	../lib-index/libindex.a \
 	../lib/liblib.a
 
 idxview_SOURCES = \
diff -r 610f3d9813b5 -r 294af3a8d974 src/util/idxview.c
--- a/src/util/idxview.c	Sun Nov 04 14:47:01 2007 +0200
+++ b/src/util/idxview.c	Sun Nov 04 14:48:16 2007 +0200
@@ -4,128 +4,98 @@
 #include "array.h"
 #include "str.h"
 #include "hex-binary.h"
+#include "file-lock.h"
 #include "mail-index-private.h"
 #include "mail-cache-private.h"
-#include "mail-transaction-log.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 
-static struct mail_index_header hdr;
-static ARRAY_DEFINE(extensions, struct mail_index_ext);
-static struct mail_cache_header cache_hdr;
-static ARRAY_DEFINE(cache_fields, struct mail_cache_field);
-static unsigned int cache_ext = (unsigned int)-1;
-static unsigned int cache_search_offset = 0;
-static int cache_fd = -1;
-
-uint32_t mail_index_offset_to_uint32(uint32_t offset)
-{
-	const unsigned char *buf = (const unsigned char *) &offset;
-
-	if ((offset & 0x80808080) != 0x80808080)
-		return 0;
-
-	return (((uint32_t)buf[3] & 0x7f) << 2) |
-		(((uint32_t)buf[2] & 0x7f) << 9) |
-		(((uint32_t)buf[1] & 0x7f) << 16) |
-		(((uint32_t)buf[0] & 0x7f) << 23);
-}
-
-static size_t get_align(size_t name_len)
-{
-	size_t size = sizeof(struct mail_index_ext_header) + name_len;
-	return MAIL_INDEX_HEADER_SIZE_ALIGN(size) - size;
-}
-
-static void dump_hdr(int fd)
-{
-	const struct mail_index_ext_header *ext_hdr;
-	struct mail_index_ext ext;
-	char *base;
-	ssize_t ret;
-	unsigned int i, offset, name_offset;
-
-	ret = read(fd, &hdr, sizeof(hdr));
-	if (ret != sizeof(hdr)) {
-		i_fatal("file hdr read() %"PRIuSIZE_T" != %"PRIuSIZE_T,
-			ret, sizeof(hdr));
-	}
-
-	printf("version = %u.%u\n", hdr.major_version, hdr.minor_version);
-	printf("base header size = %u\n", hdr.base_header_size);
-	printf("header size = %u\n", hdr.header_size);
-	printf("record size = %u\n", hdr.record_size);
-	printf("compat flags = %u\n", hdr.compat_flags);
-	printf("index id = %u\n", hdr.indexid);
-	printf("flags = %u\n", hdr.flags);
-	printf("uid validity = %u\n", hdr.uid_validity);
-	printf("next uid = %u\n", hdr.next_uid);
-	printf("messages count = %u\n", hdr.messages_count);
-	printf("seen messages count = %u\n", hdr.seen_messages_count);
-	printf("deleted messages count = %u\n", hdr.deleted_messages_count);
-	printf("first recent uid = %u\n", hdr.first_recent_uid);
-	printf("first unseen uid lowwater = %u\n", hdr.first_unseen_uid_lowwater);
-	printf("first deleted uid lowwater = %u\n", hdr.first_deleted_uid_lowwater);
-	printf("log file seq = %u\n", hdr.log_file_seq);
-	if (hdr.minor_version == 0) {
-		printf("log file int offset = %u\n", hdr.log_file_tail_offset);
-		printf("log file ext offset = %u\n", hdr.log_file_head_offset);
+static const char *unixdate2str(time_t time)
+{
+	static char buf[64];
+	struct tm *tm;
+
+	tm = localtime(&time);
+	strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", tm);
+	return buf;
+}
+
+static void dump_hdr(struct mail_index *index)
+{
+	const struct mail_index_header *hdr = &index->map->hdr;
+	unsigned int i;
+
+	printf("version .................. = %u.%u\n", hdr->major_version, hdr->minor_version);
+	printf("base header size ......... = %u\n", hdr->base_header_size);
+	printf("header size .............. = %u\n", hdr->header_size);
+	printf("record size .............. = %u\n", hdr->record_size);
+	printf("compat flags ............. = %u\n", hdr->compat_flags);
+	printf("index id ................. = %u (%s)\n", hdr->indexid, unixdate2str(hdr->indexid));
+	printf("flags .................... = %u\n", hdr->flags);
+	printf("uid validity ............. = %u (%s)\n", hdr->uid_validity, unixdate2str(hdr->uid_validity));
+	printf("next uid ................. = %u\n", hdr->next_uid);
+	printf("messages count ........... = %u\n", hdr->messages_count);
+	printf("seen messages count ...... = %u\n", hdr->seen_messages_count);
+	printf("deleted messages count ... = %u\n", hdr->deleted_messages_count);
+	printf("first recent uid ......... = %u\n", hdr->first_recent_uid);
+	printf("first unseen uid lowwater  = %u\n", hdr->first_unseen_uid_lowwater);
+	printf("first deleted uid lowwater = %u\n", hdr->first_deleted_uid_lowwater);
+	printf("log file seq ............. = %u\n", hdr->log_file_seq);
+	if (hdr->minor_version == 0) {
+		printf("log file int offset ...... = %u\n", hdr->log_file_tail_offset);
+		printf("log file ext offset ...... = %u\n", hdr->log_file_head_offset);
 	} else {
-		printf("log file tail offset = %u\n", hdr.log_file_tail_offset);
-		printf("log file head offset = %u\n", hdr.log_file_head_offset);
-	}
-	printf("sync size = %llu\n", (unsigned long long)hdr.sync_size);
-	printf("sync stamp = %u\n", hdr.sync_stamp);
-	printf("day stamp = %u\n", hdr.day_stamp);
-	for (i = 0; i < 8; i++)
-		printf("day first uid[%u] = %u\n", i, hdr.day_first_uid[i]);
-
-	i_array_init(&extensions, 16);
-	offset = MAIL_INDEX_HEADER_SIZE_ALIGN(hdr.base_header_size);
-	if (offset >= hdr.header_size) {
+		printf("log file tail offset ..... = %u\n", hdr->log_file_tail_offset);
+		printf("log file head offset ..... = %u\n", hdr->log_file_head_offset);
+	}
+	printf("sync size ................ = %llu\n", (unsigned long long)hdr->sync_size);
+	printf("sync stamp ............... = %u (%s)\n", hdr->sync_stamp, unixdate2str(hdr->sync_stamp));
+	printf("day stamp ................ = %u (%s)\n", hdr->day_stamp, unixdate2str(hdr->day_stamp));
+	for (i = 0; i < N_ELEMENTS(hdr->day_first_uid); i++)
+		printf("day first uid[%u] ......... = %u\n", i, hdr->day_first_uid[i]);
+}
+
+static void dump_extensions(struct mail_index *index)
+{
+	const struct mail_index_ext *extensions;
+	unsigned int i, count;
+
+	extensions = array_get(&index->map->extensions, &count);
+	if (count == 0) {
 		printf("no extensions\n");
 		return;
 	}
 
-	base = i_malloc(hdr.header_size);
-	ret = pread(fd, base, hdr.header_size, 0);
-	if (ret != (ssize_t)hdr.header_size) {
-		i_fatal("file hdr read() %"PRIuSIZE_T" != %u",
-			ret, hdr.header_size);
-	}
-
-	memset(&ext, 0, sizeof(ext)); i = 0;
-	while (offset < hdr.header_size) {
-		ext_hdr = CONST_PTR_OFFSET(base, offset);
-
-		offset += sizeof(*ext_hdr);
-		name_offset = offset;
-		offset += ext_hdr->name_size + get_align(ext_hdr->name_size);
-
-		ext.name = i_strndup(CONST_PTR_OFFSET(base, name_offset),
-				     ext_hdr->name_size);
-		ext.record_offset = ext_hdr->record_offset;
-		ext.record_size = ext_hdr->record_size;
-		ext.record_align = ext_hdr->record_align;
-
-		if (strcmp(ext.name, "cache") == 0)
-                        cache_ext = i;
+	for (i = 0; i < count; i++) {
+		const struct mail_index_ext *ext = &extensions[i];
 
 		printf("-- Extension %u --\n", i);
-		printf("name: %s\n", ext.name);
-		printf("hdr_size: %u\n", ext_hdr->hdr_size);
-		printf("reset_id: %u\n", ext_hdr->reset_id);
-		printf("record_offset: %u\n", ext_hdr->record_offset);
-		printf("record_size: %u\n", ext_hdr->record_size);
-		printf("record_align: %u\n", ext_hdr->record_align);
-		printf("name_size: %u\n", ext_hdr->name_size);
-
-		offset += MAIL_INDEX_HEADER_SIZE_ALIGN(ext_hdr->hdr_size);
-		array_append(&extensions, &ext, 1);
-		i++;
-	}
+		printf("name ........ = %s\n", ext->name);
+		printf("hdr_size .... = %u\n", ext->hdr_size);
+		printf("reset_id .... = %u\n", ext->reset_id);
+		printf("record_offset = %u\n", ext->record_offset);
+		printf("record_size . = %u\n", ext->record_size);
+		printf("record_align  = %u\n", ext->record_align);
+	}
+}
+
+static void dump_keywords(struct mail_index *index)
+{
+	const unsigned int *kw_indexes;
+	const char *const *keywords;
+	unsigned int i, count;
+
+	printf("-- Keywords --\n");
+
+	kw_indexes = array_get(&index->map->keyword_idx_map, &count);
+	if (count == 0)
+		return;
+
+	keywords = array_idx(&index->keywords, 0);
+	for (i = 0; i < count; i++)
+		printf("%3u = %s\n", i, keywords[kw_indexes[i]]);
 }
 
 static const char *cache_decision2str(enum mail_cache_decision_type type)
@@ -137,7 +107,7 @@ static const char *cache_decision2str(en
 		str = "no";
 		break;
 	case MAIL_CACHE_DECISION_TEMP:
-		str = "temp";
+		str = "tmp";
 		break;
 	case MAIL_CACHE_DECISION_YES:
 		str = "yes";
@@ -147,7 +117,7 @@ static const char *cache_decision2str(en
 	}
 
 	if ((type & MAIL_CACHE_DECISION_FORCED) != 0)
-		str = t_strconcat(str, " (forced)", NULL);
+		str = t_strconcat(str, "!", NULL);
 	return str;
 }
 
@@ -158,199 +128,107 @@ static const char *cache_type2str(enum m
 {
 	switch (type) {
 	case MAIL_CACHE_FIELD_FIXED_SIZE:
-		return "fixed";
+		return "fix";
 	case MAIL_CACHE_FIELD_VARIABLE_SIZE:
-		return "variable";
+		return "var";
 	case MAIL_CACHE_FIELD_STRING:
-		return "string";
+		return "str";
 	case MAIL_CACHE_FIELD_BITMASK:
-		return "bitmask";
+		return "bit";
 	case MAIL_CACHE_FIELD_HEADER:
-		return "header";
+		return "hdr";
 	default:
 		return t_strdup_printf("0x%x", type);
 	}
 }
 
-static const char *unixdate2str(time_t time)
-{
-	static char buf[64];
-	struct tm *tm;
-
-	tm = localtime(&time);
-	strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", tm);
-	return buf;
-}
-
-static void dump_cache_hdr(int fd)
-{
-        struct mail_cache_header_fields fields;
-	struct mail_cache_field field;
-	uint32_t field_offset, next_offset;
-	char *buf;
-	ssize_t ret;
-	const uint32_t *last_used, *size;
-	const uint8_t *type, *decision;
-	const char *names;
-	unsigned int i;
-
-	ret = read(fd, &cache_hdr, sizeof(cache_hdr));
-	if (ret != sizeof(cache_hdr)) {
-		i_fatal("cache file hdr read() %"PRIuSIZE_T" != %"PRIuSIZE_T,
-			ret, sizeof(cache_hdr));
-	}
-
-	field_offset =
-		mail_index_offset_to_uint32(cache_hdr.field_header_offset);
-
-	printf("Cache header:\n");
-	printf("version: %u\n", cache_hdr.version);
-	printf("indexid: %u\n", cache_hdr.indexid);
-	printf("file_seq: %u\n", cache_hdr.file_seq);
-	printf("continued_record_count: %u\n", cache_hdr.continued_record_count);
-	printf("hole_offset: %u\n", cache_hdr.hole_offset);
-	printf("used_file_size: %u\n", cache_hdr.used_file_size);


More information about the dovecot-cvs mailing list