changeset 13287:957060ca5b69

Moved GUID code to liblib. Use guid_128_t type consistently everywhere.
author Timo Sirainen <tss@iki.fi>
date Thu, 25 Aug 2011 01:16:11 +0300
parents b6b16c9eb3d5
children eaee3b8a98cf
files src/doveadm/doveadm-dump-index.c src/doveadm/doveadm-mail-fetch.c src/doveadm/doveadm-mail-mailbox-status.c src/doveadm/doveadm-mail-search.c src/dsync/dsync-brain-msgs.c src/dsync/dsync-data.c src/dsync/dsync-data.h src/dsync/dsync-worker-local.c src/dsync/test-dsync-brain-msgs.c src/dsync/test-dsync-common.c src/dsync/test-dsync-common.h src/dsync/test-dsync-proxy-server-cmd.c src/dsync/test-dsync-proxy.c src/imap/imap-status.c src/lib-index/mail-index-transaction-update.c src/lib-index/mail-index.h src/lib-index/mail-transaction-log.h src/lib-index/mailbox-log.h src/lib-index/test-mail-index-transaction-finish.c src/lib-index/test-mail-index-transaction-update.c src/lib-lda/mail-deliver.c src/lib-lda/mail-deliver.h src/lib-mail/mail-types.h src/lib-storage/index/dbox-common/dbox-file-fix.c src/lib-storage/index/dbox-common/dbox-save.c src/lib-storage/index/dbox-common/dbox-save.h src/lib-storage/index/dbox-multi/mdbox-save.c src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c src/lib-storage/index/dbox-multi/mdbox-storage.c src/lib-storage/index/dbox-multi/mdbox-storage.h src/lib-storage/index/dbox-multi/mdbox-sync.c src/lib-storage/index/dbox-single/sdbox-copy.c src/lib-storage/index/dbox-single/sdbox-file.c src/lib-storage/index/dbox-single/sdbox-save.c src/lib-storage/index/dbox-single/sdbox-storage.c src/lib-storage/index/dbox-single/sdbox-storage.h src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c src/lib-storage/index/index-attachment.c src/lib-storage/index/index-mail.c src/lib-storage/index/index-search.c src/lib-storage/index/index-storage.c src/lib-storage/index/index-sync-changes.c src/lib-storage/index/index-sync-changes.h src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/index/maildir/maildir-sync-index.c src/lib-storage/index/maildir/maildir-uidlist.c src/lib-storage/index/maildir/maildir-uidlist.h src/lib-storage/index/mbox/mbox-storage.c src/lib-storage/index/mbox/mbox-storage.h src/lib-storage/index/mbox/mbox-sync.c src/lib-storage/list/index-mailbox-list-status.c src/lib-storage/list/index-mailbox-list.h src/lib-storage/list/mailbox-list-fs.c src/lib-storage/mail-storage.c src/lib-storage/mail-storage.h src/lib-storage/mail.c src/lib-storage/mailbox-guid-cache.c src/lib-storage/mailbox-guid-cache.h src/lib-storage/mailbox-list-private.h src/lib-storage/mailbox-list.c src/lib-storage/mailbox-list.h src/lib-storage/test-mailbox-get.c src/lib/Makefile.am src/lib/guid.c src/lib/guid.h src/lmtp/client.c src/plugins/fts-lucene/doveadm-fts-lucene.c src/plugins/fts-lucene/fts-backend-lucene.c src/plugins/fts-lucene/lucene-wrapper.cc src/plugins/fts-lucene/lucene-wrapper.h src/plugins/fts/doveadm-dump-fts-expunge-log.c src/plugins/fts/fts-api-private.h src/plugins/fts/fts-api.c src/plugins/fts/fts-expunge-log.c src/plugins/fts/fts-expunge-log.h
diffstat 75 files changed, 366 insertions(+), 414 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/doveadm-dump-index.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/doveadm/doveadm-dump-index.c	Thu Aug 25 01:16:11 2011 +0300
@@ -34,11 +34,11 @@
 };
 struct sdbox_index_header {
 	uint32_t rebuild_count;
-	uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
+	guid_128_t mailbox_guid;
 };
 struct mdbox_index_header {
 	uint32_t map_uid_validity;
-	uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
+	guid_128_t mailbox_guid;
 };
 struct mdbox_mail_index_record {
 	uint32_t map_uid;
@@ -145,24 +145,21 @@
 		       (unsigned long long)hdr->sync_size);
 		printf(" - dirty_flag . = %d\n", hdr->dirty_flag);
 		printf(" - mailbox_guid = %s\n",
-		       binary_to_hex(hdr->mailbox_guid,
-				     sizeof(hdr->mailbox_guid)));
+		       guid_128_to_string(hdr->mailbox_guid));
 	} else if (strcmp(ext->name, "mdbox-hdr") == 0) {
 		const struct mdbox_index_header *hdr = data;
 
 		printf("header\n");
 		printf(" - map_uid_validity .. = %u\n", hdr->map_uid_validity);
 		printf(" - mailbox_guid ...... = %s\n",
-		       binary_to_hex(hdr->mailbox_guid,
-				     sizeof(hdr->mailbox_guid)));
+		       guid_128_to_string(hdr->mailbox_guid));
 	} else if (strcmp(ext->name, "dbox-hdr") == 0) {
 		const struct sdbox_index_header *hdr = data;
 
 		printf("header\n");
 		printf(" - rebuild_count . = %u\n", hdr->rebuild_count);
 		printf(" - mailbox_guid .. = %s\n",
-		       binary_to_hex(hdr->mailbox_guid,
-				     sizeof(hdr->mailbox_guid)));
+		       guid_128_to_string(hdr->mailbox_guid));
 	} else if (strcmp(ext->name, "modseq") == 0) {
 		const struct mail_index_modseq_header *hdr = data;
 
--- a/src/doveadm/doveadm-mail-fetch.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/doveadm/doveadm-mail-fetch.c	Thu Aug 25 01:16:11 2011 +0300
@@ -61,7 +61,7 @@
 	if (mailbox_get_metadata(ctx->mail->box, MAILBOX_METADATA_GUID,
 				 &metadata) < 0)
 		return -1;
-	doveadm_print(mail_guid_128_to_string(metadata.guid));
+	doveadm_print(guid_128_to_string(metadata.guid));
 	return 0;
 }
 
--- a/src/doveadm/doveadm-mail-mailbox-status.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/doveadm/doveadm-mail-mailbox-status.c	Thu Aug 25 01:16:11 2011 +0300
@@ -97,7 +97,7 @@
 	if ((ctx->metadata_items & MAILBOX_METADATA_VIRTUAL_SIZE) != 0)
 		doveadm_print_num(metadata->virtual_size);
 	if ((ctx->metadata_items & MAILBOX_METADATA_GUID) != 0)
-		doveadm_print(mail_guid_128_to_string(metadata->guid));
+		doveadm_print(guid_128_to_string(metadata->guid));
 }
 
 static void
--- a/src/doveadm/doveadm-mail-search.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/doveadm/doveadm-mail-search.c	Thu Aug 25 01:16:11 2011 +0300
@@ -28,7 +28,7 @@
 				 MAILBOX_METADATA_GUID, &metadata) < 0)
 		ret = -1;
 	else {
-		guid_str = mail_guid_128_to_string(metadata.guid);
+		guid_str = guid_128_to_string(metadata.guid);
 		while (doveadm_mail_iter_next(iter, &mail)) {
 			doveadm_print(guid_str);
 			T_BEGIN {
--- a/src/dsync/dsync-brain-msgs.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/dsync/dsync-brain-msgs.c	Thu Aug 25 01:16:11 2011 +0300
@@ -239,7 +239,7 @@
 	struct dsync_message *src_msg = &sync->src_msg_iter->msg;
 	struct dsync_message *dest_msg = &sync->dest_msg_iter->msg;
 	const char *src_guid, *dest_guid;
-	unsigned char guid_128_data[MAIL_GUID_128_SIZE * 2 + 1];
+	unsigned char guid_128_data[GUID_128_SIZE * 2 + 1];
 	bool src_expunged, dest_expunged;
 
 	i_assert(sync->src_msg_iter->mailbox_idx ==
--- a/src/dsync/dsync-data.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/dsync/dsync-data.c	Thu Aug 25 01:16:11 2011 +0300
@@ -116,19 +116,19 @@
 
 const char *dsync_guid_to_str(const mailbox_guid_t *guid)
 {
-	return mail_guid_128_to_string(guid->guid);
+	return guid_128_to_string(guid->guid);
 }
 
 const char *dsync_get_guid_128_str(const char *guid, unsigned char *dest,
 				   unsigned int dest_len)
 {
-	uint8_t guid_128[MAIL_GUID_128_SIZE];
+	guid_128_t guid_128;
 	buffer_t guid_128_buf;
 
-	i_assert(dest_len >= MAIL_GUID_128_SIZE * 2 + 1);
+	i_assert(dest_len >= GUID_128_SIZE * 2 + 1);
 	buffer_create_data(&guid_128_buf, dest, dest_len);
 	mail_generate_guid_128_hash(guid, guid_128);
-	if (mail_guid_128_is_empty(guid_128))
+	if (guid_128_is_empty(guid_128))
 		return "";
 	binary_to_hex_append(&guid_128_buf, guid_128, sizeof(guid_128));
 	buffer_append_c(&guid_128_buf, '\0');
--- a/src/dsync/dsync-data.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/dsync/dsync-data.h	Thu Aug 25 01:16:11 2011 +0300
@@ -4,7 +4,7 @@
 #include "mail-storage.h"
 
 typedef struct {
-	uint8_t guid[MAIL_GUID_128_SIZE];
+	guid_128_t guid;
 } mailbox_guid_t;
 ARRAY_DEFINE_TYPE(mailbox_guid, mailbox_guid_t);
 
--- a/src/dsync/dsync-worker-local.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/dsync/dsync-worker-local.c	Thu Aug 25 01:16:11 2011 +0300
@@ -375,7 +375,7 @@
 
 static int mailbox_log_record_cmp(const void *p1, const void *p2)
 {
-	return memcmp(p1, p2, MAIL_GUID_128_SIZE);
+	return memcmp(p1, p2, GUID_128_SIZE);
 }
 
 static unsigned int dir_change_hash(const void *p)
@@ -394,7 +394,7 @@
 		return 1;
 
 	return memcmp(c1->name_sha1.guid, c2->name_sha1.guid,
-		      MAIL_GUID_128_SIZE);
+		      GUID_128_SIZE);
 }
 
 static int dsync_worker_get_mailbox_log(struct local_dsync_worker *worker)
@@ -788,7 +788,7 @@
 	if (memcmp(metadata.guid, guid->guid, sizeof(guid->guid)) != 0) {
 		i_error("Mailbox %s changed its GUID (%s -> %s)",
 			lbox->name, dsync_guid_to_str(guid),
-			mail_guid_128_to_string(metadata.guid));
+			guid_128_to_string(metadata.guid));
 		mailbox_free(&box);
 		return -1;
 	}
@@ -867,7 +867,7 @@
 		       sizeof(iter->mailboxes[i].guid));
 	}
 	i_array_init(&iter->expunges, 32);
-	iter->tmp_guid_str = str_new(default_pool, MAIL_GUID_128_SIZE * 2 + 1);
+	iter->tmp_guid_str = str_new(default_pool, GUID_128_SIZE * 2 + 1);
 	(void)iter_local_mailbox_open(iter);
 	return &iter->iter;
 }
@@ -901,9 +901,9 @@
 		memset(msg_r, 0, sizeof(*msg_r));
 		str_truncate(iter->tmp_guid_str, 0);
 		guid_128 = expunges[iter->expunge_idx].guid_128;
-		if (!mail_guid_128_is_empty(guid_128)) {
+		if (!guid_128_is_empty(guid_128)) {
 			binary_to_hex_append(iter->tmp_guid_str, guid_128,
-					     MAIL_GUID_128_SIZE);
+					     GUID_128_SIZE);
 		}
 		msg_r->guid = str_c(iter->tmp_guid_str);
 		msg_r->uid = expunges[iter->expunge_idx].uid;
@@ -1090,10 +1090,10 @@
 		if (!mailbox_list_is_valid_create_name(ns->list, name)) {
 			/* name is too long? just give up and generate a
 			   unique name */
-			uint8_t guid[MAIL_GUID_128_SIZE];
+			guid_128_t guid;
 
-			mail_generate_guid_128(guid);
-			name = mail_guid_128_to_string(guid);
+			guid_128_generate(guid);
+			name = guid_128_to_string(guid);
 		}
 		i_assert(mailbox_list_is_valid_create_name(ns->list, name));
 	}
