dovecot-1.1: logview: Expand header update records to user-reada...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Jun 13 01:43:23 EEST 2008
details: http://hg.dovecot.org/dovecot-1.1/rev/082bb2fcf365
changeset: 7653:082bb2fcf365
user: Timo Sirainen <tss at iki.fi>
date: Fri Jun 13 01:43:19 2008 +0300
description:
logview: Expand header update records to user-readable form.
diffstat:
1 file changed, 96 insertions(+), 10 deletions(-)
src/util/logview.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++-----
diffs (123 lines):
diff -r bc3eab510b2b -r 082bb2fcf365 src/util/logview.c
--- a/src/util/logview.c Fri Jun 13 00:48:58 2008 +0300
+++ b/src/util/logview.c Fri Jun 13 01:43:19 2008 +0300
@@ -103,6 +103,101 @@ static void print_data(const void *data,
}
}
+static void print_try_uint(const void *data, size_t size)
+{
+ size_t i;
+
+ switch (size) {
+ case 1: {
+ const uint8_t *n = data;
+ printf("%u", *n);
+ break;
+ }
+ case 2: {
+ const uint16_t *n = data;
+ printf("%u", *n);
+ break;
+ }
+ case 4: {
+ const uint32_t *n = data;
+ printf("%u", *n);
+ break;
+ }
+ case 8: {
+ const uint64_t *n = data;
+ printf("%llu", (unsigned long long)*n);
+ break;
+ }
+ default:
+ for (i = 0; i < size; i++)
+ printf("%02x", ((const unsigned char *)data)[i]);
+ }
+}
+
+#define HDRF(field) { \
+ #field, offsetof(struct mail_index_header, field), \
+ sizeof(((struct mail_index_header *)0)->field) }
+
+static struct {
+ const char *name;
+ unsigned int offset, size;
+} header_fields[] = {
+ HDRF(minor_version),
+ HDRF(base_header_size),
+ HDRF(header_size),
+ HDRF(record_size),
+ HDRF(compat_flags),
+ HDRF(indexid),
+ HDRF(flags),
+ HDRF(uid_validity),
+ HDRF(next_uid),
+ HDRF(messages_count),
+ HDRF(unused_old_recent_messages_count),
+ HDRF(seen_messages_count),
+ HDRF(deleted_messages_count),
+ HDRF(first_recent_uid),
+ HDRF(first_unseen_uid_lowwater),
+ HDRF(first_deleted_uid_lowwater),
+ HDRF(log_file_seq),
+ HDRF(log_file_tail_offset),
+ HDRF(log_file_head_offset),
+ HDRF(sync_size),
+ HDRF(sync_stamp),
+ HDRF(day_stamp)
+};
+
+static void log_header_update(const struct mail_transaction_header_update *u)
+{
+ const void *data = u + 1;
+ unsigned int offset = u->offset, size = u->size;
+ unsigned int i;
+
+ while (size > 0) {
+ /* don't bother trying to handle header updates that include
+ unknown/unexpected fields offsets/sizes */
+ for (i = 0; i < N_ELEMENTS(header_fields); i++) {
+ if (header_fields[i].offset == offset &&
+ header_fields[i].size <= size)
+ break;
+ }
+
+ if (i == N_ELEMENTS(header_fields)) {
+ printf(" - offset = %u, size = %u: ", offset, size);
+ print_data(data, size);
+ printf("\n");
+ break;
+ }
+
+ printf(" - %s = ", header_fields[i].name);
+ print_try_uint(data, header_fields[i].size);
+ printf("\n");
+
+ data = CONST_PTR_OFFSET(data, header_fields[i].size);
+ offset += header_fields[i].size;
+ size -= header_fields[i].size;
+ }
+}
+
static void log_record_print(const struct mail_transaction_header *hdr,
const void *data)
{
@@ -144,16 +239,7 @@ static void log_record_print(const struc
case MAIL_TRANSACTION_HEADER_UPDATE: {
const struct mail_transaction_header_update *u = data;
- if (u->offset == offsetof(struct mail_index_header,
- log_file_tail_offset) &&
- u->size == sizeof(uint32_t)) {
- printf(" - log_file_tail_offset = %u\n",
- *(const uint32_t *)(u + 1));
- break;
- }
- printf(" - offset = %u, size = %u: ", u->offset, u->size);
- print_data(u + 1, u->size);
- printf("\n");
+ log_header_update(u);
break;
}
case MAIL_TRANSACTION_EXT_INTRO: {
More information about the dovecot-cvs
mailing list