Update of /cvsroot/meshdb/src/mailt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10213 Modified Files: Tag: leonard-dev Makefile.am index.h mail.inc size.c update.c Added Files: Tag: leonard-dev swap.c Log Message: index structure change (now version 2). align fields; provide a "swap" utility that performs byteswap on an index file --- NEW FILE: swap.c --- /* $Id: swap.c,v 1.1.2.1 2005/05/02 04:44:18 leonard Exp $ */ #if defined(HAVE_CONFIG_H) # include "config.h" #endif #if defined(STDC_HEADERS) # include <stdio.h> #endif #include "index.h" static void usage(name) const char *name; { fprintf(stderr, "usage: %s <mbox.mi >mbox.mi.swapped\n", name); exit(1); } /* Functions to do byte swapping */ #define copydecl(name, halfname, type, halftype) \ static void \ name(dst, src) \ type *dst; \ const type *src; \ { \ halftype *hdst = (halftype *)dst; \ const halftype *hsrc = (const halftype *)src; \ halfname(&hdst[0], &hsrc[1]); \ halfname(&hdst[1], &hsrc[0]); \ } #define uint8copy(dst, src) *(dst) = *(src) copydecl(uint16copy, uint8copy, uint16_t, uint8_t) copydecl(uint32copy, uint16copy, uint32_t, uint16_t) copydecl(uint64copy, uint32copy, uint64_t, uint32_t) #define int8copy(dst, src) *(dst) = *(src); copydecl(int16copy, int8copy, int16_t, int8_t) copydecl(int32copy, int16copy, int32_t, int16_t) copydecl(int64copy, int32copy, int64_t, int32_t) #define msgidcopy uint32copy static void convert(out, in) struct mail *out; const struct mail *in; { uint32copy(&out->hdrlen, &in->hdrlen); uint32copy(&out->bodylen, &in->bodylen); uint64copy(&out->pos, &in->pos); int32copy(&out->date, &in->date); msgidcopy(&out->parent, &in->parent); msgidcopy(&out->child, &in->child); msgidcopy(&out->sibling, &in->sibling); uint16copy(&out->flags, &in->flags); uint16copy(&out->pad, &in->pad); memcpy(out->from, in->from, sizeof out->from); memcpy(out->subject, in->subject, sizeof out->subject); } static void checksize() { struct mail m; size_t total = 0; #define chk(field, bits) \ if (sizeof m.field * 8 != bits) { \ fprintf(stderr, \ "%s: mismatch field %s size %d, not %d bits\n", \ __FILE__, #field, 8 * sizeof m.field, bits); \ exit(1); \ } \ if ((int)&(((struct mail *)0)->field) * 8 != total) { \ fprintf(stderr, \ "%s: mismatch field %s offset %d, not %d\n", \ __FILE__, #field, \ (int)&(((struct mail *)0)->field), \ total / 8); \ exit(1); \ } chk(hdrlen, 32); total += 32; chk(bodylen, 32); total += 32; chk(pos, 64); total += 64; chk(date, 32); total += 32; chk(parent, 32); total += 32; chk(child, 32); total += 32; chk(sibling, 32); total += 32; chk(flags, 16); total += 16; chk(pad, 16); total += 16; chk(from, 32*8); total += 32*8; chk(subject, 60*8); total += 60*8; if (total != 8 * sizeof m) { fprintf(stderr, "%s: mismatch struct size %d(%d), not %d(%d)\n", __FILE__, 8 * sizeof m, sizeof m, total, total / 8); exit(1); } } int main(argc, argv) int argc; char *argv[]; { struct mail m_in, m_out; int first; if (argc != 1) usage(argv[0]); checksize(); first = 1; while (!feof(stdin)) { if (fread(&m_in, sizeof m_in, 1, stdin) != 1) { if (feof(stdin)) break; perror("fread"); } convert(&m_out, &m_in); if (first) { struct mail0 *m0in = (struct mail0 *)&m_in; struct mail0 *m0out = (struct mail0 *)&m_out; if (m0in->version != MAIL0_VERSION && m0out->version != MAIL0_VERSION) { fprintf(stderr, "version mismatch: 0x%04x (expected %x)\n", m0in->version, MAIL0_VERSION); exit(1); } if (m0in->size != sizeof m_in && m0out->size != sizeof m_in) { fprintf(stderr, "size mismatch: 0x%04x (expected %x)\n", m0in->size, sizeof m_in); exit(1); } } if (fwrite(&m_out, sizeof m_out, 1, stdout) != 1) perror("fwrite"); first = 0; } fflush(stdout); exit(0); } Index: Makefile.am =================================================================== RCS file: /cvsroot/meshdb/src/mailt/Attic/Makefile.am,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -d -r1.1.2.3 -r1.1.2.4 --- Makefile.am 8 Nov 2004 12:55:31 -0000 1.1.2.3 +++ Makefile.am 2 May 2005 04:44:17 -0000 1.1.2.4 @@ -4,7 +4,7 @@ cgibindir = @cgibindir@ htmlmaildir = @htmlmaildir@ -bin_PROGRAMS = update mkill msgid +bin_PROGRAMS = update mkill msgid swap noinst_PROGRAMS = size t noinst_LIBRARIES = libmail.a libmail_a_SOURCES = index.c datetime.c open.c util.c mime.c Index: index.h =================================================================== RCS file: /cvsroot/meshdb/src/mailt/index.h,v retrieving revision 1.1.1.1.2.1 retrieving revision 1.1.1.1.2.2 diff -u -d -r1.1.1.1.2.1 -r1.1.1.1.2.2 --- index.h 8 Nov 2004 12:55:34 -0000 1.1.1.1.2.1 +++ index.h 2 May 2005 04:44:17 -0000 1.1.1.1.2.2 @@ -18,26 +18,28 @@ uint32_t bodylen; uint64_t pos; /* start of headers in file */ int32_t date; - char from[40]; /* Sender's name */ - char subject[60]; /* Subject text */ msgid_t parent, child, sibling; /* Thread tree */ uint16_t flags; #define FLAGS_KILLED 0x0001 /* Message has been killed */ + uint16_t pad; + char from[32]; /* Sender's name */ + char subject[60]; /* Subject text */ }; /* First entry */ struct mail0 { uint32_t size; /* size of each entry */ uint32_t version; /* version check */ -#define MAIL0_VERSION 1 +#define MAIL0_VERSION 2 uint64_t end; /* total size of mbox */ int32_t date; /* index update time */ - char ign4[40]; - char ign5[60]; msgid_t msgs; /* number of messages */ msgid_t child; /* first unparented child */ msgid_t ign8; uint16_t flags; + uint16_t pad; + char ign4[32]; + char ign5[60]; }; int index_create(int fd); Index: mail.inc =================================================================== RCS file: /cvsroot/meshdb/src/mailt/mail.inc,v retrieving revision 1.1.1.1.2.2 retrieving revision 1.1.1.1.2.3 diff -u -d -r1.1.1.1.2.2 -r1.1.1.1.2.3 --- mail.inc 1 May 2005 12:28:27 -0000 1.1.1.1.2.2 +++ mail.inc 2 May 2005 04:44:17 -0000 1.1.1.1.2.3 @@ -8,11 +8,16 @@ * program reports, ideally when it is run on the same host * as the web server. */ - $FMT = "Lhdrlen/Lbodylen/Lposhi/Lposlo/Ldate/a40from" - ."/a60subject/Lparent/Lchild/Lsibling/nflags"; - $FMT0 = "Lsize/Lversion/Lendhi/Lendlo/Ldate/a40ign4" - ."/a60ign5/Lmsgs/Lchild/Lign8/nflags"; - $FMTSZ = 136; + $FMT = "Lhdrlen/Lbodylen/Lposhi/Lposlo/Ldate" + ."/Lparent/Lchild/Lsibling/nflags/npad" + ."/a32from/a60subject" + ; + $FMT0 = "Lsize/Lversion/Lendhi/Lendlo/Ldate" + ."/Lmsgs/Lchild/Lign8/nflags/npad" + ."/a32ign4/a60ign5" + ; + $MAIL0_VERSION = 2; + $FMTSZ = 128; $KILLED = 1; /* off_t is a 64-bit value. (php probably doesnt handle it) */ @@ -22,15 +27,16 @@ /* Open an mbox/index file pair */ function openmbox($mbox, $index="") { - global $FMT, $FMT0, $FMTSZ; + global $FMT, $FMT0, $FMTSZ, $MAIL0_VERSION; if ($index == "") $index = $mbox . ".mi"; $mbxf = fopen($mbox, "rb"); $idxf = fopen($index, "rb"); $m0 = unpack($FMT0, fread($idxf, $FMTSZ)); if ($m0['size'] != $FMTSZ - || $m0['version'] != 1) { - die("$index: bad format"); + || $m0['version'] != $MAIL0_VERSION) { + die("$index: bad format; size=".$m0['size'] + ." version=".$m0['version']); } /* $m0["end"] = quad($m0["endlo"], $m0["endhi"]); */ fseek($idxf, 0); Index: size.c =================================================================== RCS file: /cvsroot/meshdb/src/mailt/size.c,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -d -r1.2.2.1 -r1.2.2.2 --- size.c 8 Nov 2004 12:55:34 -0000 1.2.2.1 +++ size.c 2 May 2005 04:44:18 -0000 1.2.2.2 @@ -35,29 +35,32 @@ main() { printf("\t$FMT = \""); - P(mail, hdrlen); putchar('/'); - P(mail, bodylen); putchar('/'); - P(mail, pos); putchar('/'); - P(mail, date); putchar('/'); - P(mail, from); printf("\"\n\t\t.\"/"); - P(mail, subject); putchar('/'); - P(mail, parent); putchar('/'); - P(mail, child); putchar('/'); - P(mail, sibling); putchar('/'); - P(mail, flags); printf("\";\n"); + P(mail, hdrlen); putchar('/'); + P(mail, bodylen); putchar('/'); + P(mail, pos); putchar('/'); + P(mail, date); putchar('/'); + P(mail, parent); putchar('/'); + P(mail, child); putchar('/'); + P(mail, sibling); putchar('/'); + P(mail, flags); putchar('/'); + P(mail, pad); putchar('/'); + P(mail, from); putchar('/'); + P(mail, subject); printf("\";\n"); printf("\t$FMT0 = \""); - P(mail0, size); putchar('/'); - P(mail0, version); putchar('/'); - P(mail0, end); putchar('/'); - P(mail0, date); putchar('/'); - P(mail0, ign4); printf("\"\n\t\t.\"/"); - P(mail0, ign5); putchar('/'); - P(mail0, msgs); putchar('/'); - P(mail0, child); putchar('/'); - P(mail0, ign8); putchar('/'); - P(mail0, flags); printf("\";\n"); + P(mail0, size); putchar('/'); + P(mail0, version); putchar('/'); + P(mail0, end); putchar('/'); + P(mail0, date); putchar('/'); + P(mail0, msgs); putchar('/'); + P(mail0, child); putchar('/'); + P(mail0, ign8); putchar('/'); + P(mail0, flags); putchar('/'); + P(mail0, pad); putchar('/'); + P(mail0, ign4); putchar('/'); + P(mail0, ign5); printf("\";\n"); + printf("\t$MAIL0_VERSION = %d;\n", MAIL0_VERSION); printf("\t$FMTSZ = %d;\n", sizeof (struct mail)); printf("\t$KILLED = %d;\n", FLAGS_KILLED); exit(0); Index: update.c =================================================================== RCS file: /cvsroot/meshdb/src/mailt/update.c,v retrieving revision 1.3.2.1 retrieving revision 1.3.2.2 diff -u -d -r1.3.2.1 -r1.3.2.2 --- update.c 8 Nov 2004 12:55:34 -0000 1.3.2.1 +++ update.c 2 May 2005 04:44:18 -0000 1.3.2.2 @@ -173,6 +173,7 @@ break; } + m->pad = 0; m->pos = start-mbox; m->hdrlen = p - start; m->bodylen = end - p; |