--- a/src/dsync/test-dsync-brain-msgs.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/dsync/test-dsync-brain-msgs.c	Thu Aug 25 01:16:11 2011 +0300
@@ -163,7 +163,7 @@
 			       enum test_box_add_type type,
 			       uint32_t uid, enum mail_flags flags)
 {
-	unsigned char guid_128_data[MAIL_GUID_128_SIZE * 2 + 1];
+	unsigned char guid_128_data[GUID_128_SIZE * 2 + 1];
 	struct dsync_message *msgs;
 	unsigned int i, count;
 
--- a/src/dsync/test-dsync-common.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/dsync/test-dsync-common.c	Thu Aug 25 01:16:11 2011 +0300
@@ -7,12 +7,12 @@
 #include "dsync-data.h"
 #include "test-dsync-common.h"
 
-const uint8_t test_mailbox_guid1[MAIL_GUID_128_SIZE] = {
+const guid_128_t test_mailbox_guid1 = {
 	0x12, 0x34, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
 	0x21, 0x43, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe
 };
 
-const uint8_t test_mailbox_guid2[MAIL_GUID_128_SIZE] = {
+const guid_128_t test_mailbox_guid2 = {
 	0xa3, 0xbd, 0x78, 0x24, 0xde, 0xfe, 0x08, 0xf7,
 	0xac, 0xc7, 0xca, 0x8c, 0xe7, 0x39, 0xdb, 0xca
 };
@@ -69,23 +69,10 @@
 	return TRUE;
 }
 
-void mail_generate_guid_128_hash(const char *guid,
-				 uint8_t guid_128[MAIL_GUID_128_SIZE])
+void mail_generate_guid_128_hash(const char *guid, guid_128_t guid_128_r)
 {
 	unsigned char sha1_sum[SHA1_RESULTLEN];
 
 	sha1_get_digest(guid, strlen(guid), sha1_sum);
-	memcpy(guid_128, sha1_sum, MAIL_GUID_128_SIZE);
+	memcpy(guid_128_r, sha1_sum, GUID_128_SIZE);
 }
-
-bool mail_guid_128_is_empty(const uint8_t guid_128[MAIL_GUID_128_SIZE])
-{
-	static uint8_t empty_guid[MAIL_GUID_128_SIZE] = { 0, };
-
-	return memcmp(empty_guid, guid_128, sizeof(empty_guid)) == 0;
-}
-
-const char *mail_guid_128_to_string(const uint8_t guid_128[MAIL_GUID_128_SIZE])
-{
-	return binary_to_hex(guid_128, MAIL_GUID_128_SIZE);
-}
--- a/src/dsync/test-dsync-common.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/dsync/test-dsync-common.h	Thu Aug 25 01:16:11 2011 +0300
@@ -7,8 +7,8 @@
 #define TEST_MAILBOX_GUID1 "1234456789abcdef2143547698badcfe"
 #define TEST_MAILBOX_GUID2 "a3bd7824defe08f7acc7ca8ce739dbca"
 
-extern const uint8_t test_mailbox_guid1[MAIL_GUID_128_SIZE];
-extern const uint8_t test_mailbox_guid2[MAIL_GUID_128_SIZE];
+extern const guid_128_t test_mailbox_guid1;
+extern const guid_128_t test_mailbox_guid2;
 
 bool dsync_messages_equal(const struct dsync_message *m1,
 			  const struct dsync_message *m2);
--- a/src/dsync/test-dsync-proxy-server-cmd.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/dsync/test-dsync-proxy-server-cmd.c	Thu Aug 25 01:16:11 2011 +0300
@@ -87,7 +87,7 @@
 	memset(&box, 0, sizeof(box));
 	box.name = "foo/bar";
 	box.name_sep = '/';
-	memcpy(box.mailbox_guid.guid, test_mailbox_guid1, MAIL_GUID_128_SIZE);
+	memcpy(box.mailbox_guid.guid, test_mailbox_guid1, GUID_128_SIZE);
 	box.uid_validity = 4275878552;
 	box.uid_next = 4023233417;
 	box.message_count = 4525;
@@ -238,7 +238,7 @@
 	test_assert(event.type == LAST_BOX_TYPE_CREATE);
 	test_assert(strcmp(event.box.name, "selectable") == 0);
 	test_assert(event.box.name_sep == '?');
-	test_assert(memcmp(event.box.mailbox_guid.guid, test_mailbox_guid2, MAIL_GUID_128_SIZE) == 0);
+	test_assert(memcmp(event.box.mailbox_guid.guid, test_mailbox_guid2, GUID_128_SIZE) == 0);
 	test_assert(event.box.flags == 2);
 	test_assert(event.box.uid_validity == 1234567890);
 	test_assert(event.box.uid_next == 9876);
@@ -259,13 +259,13 @@
 	test_assert(run_cmd("BOX-DELETE", TEST_MAILBOX_GUID1, "4351", NULL) == 1);
 	test_assert(test_dsync_worker_next_box_event(test_worker, &event));
 	test_assert(event.type == LAST_BOX_TYPE_DELETE);
-	test_assert(memcmp(event.box.mailbox_guid.guid, test_mailbox_guid1, MAIL_GUID_128_SIZE) == 0);
+	test_assert(memcmp(event.box.mailbox_guid.guid, test_mailbox_guid1, GUID_128_SIZE) == 0);
 	test_assert(event.box.last_change == 4351);
 
 	test_assert(run_cmd("BOX-DELETE", TEST_MAILBOX_GUID2, "653", NULL) == 1);
 	test_assert(test_dsync_worker_next_box_event(test_worker, &event));
 	test_assert(event.type == LAST_BOX_TYPE_DELETE);
-	test_assert(memcmp(event.box.mailbox_guid.guid, test_mailbox_guid2, MAIL_GUID_128_SIZE) == 0);
+	test_assert(memcmp(event.box.mailbox_guid.guid, test_mailbox_guid2, GUID_128_SIZE) == 0);
 	test_assert(event.box.last_change == 653);
 
 	test_end();
@@ -280,14 +280,14 @@
 	test_assert(run_cmd("BOX-RENAME", TEST_MAILBOX_GUID1, "name\t1", "/", NULL) == 1);
 	test_assert(test_dsync_worker_next_box_event(test_worker, &event));
 	test_assert(event.type == LAST_BOX_TYPE_RENAME);
-	test_assert(memcmp(event.box.mailbox_guid.guid, test_mailbox_guid1, MAIL_GUID_128_SIZE) == 0);
+	test_assert(memcmp(event.box.mailbox_guid.guid, test_mailbox_guid1, GUID_128_SIZE) == 0);
 	test_assert(strcmp(event.box.name, "name\t1") == 0);
 	test_assert(event.box.name_sep == '/');
 
 	test_assert(run_cmd("BOX-RENAME", TEST_MAILBOX_GUID2, "", "?", NULL) == 1);
 	test_assert(test_dsync_worker_next_box_event(test_worker, &event));
 	test_assert(event.type == LAST_BOX_TYPE_RENAME);
-	test_assert(memcmp(event.box.mailbox_guid.guid, test_mailbox_guid2, MAIL_GUID_128_SIZE) == 0);
+	test_assert(memcmp(event.box.mailbox_guid.guid, test_mailbox_guid2, GUID_128_SIZE) == 0);
 	test_assert(strcmp(event.box.name, "") == 0);
 	test_assert(event.box.name_sep == '?');
 
@@ -307,7 +307,7 @@
 	test_assert(event.type == LAST_BOX_TYPE_UPDATE);
 	test_assert(strcmp(event.box.name, "updated") == 0);
 	test_assert(event.box.name_sep == '/');
-	test_assert(memcmp(event.box.mailbox_guid.guid, test_mailbox_guid1, MAIL_GUID_128_SIZE) == 0);
+	test_assert(memcmp(event.box.mailbox_guid.guid, test_mailbox_guid1, GUID_128_SIZE) == 0);
 	test_assert(event.box.flags == DSYNC_MAILBOX_FLAG_DELETED_MAILBOX);
 	test_assert(event.box.uid_validity == 34343);
 	test_assert(event.box.uid_next == 22);
@@ -324,10 +324,10 @@
 	test_begin("proxy server box select");
 
 	test_assert(run_cmd("BOX-SELECT", TEST_MAILBOX_GUID1, NULL) == 1);
-	test_assert(memcmp(test_worker->selected_mailbox.guid, test_mailbox_guid1, MAIL_GUID_128_SIZE) == 0);
+	test_assert(memcmp(test_worker->selected_mailbox.guid, test_mailbox_guid1, GUID_128_SIZE) == 0);
 
 	test_assert(run_cmd("BOX-SELECT", TEST_MAILBOX_GUID2, NULL) == 1);
-	test_assert(memcmp(test_worker->selected_mailbox.guid, test_mailbox_guid2, MAIL_GUID_128_SIZE) == 0);
+	test_assert(memcmp(test_worker->selected_mailbox.guid, test_mailbox_guid2, GUID_128_SIZE) == 0);
 
 	test_end();
 }
@@ -392,7 +392,7 @@
 			    "8294284", NULL) == 1);
 	test_assert(test_dsync_worker_next_msg_event(test_worker, &msg_event));
 	test_assert(msg_event.type == LAST_MSG_TYPE_COPY);
-	test_assert(memcmp(msg_event.copy_src_mailbox.guid, test_mailbox_guid1, MAIL_GUID_128_SIZE) == 0);
+	test_assert(memcmp(msg_event.copy_src_mailbox.guid, test_mailbox_guid1, GUID_128_SIZE) == 0);
 	test_assert(msg_event.copy_src_uid == 5454);
 	test_assert(strcmp(msg_event.msg.guid, "copyguid") == 0);
 	test_assert(msg_event.msg.uid == 5678);
--- a/src/dsync/test-dsync-proxy.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/dsync/test-dsync-proxy.c	Thu Aug 25 01:16:11 2011 +0300
@@ -111,7 +111,7 @@
 
 	/* real mailbox */
 	i_assert(sizeof(box_in.mailbox_guid.guid) == sizeof(test_mailbox_guid1));
-	memcpy(box_in.mailbox_guid.guid, test_mailbox_guid2, MAIL_GUID_128_SIZE);
+	memcpy(box_in.mailbox_guid.guid, test_mailbox_guid2, GUID_128_SIZE);
 	box_in.flags = 24242 & ~DSYNC_MAILBOX_FLAG_NOSELECT;
 	box_in.uid_validity = 0xf74d921b;
 	box_in.uid_next = 73529472;
--- a/src/imap/imap-status.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/imap/imap-status.c	Thu Aug 25 01:16:11 2011 +0300
@@ -132,7 +132,7 @@
 	}
 	if ((items->metadata & MAILBOX_METADATA_GUID) != 0) {
 		str_printfa(str, "X-GUID %s ",
-			    mail_guid_128_to_string(result->metadata.guid));
+			    guid_128_to_string(result->metadata.guid));
 	}
 
 	if (str_len(str) != prefix_len)
--- a/src/lib-index/mail-index-transaction-update.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-index/mail-index-transaction-update.c	Thu Aug 25 01:16:11 2011 +0300
@@ -336,13 +336,13 @@
 
 void mail_index_expunge(struct mail_index_transaction *t, uint32_t seq)
 {
-	static uint8_t null_guid[MAIL_GUID_128_SIZE] =
+	static guid_128_t null_guid =
 		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 	mail_index_expunge_guid(t, seq, null_guid);
 }
 
 void mail_index_expunge_guid(struct mail_index_transaction *t, uint32_t seq,
-			     const uint8_t guid_128[MAIL_GUID_128_SIZE])
+			     const guid_128_t guid_128)
 {
 	const struct mail_transaction_expunge_guid *expunges;
 	struct mail_transaction_expunge_guid *expunge;
--- a/src/lib-index/mail-index.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-index/mail-index.h	Thu Aug 25 01:16:11 2011 +0300
@@ -3,6 +3,7 @@
 
 #include "file-lock.h"
 #include "fsync-mode.h"
+#include "guid.h"
 #include "mail-types.h"
 #include "seq-range-array.h"
 
@@ -169,7 +170,7 @@
 	unsigned int keyword_idx;
 
 	/* MAIL_INDEX_SYNC_TYPE_EXPUNGE: */
-	uint8_t guid_128[MAIL_GUID_128_SIZE];
+	guid_128_t guid_128;
 };
 
 enum mail_index_view_sync_type {
@@ -430,7 +431,7 @@
 void mail_index_expunge(struct mail_index_transaction *t, uint32_t seq);
 /* Like mail_index_expunge(), but also write message GUID to transaction log. */
 void mail_index_expunge_guid(struct mail_index_transaction *t, uint32_t seq,
-			     const uint8_t guid_128[MAIL_GUID_128_SIZE]);
+			     const guid_128_t guid_128);
 /* Update flags in index. */
 void mail_index_update_flags(struct mail_index_transaction *t, uint32_t seq,
 			     enum modify_type modify_type,
--- a/src/lib-index/mail-transaction-log.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-index/mail-transaction-log.h	Thu Aug 25 01:16:11 2011 +0300
@@ -80,7 +80,7 @@
 };
 struct mail_transaction_expunge_guid {
 	uint32_t uid;
-	uint8_t guid_128[MAIL_GUID_128_SIZE];
+	guid_128_t guid_128;
 };
 
 struct mail_transaction_flag_update {
--- a/src/lib-index/mailbox-log.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-index/mailbox-log.h	Thu Aug 25 01:16:11 2011 +0300
@@ -1,7 +1,7 @@
 #ifndef MAILBOX_LOG_H
 #define MAILBOX_LOG_H
 
-#include "mail-types.h"
+#include "guid.h"
 
 enum mailbox_log_record_type {
 	MAILBOX_LOG_RECORD_DELETE_MAILBOX = 1,
@@ -14,7 +14,7 @@
 struct mailbox_log_record {
 	uint8_t type;
 	uint8_t padding[3];
-	uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
+	guid_128_t mailbox_guid;
 	uint8_t timestamp[4];
 };
 
--- a/src/lib-index/test-mail-index-transaction-finish.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-index/test-mail-index-transaction-finish.c	Thu Aug 25 01:16:11 2011 +0300
@@ -202,9 +202,7 @@
 static void test_mail_index_transaction_finish_expunges(void)
 {
 	struct mail_index_transaction *t;
-	uint8_t guid1[MAIL_GUID_128_SIZE];
-	uint8_t guid2[MAIL_GUID_128_SIZE];
-	uint8_t guid3[MAIL_GUID_128_SIZE];
+	guid_128_t guid1, guid2, guid3;
 	const struct mail_transaction_expunge_guid *expunges;
 	struct mail_transaction_expunge_guid expunge;
 	unsigned int i, count;
--- a/src/lib-index/test-mail-index-transaction-update.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-index/test-mail-index-transaction-update.c	Thu Aug 25 01:16:11 2011 +0300
@@ -500,12 +500,10 @@
 
 static void test_mail_index_expunge(void)
 {
-	static uint8_t empty_guid[MAIL_GUID_128_SIZE] = { 0, };
+	static guid_128_t empty_guid = { 0, };
 	struct mail_index_transaction *t;
 	const struct mail_transaction_expunge_guid *expunges;
-	uint8_t guid2[MAIL_GUID_128_SIZE];
-	uint8_t guid3[MAIL_GUID_128_SIZE];
-	uint8_t guid4[MAIL_GUID_128_SIZE];
+	guid_128_t guid2, guid3, guid4;
 	unsigned int i, count;
 
 	test_begin("mail index expunge");
--- a/src/lib-lda/mail-deliver.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-lda/mail-deliver.c	Thu Aug 25 01:16:11 2011 +0300
@@ -211,7 +211,7 @@
 					 struct mailbox *box)
 {
 	struct mailbox_metadata metadata;
-	const mail_guid_128_t *guid;
+	const guid_128_t *guid;
 
 	if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID, &metadata) < 0) {
 		/* just play it safe and assume a duplicate */
@@ -223,7 +223,7 @@
 	if (!array_is_created(&session->inbox_guids))
 		p_array_init(&session->inbox_guids, session->pool, 8);
 	array_foreach(&session->inbox_guids, guid) {
-		if (memcmp(metadata.guid, guid, sizeof(metadata.guid)) == 0)
+		if (memcmp(metadata.guid, *guid, sizeof(metadata.guid)) == 0)
 			return TRUE;
 	}
 	array_append(&session->inbox_guids, &metadata.guid, 1);
@@ -236,7 +236,7 @@
 	struct mailbox_transaction_context *trans =
 		mailbox_save_get_transaction(save_ctx);
 	struct mailbox *box = mailbox_transaction_get_mailbox(trans);
-	uint8_t guid[MAIL_GUID_128_SIZE];
+	guid_128_t guid;
 
 	if (strcmp(mailbox_get_name(box), "INBOX") != 0)
 		return;
@@ -246,8 +246,8 @@
 	   session. the problem with this is that if GUIDs are used as POP3
 	   UIDLs, some clients can't handle the duplicates well. */
 	if (mail_deliver_check_duplicate(session, box)) {
-		mail_generate_guid_128(guid);
-		mailbox_save_set_guid(save_ctx, mail_guid_128_to_string(guid));
+		guid_128_generate(guid);
+		mailbox_save_set_guid(save_ctx, guid_128_to_string(guid));
 	}
 }
 
--- a/src/lib-lda/mail-deliver.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-lda/mail-deliver.h	Thu Aug 25 01:16:11 2011 +0300
@@ -1,7 +1,7 @@
 #ifndef MAIL_DELIVER_H
 #define MAIL_DELIVER_H
 
-#include "mail-types.h"
+#include "guid.h"
 
 enum mail_flags;
 enum mail_error;
@@ -13,7 +13,7 @@
 	pool_t pool;
 
 	/* List of INBOX GUIDs where this mail has already been saved to */
-	ARRAY_DEFINE(inbox_guids, mail_guid_128_t);
+	ARRAY_DEFINE(inbox_guids, guid_128_t);
 };
 
 struct mail_deliver_context {
--- a/src/lib-mail/mail-types.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-mail/mail-types.h	Thu Aug 25 01:16:11 2011 +0300
@@ -1,9 +1,6 @@
 #ifndef MAIL_TYPES_H
 #define MAIL_TYPES_H
 
-#define MAIL_GUID_128_SIZE 16
-typedef uint8_t mail_guid_128_t[MAIL_GUID_128_SIZE];
-
 enum mail_flags {
 	MAIL_ANSWERED	= 0x01,
 	MAIL_FLAGGED	= 0x02,
--- a/src/lib-storage/index/dbox-common/dbox-file-fix.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-file-fix.c	Thu Aug 25 01:16:11 2011 +0300
@@ -4,7 +4,6 @@
 #include "istream.h"
 #include "ostream.h"
 #include "str-find.h"
-#include "hex-binary.h"
 #include "message-size.h"
 #include "dbox-storage.h"
 #include "dbox-file.h"
@@ -166,7 +165,7 @@
 	bool pre, write_header, have_guid;
 	struct message_size body;
 	struct istream *body_input;
-	uint8_t guid_128[MAIL_GUID_128_SIZE];
+	guid_128_t guid_128;
 	int ret;
 
 	i_stream_seek(file->input, 0);
@@ -269,10 +268,10 @@
 		else
 			dbox_file_copy_metadata(file, output, &have_guid);
 		if (!have_guid) {
-			mail_generate_guid_128(guid_128);
+			guid_128_generate(guid_128);
 			o_stream_send_str(output,
 				t_strdup_printf("%c%s\n", DBOX_METADATA_GUID,
-				binary_to_hex(guid_128, sizeof(guid_128))));
+				guid_128_to_string(guid_128)));
 		}
 		o_stream_send_str(output,
 			t_strdup_printf("%c%llx\n", DBOX_METADATA_VIRTUAL_SIZE,
--- a/src/lib-storage/index/dbox-common/dbox-save.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-save.c	Thu Aug 25 01:16:11 2011 +0300
@@ -117,7 +117,7 @@
 void dbox_save_write_metadata(struct mail_save_context *_ctx,
 			      struct ostream *output, uoff_t output_msg_size,
 			      const char *orig_mailbox_name,
-			      uint8_t guid_128[MAIL_GUID_128_SIZE])
+			      guid_128_t guid_128)
 {
 	struct dbox_save_context *ctx = (struct dbox_save_context *)_ctx;
 	struct dbox_metadata_header metadata_hdr;
@@ -155,8 +155,8 @@
 	if (guid != NULL)
 		mail_generate_guid_128_hash(guid, guid_128);
 	else {
-		mail_generate_guid_128(guid_128);
-		guid = binary_to_hex(guid_128, MAIL_GUID_128_SIZE);
+		guid_128_generate(guid_128);
+		guid = guid_128_to_string(guid_128);
 	}
 	str_printfa(str, "%c%s\n", DBOX_METADATA_GUID, guid);
 
--- a/src/lib-storage/index/dbox-common/dbox-save.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-save.h	Thu Aug 25 01:16:11 2011 +0300
@@ -26,7 +26,7 @@
 void dbox_save_write_metadata(struct mail_save_context *ctx,
 			      struct ostream *output, uoff_t output_msg_size,
 			      const char *orig_mailbox_name,
-			      uint8_t guid_128_r[MAIL_GUID_128_SIZE]);
+			      guid_128_t guid_128_r);
 
 void dbox_save_add_to_index(struct dbox_save_context *ctx);
 
--- a/src/lib-storage/index/dbox-multi/mdbox-save.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-save.c	Thu Aug 25 01:16:11 2011 +0300
@@ -166,7 +166,7 @@
 	struct dbox_file *file = mail->file_append->file;
 	struct dbox_message_header dbox_msg_hdr;
 	uoff_t message_size;
-	uint8_t guid_128[MAIL_GUID_128_SIZE];
+	guid_128_t guid_128;
 
 	i_assert(file->msg_header_size == sizeof(dbox_msg_hdr));
 
--- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Thu Aug 25 01:16:11 2011 +0300
@@ -21,7 +21,7 @@
 #include <unistd.h>
 
 struct mdbox_rebuild_msg {
-	uint8_t guid_128[MAIL_GUID_128_SIZE];
+	guid_128_t guid_128;
 	uint32_t file_id;
 	uint32_t offset;
 	uint32_t size;
@@ -58,26 +58,6 @@
 	struct rebuild_msg_mailbox prev_msg;
 };
 
-static unsigned int guid_hash(const void *p)
-{
-        const uint8_t *s = p;
-	unsigned int i, g, h = 0;
-
-	for (i = 0; i < MAIL_GUID_128_SIZE; i++) {
-		h = (h << 4) + s[i];
-		if ((g = h & 0xf0000000UL)) {
-			h = h ^ (g >> 24);
-			h = h ^ g;
-		}
-	}
-	return h;
-}
-
-static int guid_cmp(const void *p1, const void *p2)
-{
-	return memcmp(p1, p2, MAIL_GUID_128_SIZE);
-}
-
 static struct mdbox_storage_rebuild_context *
 mdbox_storage_rebuild_init(struct mdbox_storage *storage,
 			   struct mdbox_map_atomic_context *atomic)
@@ -91,7 +71,7 @@
 	ctx->atomic = atomic;
 	ctx->pool = pool_alloconly_create("dbox map rebuild", 1024*256);
 	ctx->guid_hash = hash_table_create(default_pool, ctx->pool, 0,
-					   guid_hash, guid_cmp);
+					   guid_128_hash, guid_128_cmp);
 	i_array_init(&ctx->msgs, 512);
 	i_array_init(&ctx->seen_file_ids, 128);
 
@@ -198,7 +178,7 @@
 		rec->offset = offset;
 		rec->size = file->input->v_offset - offset;
 		mail_generate_guid_128_hash(guid, rec->guid_128);
-		i_assert(!mail_guid_128_is_empty(rec->guid_128));
+		i_assert(!guid_128_is_empty(rec->guid_128));
 		array_append(&ctx->msgs, &rec, 1);
 
 		if (hash_table_lookup(ctx->guid_hash, rec->guid_128) != NULL) {
@@ -468,12 +448,12 @@
 	}
 
 	/* make sure we have valid mailbox guid */
-	if (mail_guid_128_is_empty(hdr.mailbox_guid)) {
-		if (!mail_guid_128_is_empty(backup_hdr.mailbox_guid)) {
+	if (guid_128_is_empty(hdr.mailbox_guid)) {
+		if (!guid_128_is_empty(backup_hdr.mailbox_guid)) {
 			memcpy(hdr.mailbox_guid, backup_hdr.mailbox_guid,
 			       sizeof(hdr.mailbox_guid));
 		} else {
-			mail_generate_guid_128(hdr.mailbox_guid);
+			guid_128_generate(hdr.mailbox_guid);
 		}
 	}
 
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c	Thu Aug 25 01:16:11 2011 +0300
@@ -127,7 +127,7 @@
 					sizeof(struct mdbox_index_header), 0, 0);
 	mbox->guid_ext_id =
 		mail_index_ext_register(mbox->box.index, "guid",
-					0, MAIL_GUID_128_SIZE, 1);
+					0, GUID_128_SIZE, 1);
 	return 0;
 }
 
@@ -173,11 +173,11 @@
 
 	new_hdr = hdr;
 
-	if (update != NULL && !mail_guid_128_is_empty(update->mailbox_guid)) {
+	if (update != NULL && !guid_128_is_empty(update->mailbox_guid)) {
 		memcpy(new_hdr.mailbox_guid, update->mailbox_guid,
 		       sizeof(new_hdr.mailbox_guid));
-	} else if (mail_guid_128_is_empty(new_hdr.mailbox_guid)) {
-		mail_generate_guid_128(new_hdr.mailbox_guid);
+	} else if (guid_128_is_empty(new_hdr.mailbox_guid)) {
+		guid_128_generate(new_hdr.mailbox_guid);
 	}
 
 	new_hdr.map_uid_validity =
@@ -306,21 +306,20 @@
 }
 
 static int
-mdbox_mailbox_get_guid(struct mdbox_mailbox *mbox,
-		       uint8_t guid[MAIL_GUID_128_SIZE])
+mdbox_mailbox_get_guid(struct mdbox_mailbox *mbox, guid_128_t guid_r)
 {
 	struct mdbox_index_header hdr;
 
 	if (mdbox_read_header(mbox, &hdr) < 0)
 		memset(&hdr, 0, sizeof(hdr));
 
-	if (mail_guid_128_is_empty(hdr.mailbox_guid)) {
+	if (guid_128_is_empty(hdr.mailbox_guid)) {
 		/* regenerate it */
 		if (mdbox_write_index_header(&mbox->box, NULL, NULL) < 0 ||
 		    mdbox_read_header(mbox, &hdr) < 0)
 			return -1;
 	}
-	memcpy(guid, hdr.mailbox_guid, MAIL_GUID_128_SIZE);
+	memcpy(guid_r, hdr.mailbox_guid, GUID_128_SIZE);
 	return 0;
 }
 
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage.h	Thu Aug 25 01:16:11 2011 +0300
@@ -16,7 +16,7 @@
 #define MDBOX_INDEX_HEADER_MIN_SIZE (sizeof(uint32_t))
 struct mdbox_index_header {
 	uint32_t map_uid_validity;
-	uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
+	guid_128_t mailbox_guid;
 };
 
 struct mdbox_storage {
--- a/src/lib-storage/index/dbox-multi/mdbox-sync.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-sync.c	Thu Aug 25 01:16:11 2011 +0300
@@ -15,7 +15,6 @@
 #include "lib.h"
 #include "array.h"
 #include "ioloop.h"
-#include "hex-binary.h"
 #include "str.h"
 #include "mdbox-storage.h"
 #include "mdbox-storage-rebuild.h"
@@ -27,7 +26,7 @@
 
 static int
 dbox_sync_verify_expunge_guid(struct mdbox_sync_context *ctx, uint32_t seq,
-			      const uint8_t guid_128[MAIL_GUID_128_SIZE])
+			      const guid_128_t guid_128)
 {
 	const void *data;
 	uint32_t uid;
@@ -35,21 +34,20 @@
 	mail_index_lookup_uid(ctx->sync_view, seq, &uid);
 	mail_index_lookup_ext(ctx->sync_view, seq,
 			      ctx->mbox->guid_ext_id, &data, NULL);
-	if (mail_guid_128_is_empty(guid_128) ||
-	    memcmp(data, guid_128, MAIL_GUID_128_SIZE) == 0)
+	if (guid_128_is_empty(guid_128) ||
+	    memcmp(data, guid_128, GUID_128_SIZE) == 0)
 		return 0;
 
 	mail_storage_set_critical(&ctx->mbox->storage->storage.storage,
 		"Mailbox %s: Expunged GUID mismatch for UID %u: %s vs %s",
 		ctx->mbox->box.vname, uid,
-		binary_to_hex(data, MAIL_GUID_128_SIZE),
-		binary_to_hex(guid_128, MAIL_GUID_128_SIZE));
+		guid_128_to_string(data), guid_128_to_string(guid_128));
 	mdbox_storage_set_corrupted(ctx->mbox->storage);
 	return -1;
 }
 
 static int mdbox_sync_expunge(struct mdbox_sync_context *ctx, uint32_t seq,
-			      const uint8_t guid_128[MAIL_GUID_128_SIZE])
+			      const guid_128_t guid_128)
 {
 	uint32_t map_uid;
 
--- a/src/lib-storage/index/dbox-single/sdbox-copy.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-copy.c	Thu Aug 25 01:16:11 2011 +0300
@@ -58,7 +58,7 @@
 			sdbox_file_attachment_relpath(src_file, extref->path));
 		dest_relpath = p_strconcat(dest_file->attachment_pool,
 					   extref->path, "-",
-					   mail_generate_guid_string(), NULL);
+					   guid_generate(), NULL);
 		dest = t_strdup_printf("%s/%s", dest_storage->attachment_dir,
 				       dest_relpath);
 		if (fs_link(dest_storage->attachment_fs, src, dest) < 0) {
--- a/src/lib-storage/index/dbox-single/sdbox-file.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-file.c	Thu Aug 25 01:16:11 2011 +0300
@@ -119,7 +119,7 @@
 	}
 	return t_strdup_printf("%s-%s-%u",
 			p == NULL ? srcpath : t_strdup_until(srcpath, p),
-			mail_guid_128_to_string(file->mbox->mailbox_guid),
+			guid_128_to_string(file->mbox->mailbox_guid),
 			file->uid);
 }
 
--- a/src/lib-storage/index/dbox-single/sdbox-save.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-save.c	Thu Aug 25 01:16:11 2011 +0300
@@ -116,7 +116,7 @@
 	const struct mail_attachment_extref *extrefs;
 	struct dbox_message_header dbox_msg_hdr;
 	uoff_t message_size;
-	uint8_t guid_128[MAIL_GUID_128_SIZE];
+	guid_128_t guid_128;
 	unsigned int i, count;
 
 	i_assert(file->msg_header_size == sizeof(dbox_msg_hdr));
--- a/src/lib-storage/index/dbox-single/sdbox-storage.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-storage.c	Thu Aug 25 01:16:11 2011 +0300
@@ -98,11 +98,11 @@
 
 	new_hdr = hdr;
 
-	if (update != NULL && !mail_guid_128_is_empty(update->mailbox_guid)) {
+	if (update != NULL && !guid_128_is_empty(update->mailbox_guid)) {
 		memcpy(new_hdr.mailbox_guid, update->mailbox_guid,
 		       sizeof(new_hdr.mailbox_guid));
-	} else if (mail_guid_128_is_empty(new_hdr.mailbox_guid)) {
-		mail_generate_guid_128(new_hdr.mailbox_guid);
+	} else if (guid_128_is_empty(new_hdr.mailbox_guid)) {
+		guid_128_generate(new_hdr.mailbox_guid);
 	}
 
 	if (memcmp(&hdr, &new_hdr, sizeof(hdr)) != 0) {
@@ -185,7 +185,7 @@
 	struct sdbox_file *file = (struct sdbox_file *)_file;
 
 	return t_strdup_printf("-%s-%u",
-			mail_guid_128_to_string(file->mbox->mailbox_guid),
+			guid_128_to_string(file->mbox->mailbox_guid),
 			file->uid);
 }
 
@@ -245,7 +245,7 @@
 			memset(&hdr, 0, sizeof(hdr));
 	}
 
-	if (mail_guid_128_is_empty(hdr.mailbox_guid)) {
+	if (guid_128_is_empty(hdr.mailbox_guid)) {
 		/* regenerate it */
 		if (sdbox_mailbox_create_indexes(box, NULL, NULL) < 0 ||
 		    sdbox_read_header(mbox, &hdr, TRUE) < 0)
@@ -274,7 +274,7 @@
 
 	if ((items & MAILBOX_METADATA_GUID) != 0) {
 		memcpy(metadata_r->guid, mbox->mailbox_guid,
-		       MAIL_GUID_128_SIZE);
+		       sizeof(metadata_r->guid));
 	}
 	return index_mailbox_get_metadata(box, items, metadata_r);
 }
--- a/src/lib-storage/index/dbox-single/sdbox-storage.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-storage.h	Thu Aug 25 01:16:11 2011 +0300
@@ -12,7 +12,7 @@
 struct sdbox_index_header {
 	/* increased every time a full mailbox rebuild is done */
 	uint32_t rebuild_count;
-	uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
+	guid_128_t mailbox_guid;
 };
 
 struct sdbox_storage {
@@ -28,7 +28,7 @@
 	   has changed from this value) */
 	uint32_t corrupted_rebuild_count;
 
-	uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
+	guid_128_t mailbox_guid;
 };
 
 extern struct mail_vfuncs sdbox_mail_vfuncs;
--- a/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c	Thu Aug 25 01:16:11 2011 +0300
@@ -135,8 +135,8 @@
 
 	if (sdbox_read_header(mbox, &hdr, FALSE) < 0)
 		memset(&hdr, 0, sizeof(hdr));
-	if (mail_guid_128_is_empty(hdr.mailbox_guid))
-		mail_generate_guid_128(hdr.mailbox_guid);
+	if (guid_128_is_empty(hdr.mailbox_guid))
+		guid_128_generate(hdr.mailbox_guid);
 	if (++hdr.rebuild_count == 0)
 		hdr.rebuild_count = 1;
 	mail_index_update_header_ext(ctx->trans, mbox->hdr_ext_id, 0,
--- a/src/lib-storage/index/index-attachment.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/index-attachment.c	Thu Aug 25 01:16:11 2011 +0300
@@ -350,7 +350,7 @@
 	struct fs_file *file;
 	struct istream *input;
 	struct ostream *output;
-	uint8_t guid_128[MAIL_GUID_128_SIZE];
+	guid_128_t guid_128;
 	const char *attachment_dir, *path, *digest;
 	string_t *digest_str;
 	const unsigned char *data;
@@ -393,12 +393,12 @@
 		digest = t_strconcat(digest, "\0\0\0\0", NULL);
 	}
 
-	mail_generate_guid_128(guid_128);
+	guid_128_generate(guid_128);
 	attachment_dir = index_attachment_dir_get(storage);
 	path = t_strdup_printf("%s/%c%c/%c%c/%s-%s", attachment_dir,
 			       digest[0], digest[1],
 			       digest[2], digest[3], digest,
-			       mail_guid_128_to_string(guid_128));
+			       guid_128_to_string(guid_128));
 	if (fs_open(ctx->attach->fs, path,
 		    FS_OPEN_MODE_CREATE | flags, &file) < 0) {
 		mail_storage_set_critical(storage, "%s",
--- a/src/lib-storage/index/index-mail.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/index-mail.c	Thu Aug 25 01:16:11 2011 +0300
@@ -1546,7 +1546,7 @@
 void index_mail_expunge(struct mail *mail)
 {
 	const char *value;
-	uint8_t guid_128[MAIL_GUID_128_SIZE];
+	guid_128_t guid_128;
 
 	if (mail_get_special(mail, MAIL_FETCH_GUID, &value) < 0)
 		mail_index_expunge(mail->transaction->itrans, mail->seq);
--- a/src/lib-storage/index/index-search.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/index-search.c	Thu Aug 25 01:16:11 2011 +0300
@@ -88,7 +88,7 @@
 			break;
 		}
 
-		match = strcmp(mail_guid_128_to_string(metadata.guid),
+		match = strcmp(guid_128_to_string(metadata.guid),
 			       arg->value.str) == 0;
 		if (match != arg->match_not)
 			arg->match_always = TRUE;
--- a/src/lib-storage/index/index-storage.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/index-storage.c	Thu Aug 25 01:16:11 2011 +0300
@@ -469,7 +469,7 @@
 
 int index_storage_mailbox_delete_dir(struct mailbox *box, bool mailbox_deleted)
 {
-	uint8_t dir_sha128[MAIL_GUID_128_SIZE];
+	guid_128_t dir_sha128;
 	enum mail_error error;
 
 	if (mailbox_list_delete_dir(box->list, box->name) == 0)
@@ -578,7 +578,7 @@
 int index_storage_mailbox_rename(struct mailbox *src, struct mailbox *dest,
 				 bool rename_children)
 {
-	uint8_t guid[MAIL_GUID_128_SIZE];
+	guid_128_t guid;
 
 	if (src->list->v.rename_mailbox(src->list, src->name,
 					dest->list, dest->name,
--- a/src/lib-storage/index/index-sync-changes.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/index-sync-changes.c	Thu Aug 25 01:16:11 2011 +0300
@@ -71,7 +71,7 @@
 static bool
 index_sync_changes_have_expunges(struct index_sync_changes_context *ctx,
 				 unsigned int count,
-				 uint8_t expunged_guid_128[MAIL_GUID_128_SIZE])
+				 guid_128_t expunged_guid_128_r)
 {
 	const struct mail_index_sync_rec *syncs;
 	unsigned int i;
@@ -79,8 +79,8 @@
 	syncs = array_idx(&ctx->syncs, 0);
 	for (i = 0; i < count; i++) {
 		if (syncs[i].type == MAIL_INDEX_SYNC_TYPE_EXPUNGE) {
-			memcpy(expunged_guid_128, syncs[i].guid_128,
-			       MAIL_GUID_128_SIZE);
+			memcpy(expunged_guid_128_r, syncs[i].guid_128,
+			       GUID_128_SIZE);
 			return TRUE;
 		}
 	}
@@ -89,7 +89,7 @@
 
 void index_sync_changes_read(struct index_sync_changes_context *ctx,
 			     uint32_t uid, bool *sync_expunge_r,
-			     uint8_t expunged_guid_128[MAIL_GUID_128_SIZE])
+			     guid_128_t expunged_guid_128_r)
 {
 	struct mail_index_sync_rec *sync_rec = &ctx->sync_rec;
 	uint32_t seq1, seq2;
@@ -107,8 +107,8 @@
 
 			if (sync_rec->type == MAIL_INDEX_SYNC_TYPE_EXPUNGE) {
 				*sync_expunge_r = TRUE;
-				memcpy(expunged_guid_128, sync_rec->guid_128,
-				       MAIL_GUID_128_SIZE);
+				memcpy(expunged_guid_128_r, sync_rec->guid_128,
+				       GUID_128_SIZE);
 			}
 		}
 
@@ -151,7 +151,7 @@
 	if (!*sync_expunge_r && orig_count > 0) {
 		*sync_expunge_r =
 			index_sync_changes_have_expunges(ctx, orig_count,
-							 expunged_guid_128);
+							 expunged_guid_128_r);
 	}
 }
 
--- a/src/lib-storage/index/index-sync-changes.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/index-sync-changes.h	Thu Aug 25 01:16:11 2011 +0300
@@ -14,7 +14,7 @@
 
 void index_sync_changes_read(struct index_sync_changes_context *ctx,
 			     uint32_t uid, bool *sync_expunge_r,
-			     uint8_t expunged_guid_128[MAIL_GUID_128_SIZE]);
+			     guid_128_t expunged_guid_128);
 bool index_sync_changes_have(struct index_sync_changes_context *ctx);
 uint32_t
 index_sync_changes_get_next_uid(struct index_sync_changes_context *ctx);
--- a/src/lib-storage/index/maildir/maildir-storage.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Thu Aug 25 01:16:11 2011 +0300
@@ -421,7 +421,7 @@
 	if (maildir_uidlist_lock(uidlist) <= 0)
 		return -1;
 
-	if (!mail_guid_128_is_empty(update->mailbox_guid))
+	if (!guid_128_is_empty(update->mailbox_guid))
 		maildir_uidlist_set_mailbox_guid(uidlist, update->mailbox_guid);
 	if (update->uid_validity != 0)
 		maildir_uidlist_set_uid_validity(uidlist, update->uid_validity);
--- a/src/lib-storage/index/maildir/maildir-sync-index.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync-index.c	Thu Aug 25 01:16:11 2011 +0300
@@ -3,7 +3,6 @@
 #include "lib.h"
 #include "ioloop.h"
 #include "array.h"
-#include "hex-binary.h"
 #include "maildir-storage.h"
 #include "index-sync-changes.h"
 #include "maildir-uidlist.h"
@@ -51,12 +50,12 @@
 static bool
 maildir_expunge_is_valid_guid(struct maildir_index_sync_context *ctx,
 			      uint32_t uid, const char *filename,
-			      uint8_t expunged_guid_128[MAIL_GUID_128_SIZE])
+			      guid_128_t expunged_guid_128)
 {
-	uint8_t guid_128[MAIL_GUID_128_SIZE];
+	guid_128_t guid_128;
 	const char *guid;
 
-	if (mail_guid_128_is_empty(expunged_guid_128)) {
+	if (guid_128_is_empty(expunged_guid_128)) {
 		/* no GUID associated with expunge */
 		return TRUE;
 	}
@@ -75,8 +74,8 @@
 	mail_storage_set_critical(&ctx->mbox->storage->storage,
 		"Mailbox %s: Expunged GUID mismatch for UID %u: %s vs %s",
 		ctx->mbox->box.vname, ctx->uid,
-		binary_to_hex(guid_128, sizeof(guid_128)),
-		binary_to_hex(expunged_guid_128, MAIL_GUID_128_SIZE));
+		guid_128_to_string(guid_128),
+		guid_128_to_string(expunged_guid_128));
 	return FALSE;
 }
 
@@ -466,7 +465,7 @@
 	unsigned int changes = 0;
 	int ret = 0;
 	time_t time_before_sync;
-	uint8_t expunged_guid_128[MAIL_GUID_128_SIZE];
+	guid_128_t expunged_guid_128;
 	enum mail_flags private_flags_mask;
 	bool expunged, full_rescan = FALSE;
 
--- a/src/lib-storage/index/maildir/maildir-uidlist.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c	Thu Aug 25 01:16:11 2011 +0300
@@ -30,7 +30,6 @@
 #include "istream.h"
 #include "ostream.h"
 #include "str.h"
-#include "hex-binary.h"
 #include "file-dotlock.h"
 #include "close-keep-errno.h"
 #include "nfs-workarounds.h"
@@ -88,7 +87,7 @@
 	uoff_t last_read_offset;
 	string_t *hdr_extensions;
 
-	uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
+	guid_128_t mailbox_guid;
 
 	unsigned int recreate:1;
 	unsigned int recreate_on_change:1;
@@ -579,7 +578,6 @@
 			       unsigned int *uid_validity_r,
 			       unsigned int *next_uid_r)
 {
-	buffer_t *buf;
 	char key;
 
 	str_truncate(uidlist->hdr_extensions, 0);
@@ -599,16 +597,12 @@
 			*next_uid_r = strtoul(value, NULL, 10);
 			break;
 		case MAILDIR_UIDLIST_HDR_EXT_GUID:
-			buf = buffer_create_dynamic(pool_datastack_create(),
-						    MAIL_GUID_128_SIZE);
-			if (hex_to_binary(value, buf) < 0 ||
-			    buf->used != MAIL_GUID_128_SIZE) {
+			if (guid_128_from_string(value,
+						 uidlist->mailbox_guid) < 0) {
 				maildir_uidlist_set_corrupted(uidlist,
 					"Invalid mailbox GUID: %s", value);
 				return -1;
 			}
-			memcpy(uidlist->mailbox_guid, buf->data,
-			       sizeof(uidlist->mailbox_guid));
 			uidlist->have_mailbox_guid = TRUE;
 			break;
 		default:
@@ -1079,7 +1073,7 @@
 }
 
 int maildir_uidlist_get_mailbox_guid(struct maildir_uidlist *uidlist,
-				     uint8_t mailbox_guid[MAIL_GUID_128_SIZE])
+				     guid_128_t mailbox_guid)
 {
 	if (!uidlist->initial_hdr_read) {
 		if (maildir_uidlist_refresh(uidlist) < 0)
@@ -1090,12 +1084,12 @@
 		if (maildir_uidlist_update(uidlist) < 0)
 			return -1;
 	}
-	memcpy(mailbox_guid, uidlist->mailbox_guid, MAIL_GUID_128_SIZE);
+	memcpy(mailbox_guid, uidlist->mailbox_guid, GUID_128_SIZE);
 	return 0;
 }
 
 void maildir_uidlist_set_mailbox_guid(struct maildir_uidlist *uidlist,
-				      const uint8_t mailbox_guid[MAIL_GUID_128_SIZE])
+				      const guid_128_t mailbox_guid)
 {
 	if (memcmp(uidlist->mailbox_guid, mailbox_guid,
 		   sizeof(uidlist->mailbox_guid)) != 0) {
@@ -1236,7 +1230,7 @@
 		if (uidlist->uid_validity == 0)
 			maildir_uidlist_generate_uid_validity(uidlist);
 		if (!uidlist->have_mailbox_guid)
-			mail_generate_guid_128(uidlist->mailbox_guid);
+			guid_128_generate(uidlist->mailbox_guid);
 
 		i_assert(uidlist->next_uid > 0);
 		str_printfa(str, "%u %c%u %c%u %c%s", uidlist->version,
@@ -1245,8 +1239,7 @@
 			    MAILDIR_UIDLIST_HDR_EXT_NEXT_UID,
 			    uidlist->next_uid,
 			    MAILDIR_UIDLIST_HDR_EXT_GUID,
-			    binary_to_hex(uidlist->mailbox_guid,
-					  sizeof(uidlist->mailbox_guid)));
+			    guid_128_to_string(uidlist->mailbox_guid));
 		if (str_len(uidlist->hdr_extensions) > 0) {
 			str_append_c(str, ' ');
 			str_append_str(str, uidlist->hdr_extensions);
--- a/src/lib-storage/index/maildir/maildir-uidlist.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/maildir/maildir-uidlist.h	Thu Aug 25 01:16:11 2011 +0300
@@ -90,9 +90,9 @@
 uint32_t maildir_uidlist_get_uid_validity(struct maildir_uidlist *uidlist);
 uint32_t maildir_uidlist_get_next_uid(struct maildir_uidlist *uidlist);
 int maildir_uidlist_get_mailbox_guid(struct maildir_uidlist *uidlist,
-				     uint8_t mailbox_guid[MAIL_GUID_128_SIZE]);
+				     guid_128_t mailbox_guid);
 void maildir_uidlist_set_mailbox_guid(struct maildir_uidlist *uidlist,
-				      const uint8_t mailbox_guid[MAIL_GUID_128_SIZE]);
+				      const guid_128_t mailbox_guid);
 
 void maildir_uidlist_set_uid_validity(struct maildir_uidlist *uidlist,
 				      uint32_t uid_validity);
--- a/src/lib-storage/index/mbox/mbox-storage.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Thu Aug 25 01:16:11 2011 +0300
@@ -588,19 +588,18 @@
 }
 
 static int
-mbox_mailbox_get_guid(struct mbox_mailbox *mbox,
-		      uint8_t guid[MAIL_GUID_128_SIZE])
+mbox_mailbox_get_guid(struct mbox_mailbox *mbox, guid_128_t guid_r)
 {
 	if (mail_index_is_in_memory(mbox->box.index)) {
 		mail_storage_set_error(mbox->box.storage, MAIL_ERROR_NOTPOSSIBLE,
 			"Mailbox GUIDs are not permanent without index files");
 		return -1;
 	}
-	if (mail_guid_128_is_empty(mbox->mbox_hdr.mailbox_guid)) {
+	if (guid_128_is_empty(mbox->mbox_hdr.mailbox_guid)) {
 		if (mbox_sync_get_guid(mbox) < 0)
 			return -1;
 	}
-	memcpy(guid, mbox->mbox_hdr.mailbox_guid, MAIL_GUID_128_SIZE);
+	memcpy(guid_r, mbox->mbox_hdr.mailbox_guid, GUID_128_SIZE);
 	return 0;
 }
 
--- a/src/lib-storage/index/mbox/mbox-storage.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.h	Thu Aug 25 01:16:11 2011 +0300
@@ -19,7 +19,7 @@
 	uint32_t sync_mtime;
 	uint8_t dirty_flag;
 	uint8_t unused[3];
-	uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
+	guid_128_t mailbox_guid;
 };
 struct mbox_storage {
 	struct mail_storage storage;
--- a/src/lib-storage/index/mbox/mbox-sync.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Thu Aug 25 01:16:11 2011 +0300
@@ -172,7 +172,7 @@
 static void mbox_sync_read_index_syncs(struct mbox_sync_context *sync_ctx,
 				       uint32_t uid, bool *sync_expunge_r)
 {
-	uint8_t expunged_guid_128[MAIL_GUID_128_SIZE];
+	guid_128_t expunged_guid_128;
 
 	if (uid == 0 || sync_ctx->index_reset) {
 		/* nothing for this or the future ones */
@@ -1383,11 +1383,11 @@
 	const void *data;
 	size_t data_size;
 
-	if (update != NULL && !mail_guid_128_is_empty(update->mailbox_guid)) {
+	if (update != NULL && !guid_128_is_empty(update->mailbox_guid)) {
 		memcpy(mbox->mbox_hdr.mailbox_guid, update->mailbox_guid,
 		       sizeof(mbox->mbox_hdr.mailbox_guid));
-	} else if (mail_guid_128_is_empty(mbox->mbox_hdr.mailbox_guid)) {
-		mail_generate_guid_128(mbox->mbox_hdr.mailbox_guid);
+	} else if (guid_128_is_empty(mbox->mbox_hdr.mailbox_guid)) {
+		guid_128_generate(mbox->mbox_hdr.mailbox_guid);
 	}
 
 	mail_index_get_header_ext(mbox->box.view, mbox->mbox_ext_idx,
@@ -1711,7 +1711,7 @@
 	if (mbox_sync_header_refresh(mbox) < 0)
 		return -1;
 
-	if (mail_guid_128_is_empty(mbox->mbox_hdr.mailbox_guid)) {
+	if (guid_128_is_empty(mbox->mbox_hdr.mailbox_guid)) {
 		/* need to assign mailbox GUID */
 		return 1;
 	}
--- a/src/lib-storage/list/index-mailbox-list-status.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/list/index-mailbox-list-status.c	Thu Aug 25 01:16:11 2011 +0300
@@ -81,7 +81,7 @@
 			ret = FALSE;
 		else {
 			status_r->uidvalidity = rec->uid_validity;
-			memcpy(mailbox_guid, rec->guid, MAIL_GUID_128_SIZE);
+			memcpy(mailbox_guid, rec->guid, GUID_128_SIZE);
 		}
 	}
 
@@ -158,7 +158,7 @@
 	struct mail_index_transaction_commit_result result;
 	struct mailbox_metadata metadata;
 	struct mailbox_status old_status;
-	uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
+	guid_128_t mailbox_guid;
 	bool rec_changed, msgs_changed, hmodseq_changed;
 
 	if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID, &metadata) < 0)
--- a/src/lib-storage/list/index-mailbox-list.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/list/index-mailbox-list.h	Thu Aug 25 01:16:11 2011 +0300
@@ -33,7 +33,7 @@
 	/* the following fields are temporarily zero while unknown,
 	   also permanently zero for \NoSelect and \Nonexistent mailboxes: */
 
-	uint8_t guid[MAIL_GUID_128_SIZE];
+	guid_128_t guid;
 	uint32_t uid_validity;
 };
 
--- a/src/lib-storage/list/mailbox-list-fs.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/list/mailbox-list-fs.c	Thu Aug 25 01:16:11 2011 +0300
@@ -361,7 +361,7 @@
 static int fs_list_rmdir(struct mailbox_list *list, const char *name,
 			 const char *path)
 {
-	uint8_t dir_sha128[MAIL_GUID_128_SIZE];
+	guid_128_t dir_sha128;
 
 	if (rmdir(path) < 0)
 		return -1;
--- a/src/lib-storage/mail-storage.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/mail-storage.c	Thu Aug 25 01:16:11 2011 +0300
@@ -602,7 +602,7 @@
 }
 
 struct mailbox *mailbox_alloc_guid(struct mailbox_list *list,
-				   uint8_t guid[MAIL_GUID_128_SIZE],
+				   const guid_128_t guid,
 				   enum mailbox_flags flags)
 {
 	struct mailbox *box = NULL;
@@ -628,19 +628,19 @@
 		}
 		i_error("mailbox_alloc_guid(%s): "
 			"Couldn't verify mailbox GUID: %s",
-			mail_guid_128_to_string(guid),
+			guid_128_to_string(guid),
 			mailbox_get_last_error(box, NULL));
 		vname = NULL;
 		mailbox_free(&box);
 	} else {
 		vname = t_strdup_printf("(nonexistent mailbox with GUID=%s)",
-					mail_guid_128_to_string(guid));
+					guid_128_to_string(guid));
 		open_error = MAIL_ERROR_NOTFOUND;
 	}
 
 	if (vname == NULL) {
 		vname = t_strdup_printf("(error in mailbox with GUID=%s)",
-					mail_guid_128_to_string(guid));
+					guid_128_to_string(guid));
 	}
 	box = mailbox_alloc(list, vname, flags);
 	box->open_error = open_error;
@@ -1166,7 +1166,7 @@
 		return -1;
 
 	i_assert((items & MAILBOX_METADATA_GUID) == 0 ||
-		 !mail_guid_128_is_empty(metadata_r->guid));
+		 !guid_128_is_empty(metadata_r->guid));
 	return 0;
 }
 
--- a/src/lib-storage/mail-storage.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/mail-storage.h	Thu Aug 25 01:16:11 2011 +0300
@@ -5,6 +5,7 @@
 
 #include "seq-range-array.h"
 #include "file-lock.h"
+#include "guid.h"
 #include "mail-types.h"
 #include "mail-error.h"
 #include "mailbox-list.h"
@@ -221,7 +222,7 @@
 };
 
 struct mailbox_metadata {
-	uint8_t guid[MAIL_GUID_128_SIZE];
+	guid_128_t guid;
 	/* sum of virtual size of all messages in mailbox */
 	uint64_t virtual_size;
 	/* Fields that have "temp" or "yes" caching decision. */
@@ -230,7 +231,7 @@
 
 struct mailbox_update {
 	/* All non-zero fields are changed. */
-	uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
+	guid_128_t mailbox_guid;
 	uint32_t uid_validity;
 	uint32_t min_next_uid;
 	uint32_t min_first_recent_uid;
@@ -266,7 +267,7 @@
 	uint32_t uid;
 	/* 128 bit GUID. If the actual GUID has a different size, this
 	   contains last bits of its SHA1 sum. */
-	uint8_t guid_128[MAIL_GUID_128_SIZE];
+	guid_128_t guid_128;
 };
 ARRAY_DEFINE_TYPE(mailbox_expunge_rec, struct mailbox_expunge_rec);
 
@@ -370,7 +371,7 @@
 			      enum mailbox_flags flags);
 /* Like mailbox_alloc(), but use mailbox GUID. */
 struct mailbox *mailbox_alloc_guid(struct mailbox_list *list,
-				   uint8_t guid[MAIL_GUID_128_SIZE],
+				   const guid_128_t guid,
 				   enum mailbox_flags flags);
 /* Get mailbox existence state. If auto_boxes=FALSE, return
    MAILBOX_EXISTENCE_NONE for autocreated mailboxes that haven't been
@@ -745,22 +746,9 @@
 /* Mark a cached field corrupted and have it recalculated. */
 void mail_set_cache_corrupted(struct mail *mail, enum mail_fetch_field field);
 
-/* Generate a GUID (contains host name) */
-const char *mail_generate_guid_string(void);
-/* Generate 128 bit GUID */
-void mail_generate_guid_128(uint8_t guid[MAIL_GUID_128_SIZE]);
 /* Return 128 bit GUID using input string. If guid is already 128 bit hex
    encoded, it's returned as-is. Otherwise SHA1 sum is taken and its last
    128 bits are returned. */
-void mail_generate_guid_128_hash(const char *guid,
-				 uint8_t guid_128[MAIL_GUID_128_SIZE]);
-/* Returns TRUE if GUID is empty (not set / unknown). */
-bool mail_guid_128_is_empty(const uint8_t guid_128[MAIL_GUID_128_SIZE]);
-/* Returns GUID as a hex string. */
-const char *mail_guid_128_to_string(const uint8_t guid_128[MAIL_GUID_128_SIZE]);
-
-/* guid_128 hash/cmp functions for hash.h */
-unsigned int mail_guid_128_hash(const void *p);
-int mail_guid_128_cmp(const void *p1, const void *p2);
+void mail_generate_guid_128_hash(const char *guid, guid_128_t guid_128_r);
 
 #endif
--- a/src/lib-storage/mail.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/mail.c	Thu Aug 25 01:16:11 2011 +0300
@@ -275,117 +275,21 @@
 	p->v.set_cache_corrupted(mail, field);
 }
 
-const char *mail_generate_guid_string(void)
-{
-	static struct timespec ts = { 0, 0 };
-	static unsigned int pid = 0;
-
-	/* we'll use the current time in nanoseconds as the initial 64bit
-	   counter. */
-	if (ts.tv_sec == 0) {
-		if (clock_gettime(CLOCK_REALTIME, &ts) < 0)
-			i_fatal("clock_gettime() failed: %m");
-		pid = getpid();
-	} else if ((uint32_t)ts.tv_nsec < (uint32_t)-1) {
-		ts.tv_nsec++;
-	} else {
-		ts.tv_sec++;
-		ts.tv_nsec = 0;
-	}
-	return t_strdup_printf("%04x%04lx%04x%s",
-			       (unsigned int)ts.tv_nsec,
-			       (unsigned long)ts.tv_sec,
-			       pid, my_hostname);
-}
-
-void mail_generate_guid_128(uint8_t guid[MAIL_GUID_128_SIZE])
-{
-	static struct timespec ts = { 0, 0 };
-	static uint8_t guid_static[8];
-	uint32_t pid, host_crc;
-
-	/* we'll use the current time in nanoseconds as the initial 64bit
-	   counter. */
-	if (ts.tv_sec == 0) {
-		if (clock_gettime(CLOCK_REALTIME, &ts) < 0)
-			i_fatal("clock_gettime() failed: %m");
-		pid = getpid();
-		host_crc = crc32_str(my_hostname);
-
-		guid_static[0] = (pid & 0x000000ff);
-		guid_static[1] = (pid & 0x0000ff00) >> 8;
-		guid_static[2] = (pid & 0x00ff0000) >> 16;
-		guid_static[3] = (pid & 0xff000000) >> 24;
-		guid_static[4] = (host_crc & 0x000000ff);
-		guid_static[5] = (host_crc & 0x0000ff00) >> 8;
-		guid_static[6] = (host_crc & 0x00ff0000) >> 16;
-		guid_static[7] = (host_crc & 0xff000000) >> 24;
-	} else if ((uint32_t)ts.tv_nsec < (uint32_t)-1) {
-		ts.tv_nsec++;
-	} else {
-		ts.tv_sec++;
-		ts.tv_nsec = 0;
-	}
-
-	guid[0] = (ts.tv_nsec & 0x000000ff);
-	guid[1] = (ts.tv_nsec & 0x0000ff00) >> 8;
-	guid[2] = (ts.tv_nsec & 0x00ff0000) >> 16;
-	guid[3] = (ts.tv_nsec & 0xff000000) >> 24;
-	guid[4] = (ts.tv_sec & 0x000000ff);
-	guid[5] = (ts.tv_sec & 0x0000ff00) >> 8;
-	guid[6] = (ts.tv_sec & 0x00ff0000) >> 16;
-	guid[7] = (ts.tv_sec & 0xff000000) >> 24;
-	memcpy(guid + 8, guid_static, 8);
-}
-
-void mail_generate_guid_128_hash(const char *guid,
-				 uint8_t guid_128[MAIL_GUID_128_SIZE])
+void mail_generate_guid_128_hash(const char *guid, guid_128_t guid_128_r)
 {
 	unsigned char sha1_sum[SHA1_RESULTLEN];
 	buffer_t buf;
 
-	buffer_create_data(&buf, guid_128, MAIL_GUID_128_SIZE);
-	if (strlen(guid) != MAIL_GUID_128_SIZE*2 ||
-	    hex_to_binary(guid, &buf) < 0 ||
-	    buf.used != MAIL_GUID_128_SIZE) {
+	if (guid_128_from_string(guid, guid_128_r) < 0) {
 		/* not 128bit hex. use a hash of it instead. */
+		buffer_create_data(&buf, guid_128_r, GUID_128_SIZE);
 		buffer_set_used_size(&buf, 0);
 		sha1_get_digest(guid, strlen(guid), sha1_sum);
 #if SHA1_RESULTLEN < DBOX_GUID_BIN_LEN
 #  error not possible
 #endif
 		buffer_append(&buf,
-			      sha1_sum + SHA1_RESULTLEN - MAIL_GUID_128_SIZE,
-			      MAIL_GUID_128_SIZE);
+			      sha1_sum + SHA1_RESULTLEN - GUID_128_SIZE,
+			      GUID_128_SIZE);
 	}
 }
-
-bool mail_guid_128_is_empty(const uint8_t guid_128[MAIL_GUID_128_SIZE])
-{
-	unsigned int i;
-
-	for (i = 0; i < MAIL_GUID_128_SIZE; i++) {
-		if (guid_128[i] != 0)
-			return FALSE;
-	}
-	return TRUE;
-}
-
-const char *mail_guid_128_to_string(const uint8_t guid_128[MAIL_GUID_128_SIZE])
-{
-	return binary_to_hex(guid_128, MAIL_GUID_128_SIZE);
-}
-
-unsigned int mail_guid_128_hash(const void *p)
-{
-	const uint8_t *guid = p;
-
-	return mem_hash(guid, MAIL_GUID_128_SIZE);
-}
-
-int mail_guid_128_cmp(const void *p1, const void *p2)
-{
-	const uint8_t *g1 = p1, *g2 = p2;
-
-	return memcmp(g1, g2, MAIL_GUID_128_SIZE);
-}
--- a/src/lib-storage/mailbox-guid-cache.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/mailbox-guid-cache.c	Thu Aug 25 01:16:11 2011 +0300
@@ -7,40 +7,23 @@
 #include "mailbox-guid-cache.h"
 
 struct mailbox_guid_cache_rec {
-	uint8_t guid[MAIL_GUID_128_SIZE];
+	guid_128_t guid;
 	const char *vname;
 };
 
-static unsigned int guid_cache_rec_hash(const void *_rec)
-{
-	const struct mailbox_guid_cache_rec *rec = _rec;
-
-	return mem_hash(rec->guid, sizeof(rec->guid));
-}
-
-static int guid_cache_rec_cmp(const void *_r1, const void *_r2)
-{
-	const struct mailbox_guid_cache_rec *r1 = _r1, *r2 = _r2;
-
-	return memcmp(r1->guid, r2->guid, sizeof(r1->guid));
-}
-
 int mailbox_guid_cache_find(struct mailbox_list *list,
-			    uint8_t guid[MAIL_GUID_128_SIZE],
-			    const char **vname_r)
+			    const guid_128_t guid, const char **vname_r)
 {
 	const struct mailbox_guid_cache_rec *rec;
-	struct mailbox_guid_cache_rec lookup_rec;
 
-	memcpy(lookup_rec.guid, guid, sizeof(lookup_rec.guid));
 	if (list->guid_cache == NULL) {
 		mailbox_guid_cache_refresh(list);
-		rec = hash_table_lookup(list->guid_cache, &lookup_rec);
+		rec = hash_table_lookup(list->guid_cache, guid);
 	} else {
-		rec = hash_table_lookup(list->guid_cache, &lookup_rec);
+		rec = hash_table_lookup(list->guid_cache, guid);
 		if (rec == NULL) {
 			mailbox_guid_cache_refresh(list);
-			rec = hash_table_lookup(list->guid_cache, &lookup_rec);
+			rec = hash_table_lookup(list->guid_cache, guid);
 		}
 	}
 	if (rec == NULL) {
@@ -64,8 +47,8 @@
 			pool_alloconly_create("guid cache", 1024*16);
 		list->guid_cache = hash_table_create(default_pool,
 						     list->guid_cache_pool, 0,
-						     guid_cache_rec_hash,
-						     guid_cache_rec_cmp);
+						     guid_128_hash,
+						     guid_128_cmp);
 	} else {
 		hash_table_clear(list->guid_cache, TRUE);
 		p_clear(list->guid_cache_pool);
@@ -90,7 +73,7 @@
 				    struct mailbox_guid_cache_rec, 1);
 			memcpy(rec->guid, metadata.guid, sizeof(rec->guid));
 			rec->vname = p_strdup(list->guid_cache_pool, info->name);
-			hash_table_insert(list->guid_cache, rec, rec);
+			hash_table_insert(list->guid_cache, rec->guid, rec);
 		}
 		mailbox_free(&box);
 	}
--- a/src/lib-storage/mailbox-guid-cache.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/mailbox-guid-cache.h	Thu Aug 25 01:16:11 2011 +0300
@@ -1,8 +1,7 @@
 #ifndef MAILBOX_GUID_CACHE_H
 #define MAILBOX_GUID_CACHE_H
 
-int mailbox_guid_cache_find(struct mailbox_list *list,
-			    uint8_t guid[MAIL_GUID_128_SIZE],
+int mailbox_guid_cache_find(struct mailbox_list *list, const guid_128_t guid,
 			    const char **vname_r);
 void mailbox_guid_cache_refresh(struct mailbox_list *list);
 
--- a/src/lib-storage/mailbox-list-private.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/mailbox-list-private.h	Thu Aug 25 01:16:11 2011 +0300
@@ -200,11 +200,10 @@
 
 void mailbox_list_add_change(struct mailbox_list *list,
 			     enum mailbox_log_record_type type,
-			     const uint8_t mailbox_guid[MAIL_GUID_128_SIZE]);
+			     const guid_128_t guid_128);
 int mailbox_list_get_guid_path(struct mailbox_list *list, const char *path,
-			       uint8_t mailbox_guid[MAIL_GUID_128_SIZE]);
-void mailbox_name_get_sha128(const char *name,
-			     uint8_t guid[MAIL_GUID_128_SIZE]);
+			       guid_128_t guid_128_r);
+void mailbox_name_get_sha128(const char *name, guid_128_t guid_128_r);
 
 void mailbox_list_clear_error(struct mailbox_list *list);
 void mailbox_list_set_error(struct mailbox_list *list,
--- a/src/lib-storage/mailbox-list.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/mailbox-list.c	Thu Aug 25 01:16:11 2011 +0300
@@ -1386,13 +1386,13 @@
 
 void mailbox_list_add_change(struct mailbox_list *list,
 			     enum mailbox_log_record_type type,
-			     const uint8_t mailbox_guid[MAIL_GUID_128_SIZE])
+			     const guid_128_t mailbox_guid)
 {
 	struct mailbox_log_record rec;
 	time_t stamp;
 
 	if (!mailbox_list_init_changelog(list) ||
-	    mail_guid_128_is_empty(mailbox_guid))
+	    guid_128_is_empty(mailbox_guid))
 		return;
 
 	if (!list->index_root_dir_created) {
@@ -1413,7 +1413,7 @@
 int mailbox_list_set_subscribed(struct mailbox_list *list,
 				const char *name, bool set)
 {
-	uint8_t guid[MAIL_GUID_128_SIZE];
+	guid_128_t guid;
 	int ret;
 
 	/* make sure we'll refresh the file on next list */
@@ -1463,12 +1463,12 @@
 	return list->v.delete_symlink(list, name);
 }
 
-void mailbox_name_get_sha128(const char *name, uint8_t guid[MAIL_GUID_128_SIZE])
+void mailbox_name_get_sha128(const char *name, guid_128_t guid_128_r)
 {
 	unsigned char sha[SHA1_RESULTLEN];
 
 	sha1_get_digest(name, strlen(name), sha);
-	memcpy(guid, sha, I_MIN(MAIL_GUID_128_SIZE, sizeof(sha)));
+	memcpy(guid_128_r, sha, I_MIN(GUID_128_SIZE, sizeof(sha)));
 }
 
 struct mailbox_log *mailbox_list_get_changelog(struct mailbox_list *list)
--- a/src/lib-storage/mailbox-list.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/mailbox-list.h	Thu Aug 25 01:16:11 2011 +0300
@@ -1,7 +1,7 @@
 #ifndef MAILBOX_LIST_H
 #define MAILBOX_LIST_H
 
-#include "mail-types.h"
+#include "guid.h"
 #include "mail-error.h"
 
 #ifdef PATH_MAX
--- a/src/lib-storage/test-mailbox-get.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib-storage/test-mailbox-get.c	Thu Aug 25 01:16:11 2011 +0300
@@ -7,7 +7,7 @@
 #include "mail-storage-private.h"
 
 static uint32_t expunge_uids[] = { 25, 15, 7, 3, 11, 1, 53, 33 };
-static uint8_t mail_guids[N_ELEMENTS(expunge_uids)][MAIL_GUID_128_SIZE];
+static guid_128_t mail_guids[N_ELEMENTS(expunge_uids)];
 static unsigned int expunge_idx;
 static unsigned int nonexternal_idx;
 
@@ -113,8 +113,8 @@
 	test_begin("mailbox get expunges");
 
 	nonexternal_idx = 1;
-	memset(mail_guids + 2, 0, MAIL_GUID_128_SIZE);
-	memset(mail_guids + 4, 0, MAIL_GUID_128_SIZE);
+	memset(mail_guids + 2, 0, GUID_128_SIZE);
+	memset(mail_guids + 4, 0, GUID_128_SIZE);
 
 	t_array_init(&uids_filter, 32);
 	seq_range_array_add_range(&uids_filter, 1, 20);
@@ -128,15 +128,15 @@
 	exp = array_get(&expunges, &count);
 	test_assert(count == 5);
 	test_assert(exp[0].uid == 3);
-	test_assert(memcmp(exp[0].guid_128, mail_guids[3], MAIL_GUID_128_SIZE) == 0);
+	test_assert(memcmp(exp[0].guid_128, mail_guids[3], GUID_128_SIZE) == 0);
 	test_assert(exp[1].uid == 1);
-	test_assert(memcmp(exp[1].guid_128, mail_guids[5], MAIL_GUID_128_SIZE) == 0);
+	test_assert(memcmp(exp[1].guid_128, mail_guids[5], GUID_128_SIZE) == 0);
 	test_assert(exp[2].uid == 53);
-	test_assert(memcmp(exp[2].guid_128, mail_guids[6], MAIL_GUID_128_SIZE) == 0);
+	test_assert(memcmp(exp[2].guid_128, mail_guids[6], GUID_128_SIZE) == 0);
 	test_assert(exp[3].uid == 7);
-	test_assert(memcmp(exp[3].guid_128, mail_guids[2], MAIL_GUID_128_SIZE) == 0);
+	test_assert(memcmp(exp[3].guid_128, mail_guids[2], GUID_128_SIZE) == 0);
 	test_assert(exp[4].uid == 11);
-	test_assert(memcmp(exp[4].guid_128, mail_guids[4], MAIL_GUID_128_SIZE) == 0);
+	test_assert(memcmp(exp[4].guid_128, mail_guids[4], GUID_128_SIZE) == 0);
 
 	test_end();
 }
@@ -150,7 +150,7 @@
 	unsigned int i, j;
 
 	for (i = 0; i < N_ELEMENTS(mail_guids); i++) {
-		for (j = 0; j < MAIL_GUID_128_SIZE; j++)
+		for (j = 0; j < GUID_128_SIZE; j++)
 			mail_guids[i][j] = j + i + 1;
 	}
 	return test_run(test_functions);
--- a/src/lib/Makefile.am	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lib/Makefile.am	Thu Aug 25 01:16:11 2011 +0300
@@ -35,6 +35,7 @@
 	file-dotlock.c \
 	file-lock.c \
 	file-set-size.c \
+	guid.c \
 	hash.c \
 	hash-format.c \
 	hash-method.c \
@@ -148,6 +149,7 @@
 	file-lock.h \
 	file-set-size.h \
 	fsync-mode.h \
+	guid.h \
 	hash.h \
 	hash-format.h \
 	hash-method.h \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/guid.c	Thu Aug 25 01:16:11 2011 +0300
@@ -0,0 +1,115 @@
+/* Copyright (c) 2011 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "buffer.h"
+#include "crc32.h"
+#include "hash.h"
+#include "hex-binary.h"
+#include "hostpid.h"
+#include "guid.h"
+
+#include <unistd.h>
+#include <time.h>
+
+const char *guid_generate(void)
+{
+	static struct timespec ts = { 0, 0 };
+	static unsigned int pid = 0;
+
+	/* we'll use the current time in nanoseconds as the initial 64bit
+	   counter. */
+	if (ts.tv_sec == 0) {
+		if (clock_gettime(CLOCK_REALTIME, &ts) < 0)
+			i_fatal("clock_gettime() failed: %m");
+		pid = getpid();
+	} else if ((uint32_t)ts.tv_nsec < (uint32_t)-1) {
+		ts.tv_nsec++;
+	} else {
+		ts.tv_sec++;
+		ts.tv_nsec = 0;
+	}
+	return t_strdup_printf("%04x%04lx%04x%s",
+			       (unsigned int)ts.tv_nsec,
+			       (unsigned long)ts.tv_sec,
+			       pid, my_hostname);
+}
+
+void guid_128_generate(guid_128_t guid_r)
+{
+	static struct timespec ts = { 0, 0 };
+	static uint8_t guid_static[8];
+	uint32_t pid, host_crc;
+
+	/* we'll use the current time in nanoseconds as the initial 64bit
+	   counter. */
+	if (ts.tv_sec == 0) {
+		if (clock_gettime(CLOCK_REALTIME, &ts) < 0)
+			i_fatal("clock_gettime() failed: %m");
+		pid = getpid();
+		host_crc = crc32_str(my_hostname);
+
+		guid_static[0] = (pid & 0x000000ff);
+		guid_static[1] = (pid & 0x0000ff00) >> 8;
+		guid_static[2] = (pid & 0x00ff0000) >> 16;
+		guid_static[3] = (pid & 0xff000000) >> 24;
+		guid_static[4] = (host_crc & 0x000000ff);
+		guid_static[5] = (host_crc & 0x0000ff00) >> 8;
+		guid_static[6] = (host_crc & 0x00ff0000) >> 16;
+		guid_static[7] = (host_crc & 0xff000000) >> 24;
+	} else if ((uint32_t)ts.tv_nsec < (uint32_t)-1) {
+		ts.tv_nsec++;
+	} else {
+		ts.tv_sec++;
+		ts.tv_nsec = 0;
+	}
+
+	guid_r[0] = (ts.tv_nsec & 0x000000ff);
+	guid_r[1] = (ts.tv_nsec & 0x0000ff00) >> 8;
+	guid_r[2] = (ts.tv_nsec & 0x00ff0000) >> 16;
+	guid_r[3] = (ts.tv_nsec & 0xff000000) >> 24;
+	guid_r[4] = (ts.tv_sec & 0x000000ff);
+	guid_r[5] = (ts.tv_sec & 0x0000ff00) >> 8;
+	guid_r[6] = (ts.tv_sec & 0x00ff0000) >> 16;
+	guid_r[7] = (ts.tv_sec & 0xff000000) >> 24;
+	memcpy(guid_r + 8, guid_static, 8);
+}
+
+bool guid_128_is_empty(const guid_128_t guid)
+{
+	unsigned int i;
+
+	for (i = 0; i < GUID_128_SIZE; i++) {
+		if (guid[i] != 0)
+			return FALSE;
+	}
+	return TRUE;
+}
+
+int guid_128_from_string(const char *str, guid_128_t guid_r)
+{
+	buffer_t buf;
+
+	buffer_create_data(&buf, guid_r, GUID_128_SIZE);
+	return strlen(str) == GUID_128_SIZE*2 &&
+		hex_to_binary(str, &buf) == 0 &&
+		buf.used == GUID_128_SIZE ? 0 : -1;
+}
+
+const char *guid_128_to_string(const guid_128_t guid)
+{
+	return binary_to_hex(guid, GUID_128_SIZE);
+}
+
+unsigned int guid_128_hash(const void *p)
+{
+	const uint8_t *guid = p;
+
+	return mem_hash(guid, GUID_128_SIZE);
+}
+
+int guid_128_cmp(const void *p1, const void *p2)
+{
+	const uint8_t *g1 = p1, *g2 = p2;
+
+	return memcmp(g1, g2, GUID_128_SIZE);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/guid.h	Thu Aug 25 01:16:11 2011 +0300
@@ -0,0 +1,23 @@
+#ifndef GUID_H
+#define GUID_H
+
+#define GUID_128_SIZE 16
+typedef uint8_t guid_128_t[GUID_128_SIZE];
+
+/* Generate a GUID (contains host name) */
+const char *guid_generate(void);
+/* Generate 128 bit GUID */
+void guid_128_generate(guid_128_t guid_r);
+/* Returns TRUE if GUID is empty (not set / unknown). */
+bool guid_128_is_empty(const guid_128_t guid);
+
+/* Returns GUID as a hex string. */
+const char *guid_128_to_string(const guid_128_t guid);
+/* Parse GUID from a string. Returns 0 if ok, -1 if GUID isn't valid. */
+int guid_128_from_string(const char *str, guid_128_t guid_r);
+
+/* guid_128 hash/cmp functions for hash.h */
+unsigned int guid_128_hash(const void *p);
+int guid_128_cmp(const void *p1, const void *p2);
+
+#endif
--- a/src/lmtp/client.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/lmtp/client.c	Thu Aug 25 01:16:11 2011 +0300
@@ -171,10 +171,10 @@
 
 static void client_generate_session_id(struct client *client)
 {
-	uint8_t guid[MAIL_GUID_128_SIZE];
+	guid_128_t guid;
 	string_t *id = t_str_new(30);
 
-	mail_generate_guid_128(guid);
+	guid_128_generate(guid);
 	base64_encode(guid, sizeof(guid), id);
 	i_assert(str_c(id)[str_len(id)-2] == '=');
 	str_truncate(id, str_len(id)-2); /* drop trailing "==" */
--- a/src/plugins/fts-lucene/doveadm-fts-lucene.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/plugins/fts-lucene/doveadm-fts-lucene.c	Thu Aug 25 01:16:11 2011 +0300
@@ -1,7 +1,6 @@
 /* Copyright (c) 2011 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
-#include "hex-binary.h"
 #include "doveadm-dump.h"
 #include "doveadm-fts.h"
 #include "lucene-wrapper.h"
@@ -18,7 +17,7 @@
 {
 	struct lucene_index *index;
 	struct lucene_index_iter *iter;
-	mail_guid_128_t prev_guid;
+	guid_128_t prev_guid;
 	const struct lucene_index_record *rec;
 	bool first = TRUE;
 
@@ -33,7 +32,7 @@
 			else
 				printf("\n");
 			memcpy(prev_guid, rec->mailbox_guid, sizeof(prev_guid));
-			printf("%s: ", binary_to_hex(prev_guid, sizeof(prev_guid)));
+			printf("%s: ", guid_128_to_string(prev_guid));
 		}
 		printf("%u,", rec->uid);
 	}
--- a/src/plugins/fts-lucene/fts-backend-lucene.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/plugins/fts-lucene/fts-backend-lucene.c	Thu Aug 25 01:16:11 2011 +0300
@@ -24,7 +24,7 @@
 	struct lucene_index *index;
 	struct mailbox *selected_box;
 	unsigned int selected_box_generation;
-	mail_guid_128_t selected_box_guid;
+	guid_128_t selected_box_guid;
 
 	struct fts_expunge_log *expunge_log;
 
@@ -62,7 +62,7 @@
 }
 
 static int
-fts_lucene_get_mailbox_guid(struct mailbox *box, mail_guid_128_t *guid_r)
+fts_lucene_get_mailbox_guid(struct mailbox *box, guid_128_t guid_r)
 {
 	struct mailbox_metadata metadata;
 
@@ -72,14 +72,14 @@
 			box->vname, mailbox_get_last_error(box, NULL));
 		return -1;
 	}
-	memcpy(guid_r, metadata.guid, MAIL_GUID_128_SIZE);
+	memcpy(guid_r, metadata.guid, GUID_128_SIZE);
 	return 0;
 }
 
 static int
 fts_backend_select(struct lucene_fts_backend *backend, struct mailbox *box)
 {
-	mail_guid_128_t guid;
+	guid_128_t guid;
 	unsigned char guid_hex[MAILBOX_GUID_HEX_LENGTH];
 	wchar_t wguid_hex[MAILBOX_GUID_HEX_LENGTH];
 	buffer_t buf;
@@ -90,10 +90,10 @@
 		return 0;
 
 	if (box != NULL) {
-		if (fts_lucene_get_mailbox_guid(box, &guid) < 0)
+		if (fts_lucene_get_mailbox_guid(box, guid) < 0)
 			return -1;
 		buffer_create_data(&buf, guid_hex, MAILBOX_GUID_HEX_LENGTH);
-		binary_to_hex_append(&buf, guid, MAIL_GUID_128_SIZE);
+		binary_to_hex_append(&buf, guid, GUID_128_SIZE);
 		for (i = 0; i < N_ELEMENTS(wguid_hex); i++)
 			wguid_hex[i] = guid_hex[i];
 
--- a/src/plugins/fts-lucene/lucene-wrapper.cc	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/plugins/fts-lucene/lucene-wrapper.cc	Thu Aug 25 01:16:11 2011 +0300
@@ -66,7 +66,7 @@
 	struct lucene_index *index;
 
 	struct mailbox *box;
-	mail_guid_128_t box_guid;
+	guid_128_t box_guid;
 	int box_ret;
 
 	pool_t pool;
@@ -501,10 +501,10 @@
 }
 
 static int
-wcharguid_to_guid(mail_guid_128_t *dest, const wchar_t *src)
+wcharguid_to_guid(guid_128_t dest, const wchar_t *src)
 {
 	buffer_t buf = { 0, 0, { 0, 0, 0, 0, 0 } };
-	char src_chars[MAIL_GUID_128_SIZE*2 + 1];
+	char src_chars[GUID_128_SIZE*2 + 1];
 	unsigned int i;
 
 	for (i = 0; i < sizeof(src_chars)-1; i++) {
@@ -551,7 +551,7 @@
 
 static int
 fts_lucene_get_mailbox_guid(struct lucene_index *index, Document *doc,
-			    mail_guid_128_t *guid_r)
+			    guid_128_t guid_r)
 {
 	Field *field = doc->getField(_T("box"));
 	const TCHAR *box_guid = field == NULL ? NULL : field->stringValue();
@@ -572,10 +572,10 @@
 static int
 rescan_open_mailbox(struct rescan_context *ctx, Document *doc)
 {
-	mail_guid_128_t guid, *guidp;
+	guid_128_t guid, *guidp;
 	int ret;
 
-	if (fts_lucene_get_mailbox_guid(ctx->index, doc, &guid) < 0)
+	if (fts_lucene_get_mailbox_guid(ctx->index, doc, guid) < 0)
 		return 0;
 
 	if (memcmp(guid, ctx->box_guid, sizeof(guid)) == 0) {
@@ -584,7 +584,7 @@
 	}
 	memcpy(ctx->box_guid, guid, sizeof(ctx->box_guid));
 
-	guidp = p_new(ctx->pool, mail_guid_128_t, 1);
+	guidp = p_new(ctx->pool, guid_128_t, 1);
 	memcpy(guidp, guid, sizeof(*guidp));
 	hash_table_insert(ctx->guids, guidp, guidp);
 
@@ -698,7 +698,7 @@
 {
 	static const TCHAR *sort_fields[] = { _T("box"), _T("uid"), NULL };
 	struct rescan_context ctx;
-	mail_guid_128_t guid;
+	guid_128_t guid;
 	bool failed = false;
 	int ret;
 
@@ -715,8 +715,7 @@
 	ctx.index = index;
 	ctx.pool = pool_alloconly_create("guids", 1024);
 	ctx.guids = hash_table_create(default_pool, ctx.pool, 0,
-				      mail_guid_128_hash,
-				      mail_guid_128_cmp);
+				      guid_128_hash, guid_128_cmp);
 	i_array_init(&ctx.uids, 128);
 
 	if (ret > 0) try {
@@ -748,7 +747,7 @@
 	return failed ? -1 : 0;
 }
 
-static void guid128_to_wguid(const mail_guid_128_t guid,
+static void guid128_to_wguid(const guid_128_t guid,
 			     wchar_t wguid_hex[MAILBOX_GUID_HEX_LENGTH + 1])
 {
 	buffer_t buf = { 0, 0, { 0, 0, 0, 0, 0 } };
@@ -756,7 +755,7 @@
 	unsigned int i;
 
 	buffer_create_data(&buf, guid_hex, MAILBOX_GUID_HEX_LENGTH);
-	binary_to_hex_append(&buf, guid, MAIL_GUID_128_SIZE);
+	binary_to_hex_append(&buf, guid, GUID_128_SIZE);
 	for (i = 0; i < MAILBOX_GUID_HEX_LENGTH; i++)
 		wguid_hex[i] = guid_hex[i];
 	wguid_hex[i] = '\0';
@@ -1332,7 +1331,7 @@
 
 	memset(&iter->rec, 0, sizeof(iter->rec));
 	(void)fts_lucene_get_mailbox_guid(iter->index, doc,
-					  &iter->rec.mailbox_guid);
+					  iter->rec.mailbox_guid);
 	(void)lucene_doc_get_uid(iter->index, doc, &iter->rec.uid);
 	return &iter->rec;
 }
--- a/src/plugins/fts-lucene/lucene-wrapper.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/plugins/fts-lucene/lucene-wrapper.h	Thu Aug 25 01:16:11 2011 +0300
@@ -2,17 +2,17 @@
 #define LUCENE_WRAPPER_H
 
 #include "fts-api-private.h"
-#include "mail-types.h"
+#include "guid.h"
 
 struct hash_table;
 struct mailbox_list;
 struct fts_expunge_log;
 struct fts_lucene_settings;
 
-#define MAILBOX_GUID_HEX_LENGTH (MAIL_GUID_128_SIZE*2)
+#define MAILBOX_GUID_HEX_LENGTH (GUID_128_SIZE*2)
 
 struct lucene_index_record {
-	mail_guid_128_t mailbox_guid;
+	guid_128_t mailbox_guid;
 	uint32_t uid;
 };
 
--- a/src/plugins/fts/doveadm-dump-fts-expunge-log.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/plugins/fts/doveadm-dump-fts-expunge-log.c	Thu Aug 25 01:16:11 2011 +0300
@@ -3,7 +3,7 @@
 #include "lib.h"
 #include "buffer.h"
 #include "hex-binary.h"
-#include "mail-types.h"
+#include "guid.h"
 #include "doveadm-dump.h"
 #include "doveadm-fts.h"
 
@@ -14,7 +14,7 @@
 struct fts_expunge_log_record {
 	uint32_t checksum;
 	uint32_t record_size;
-	mail_guid_128_t guid;
+	guid_128_t guid;
 };
 
 static int dump_record(int fd, buffer_t *buf)
@@ -46,7 +46,7 @@
 	printf("#%"PRIuUOFF_T":\n", offset);
 	printf("  checksum  = %8x\n", rec.checksum);
 	printf("  size .... = %u\n", rec.record_size);
-	printf("  mailbox . = %s\n", binary_to_hex(rec.guid, sizeof(rec.guid)));
+	printf("  mailbox . = %s\n", guid_128_to_string(rec.guid));
 
 	expunges = CONST_PTR_OFFSET(data, data_size - sizeof(uint32_t));
 	printf("  expunges  = %u\n", *expunges);
--- a/src/plugins/fts/fts-api-private.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/plugins/fts/fts-api-private.h	Thu Aug 25 01:16:11 2011 +0300
@@ -5,7 +5,7 @@
 
 struct mail_user;
 
-#define MAILBOX_GUID_HEX_LENGTH (MAIL_GUID_128_SIZE*2)
+#define MAILBOX_GUID_HEX_LENGTH (GUID_128_SIZE*2)
 
 struct fts_backend_vfuncs {
 	struct fts_backend *(*alloc)(void);
--- a/src/plugins/fts/fts-api.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/plugins/fts/fts-api.c	Thu Aug 25 01:16:11 2011 +0300
@@ -388,14 +388,10 @@
 int fts_mailbox_get_guid(struct mailbox *box, const char **guid_r)
 {
 	struct mailbox_metadata metadata;
-	buffer_t buf;
-	unsigned char guid_hex[MAILBOX_GUID_HEX_LENGTH];
 
 	if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID, &metadata) < 0)
 		return -1;
 
-	buffer_create_data(&buf, guid_hex, sizeof(guid_hex));
-	binary_to_hex_append(&buf, metadata.guid, MAIL_GUID_128_SIZE);
-	*guid_r = t_strndup(guid_hex, sizeof(guid_hex));
+	*guid_r = guid_128_to_string(metadata.guid);
 	return 0;
 }
--- a/src/plugins/fts/fts-expunge-log.c	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/plugins/fts/fts-expunge-log.c	Thu Aug 25 01:16:11 2011 +0300
@@ -21,7 +21,7 @@
 	uint32_t record_size;
 
 	/* Mailbox GUID */
-	mail_guid_128_t guid;
+	guid_128_t guid;
 	/* { uid1, uid2 } pairs */
 	/* uint32_t expunge_uid_ranges[]; */
 
@@ -37,7 +37,7 @@
 };
 
 struct fts_expunge_log_mailbox {
-	mail_guid_128_t guid;
+	guid_128_t guid;
 	ARRAY_TYPE(seq_range) uids;
 	unsigned uids_count;
 };
@@ -179,7 +179,7 @@
 	ctx->pool = pool;
 	ctx->mailboxes =
 		hash_table_create(default_pool, pool, 0,
-				  mail_guid_128_hash, mail_guid_128_cmp);
+				  guid_128_hash, guid_128_cmp);
 
 	if (fts_expunge_log_reopen_if_needed(log, TRUE) < 0)
 		ctx->failed = TRUE;
@@ -188,7 +188,7 @@
 
 static struct fts_expunge_log_mailbox *
 fts_expunge_log_mailbox_alloc(struct fts_expunge_log_append_ctx *ctx,
-			      const mail_guid_128_t mailbox_guid)
+			      const guid_128_t mailbox_guid)
 {
 	struct fts_expunge_log_mailbox *mailbox;
 
@@ -200,7 +200,7 @@
 }
 
 void fts_expunge_log_append_next(struct fts_expunge_log_append_ctx *ctx,
-				 const mail_guid_128_t mailbox_guid,
+				 const guid_128_t mailbox_guid,
 				 uint32_t uid)
 {
 	struct fts_expunge_log_mailbox *mailbox;
--- a/src/plugins/fts/fts-expunge-log.h	Thu Aug 25 00:27:41 2011 +0300
+++ b/src/plugins/fts/fts-expunge-log.h	Thu Aug 25 01:16:11 2011 +0300
@@ -2,10 +2,10 @@
 #define FTS_EXPUNGE_LOG
 
 #include "seq-range-array.h"
-#include "mail-types.h"
+#include "guid.h"
 
 struct fts_expunge_log_read_record {
-	mail_guid_128_t mailbox_guid;
+	guid_128_t mailbox_guid;
 	ARRAY_TYPE(seq_range) uids;
 };
 
@@ -15,7 +15,7 @@
 struct fts_expunge_log_append_ctx *
 fts_expunge_log_append_begin(struct fts_expunge_log *log);
 void fts_expunge_log_append_next(struct fts_expunge_log_append_ctx *ctx,
-				 const mail_guid_128_t mailbox_guid,
+				 const guid_128_t mailbox_guid,
 				 uint32_t uid);
 int fts_expunge_log_append_commit(struct fts_expunge_log_append_ctx **ctx);