Mercurial > libpst
changeset 52:034641c26ab9
code cleanup
author | carl |
---|---|
date | Thu, 31 Jan 2008 08:03:30 -0800 |
parents | 06c0262ad689 |
children | c97dabe37115 |
files | ChangeLog configure.in regression/regression-tests.bash src/dumpblocks.c src/getidblock.c src/libpst.c src/libpst.h src/lspst.c src/pst2ldif.cpp src/readpst.c src/readpstlog.c xml/libpst.in |
diffstat | 12 files changed, 381 insertions(+), 337 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Jan 22 14:39:02 2008 -0800 +++ b/ChangeLog Thu Jan 31 08:03:30 2008 -0800 @@ -1,3 +1,11 @@ +LibPST 0.6.6 (2008-01-xx) +=============================== + + * More code cleanup, removing unnecessary null terminations on + binary buffers. All pst file reads now go thru one function. + Logging all pst reads to detect cases where we read the same data + multiple times - discovers node sizes are actually 512 bytes. + LibPST 0.6.5 (2008-01-22) ===============================
--- a/configure.in Tue Jan 22 14:39:02 2008 -0800 +++ b/configure.in Thu Jan 31 08:03:30 2008 -0800 @@ -1,7 +1,7 @@ AC_INIT(configure.in) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(libpst,0.6.5) +AM_INIT_AUTOMAKE(libpst,0.6.6) AC_PATH_PROGS(BASH, bash) AC_LANG_CPLUSPLUS
--- a/regression/regression-tests.bash Tue Jan 22 14:39:02 2008 -0800 +++ b/regression/regression-tests.bash Thu Jan 31 08:03:30 2008 -0800 @@ -29,5 +29,5 @@ $val ../src/lspst -d dumper ams.pst >out9.err 2>&1 ../src/readpstlog -f I dumper >ams.log -rm -f dumper lspst.debug +rm -f dumper
--- a/src/dumpblocks.c Tue Jan 22 14:39:02 2008 -0800 +++ b/src/dumpblocks.c Thu Jan 31 08:03:30 2008 -0800 @@ -10,7 +10,7 @@ pst_file pstfile; pst_index_ll *ptr; char *outdir=NULL, *file=NULL, *outname=NULL; - unsigned char *buf=NULL; + char *buf=NULL; int c; FILE *fp;
--- a/src/getidblock.c Tue Jan 22 14:39:02 2008 -0800 +++ b/src/getidblock.c Thu Jan 31 08:03:30 2008 -0800 @@ -21,7 +21,7 @@ pst_file pstfile; unsigned int id; int decrypt = 0, process = 0, binary = 0, c; - unsigned char *buf = NULL; + char *buf = NULL; size_t readSize; pst_item *item; pst_desc_ll* ptr;
--- a/src/libpst.c Tue Jan 22 14:39:02 2008 -0800 +++ b/src/libpst.c Thu Jan 31 08:03:30 2008 -0800 @@ -40,21 +40,21 @@ #define INDEX_BACK32 (off_t)0xC0 #define SECOND_POINTER32 (off_t)0xBC #define SECOND_BACK32 (off_t)0xB8 -#define ENC_OFFSET32 (off_t)0x1CD +#define ENC_TYPE32 (off_t)0x1CD #define FILE_SIZE_POINTER64 (off_t)0xB8 #define INDEX_POINTER64 (off_t)0xF0 #define INDEX_BACK64 (off_t)0xE8 #define SECOND_POINTER64 (off_t)0xE0 #define SECOND_BACK64 (off_t)0xD8 -#define ENC_OFFSET64 (off_t)0x201 +#define ENC_TYPE64 (off_t)0x201 #define FILE_SIZE_POINTER ((pf->do_read64) ? FILE_SIZE_POINTER64 : FILE_SIZE_POINTER32) #define INDEX_POINTER ((pf->do_read64) ? INDEX_POINTER64 : INDEX_POINTER32) #define INDEX_BACK ((pf->do_read64) ? INDEX_BACK64 : INDEX_BACK32) #define SECOND_POINTER ((pf->do_read64) ? SECOND_POINTER64 : SECOND_POINTER32) #define SECOND_BACK ((pf->do_read64) ? SECOND_BACK64 : SECOND_BACK32) -#define ENC_OFFSET ((pf->do_read64) ? ENC_OFFSET64 : ENC_OFFSET32) +#define ENC_TYPE ((pf->do_read64) ? ENC_TYPE64 : ENC_TYPE32) #define PST_SIGNATURE 0x4E444221 @@ -176,7 +176,7 @@ } // Check pst file magic - if (fread(&sig, sizeof(sig), (size_t)1, pf->fp) == 0) { + if (pst_getAtPos(pf, 0, &sig, sizeof(sig)) != sizeof(sig)) { (void)fclose(pf->fp); WARN(("cannot read signature from PST file. Closing on error\n")); DEBUG_RET(); @@ -192,7 +192,7 @@ } // read index type - (void)pst_getAtPos(pf->fp, INDEX_TYPE_OFFSET, &(pf->ind_type), sizeof(pf->ind_type)); + (void)pst_getAtPos(pf, INDEX_TYPE_OFFSET, &(pf->ind_type), sizeof(pf->ind_type)); DEBUG_INFO(("index_type = %i\n", pf->ind_type)); switch (pf->ind_type) { case INDEX_TYPE32 : @@ -208,7 +208,7 @@ } // read encryption setting - (void)pst_getAtPos(pf->fp, ENC_OFFSET, &(pf->encryption), sizeof(pf->encryption)); + (void)pst_getAtPos(pf, ENC_TYPE, &(pf->encryption), sizeof(pf->encryption)); DEBUG_INFO(("encrypt = %i\n", pf->encryption)); pf->index2_back = pst_getIntAtPos(pf, SECOND_BACK); @@ -264,7 +264,7 @@ } -size_t pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, unsigned char **b){ +size_t pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, char **b){ size_t size=0; pst_index_ll *ptr; pst_holder h = {b, NULL, 0, "", 0}; @@ -395,14 +395,15 @@ pst_desc_ll *p; pst_num_array *na; pst_index2_ll *id2_head = NULL; - unsigned char *buffer=NULL, *headerbuffer=NULL; + char *buffer=NULL, *headerbuffer=NULL; size_t bsize=0, hsize=0, bptr=0; pst_x_attrib xattrib; int32_t tint, err=0, x; pst_x_attrib_ll *ptr, *p_head=NULL, *p_sh=NULL, *p_sh2=NULL; DEBUG_ENT("pst_loadExtendedAttributes"); - if ((p = pst_getDptr(pf, (uint64_t)0x61)) == NULL) { + p = pst_getDptr(pf, (uint64_t)0x61); + if (!p) { DEBUG_WARN(("Cannot find DescID 0x61 for loading the Extended Attributes\n")); DEBUG_RET(); return 0; @@ -527,8 +528,7 @@ return 1; } -#define BLOCK_SIZE32 516 // index blocks -#define DESC_BLOCK_SIZE32 516 // descriptor blocks + #define ITEM_COUNT_OFFSET32 0x1f0 // count byte #define LEVEL_INDICATOR_OFFSET32 0x1f3 // node or leaf #define BACKLINK_OFFSET32 0x1f8 // backlink u1 value @@ -537,8 +537,6 @@ #define INDEX_COUNT_MAX32 41 // max active items #define DESC_COUNT_MAX32 31 // max active items -#define BLOCK_SIZE64 512 // index blocks -#define DESC_BLOCK_SIZE64 512 // descriptor blocks #define ITEM_COUNT_OFFSET64 0x1e8 // count byte #define LEVEL_INDICATOR_OFFSET64 0x1eb // node or leaf #define BACKLINK_OFFSET64 0x1f8 // backlink u1 value @@ -547,8 +545,8 @@ #define INDEX_COUNT_MAX64 20 // max active items #define DESC_COUNT_MAX64 15 // max active items -#define BLOCK_SIZE (size_t)((pf->do_read64) ? BLOCK_SIZE64 : BLOCK_SIZE32) -#define DESC_BLOCK_SIZE (size_t)((pf->do_read64) ? DESC_BLOCK_SIZE64 : DESC_BLOCK_SIZE32) +#define BLOCK_SIZE 512 // index blocks +#define DESC_BLOCK_SIZE 512 // descriptor blocks #define ITEM_COUNT_OFFSET (size_t)((pf->do_read64) ? ITEM_COUNT_OFFSET64 : ITEM_COUNT_OFFSET32) #define LEVEL_INDICATOR_OFFSET (size_t)((pf->do_read64) ? LEVEL_INDICATOR_OFFSET64 : LEVEL_INDICATOR_OFFSET32) #define BACKLINK_OFFSET (size_t)((pf->do_read64) ? BACKLINK_OFFSET64 : BACKLINK_OFFSET32) @@ -1296,8 +1294,8 @@ pst_num_array * pst_parse_block(pst_file *pf, uint64_t block_id, pst_index2_ll *i2_head, pst_num_array *na_head) { - unsigned char *buf = NULL; - size_t read_size = 0; + char *buf = NULL; + size_t read_size = 0; pst_subblocks subblocks; pst_num_array *na_ptr = NULL; pst_block_offset_pointer block_offset1; @@ -4005,7 +4003,7 @@ } -int pst_getBlockOffset(unsigned char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p) { +int pst_getBlockOffset(char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p) { uint32_t low = offset & 0xf; uint32_t of1 = offset >> 4; DEBUG_ENT("pst_getBlockOffset"); @@ -4021,6 +4019,7 @@ DEBUG_WARN(("get block offset finds from=%i(%#x), to=%i(%#x)\n", p->from, p->from, p->to, p->to)); if (p->from > p->to) { DEBUG_WARN(("get block offset from > to")); + DEBUG_RET(); return 0; } DEBUG_RET(); @@ -4054,8 +4053,7 @@ pst_index_ll * pst_getID2(pst_index2_ll *ptr, uint64_t id) { DEBUG_ENT("pst_getID2"); - DEBUG_INDEX(("Head = %p\n", ptr)); - DEBUG_INDEX(("Trying to find %#x\n", id)); + DEBUG_INDEX(("Head = %p id = %#llx\n", ptr, id)); while (ptr && (ptr->id2 != id)) { ptr = ptr->next; } @@ -4133,24 +4131,29 @@ } +/** + * Read a block of data from file into memory + * @param pf PST file + * @param offset offset in the pst file of the data + * @param size size of the block to be read + * @param buf reference to pointer to buffer. If this pointer + is non-NULL, it will first be free()d + * @return size of block read into memory + */ size_t pst_read_block_size(pst_file *pf, off_t offset, size_t size, char **buf) { - off_t fpos; size_t rsize; - DEBUG_ENT("pst_read_block_size"); DEBUG_READ(("Reading block from %#x, %i bytes\n", offset, size)); - fpos = ftell(pf->fp); - (void)fseek(pf->fp, offset, SEEK_SET); if (*buf) { DEBUG_READ(("Freeing old memory\n")); free(*buf); } - - *buf = (void*) xmalloc(size); - rsize = fread(*buf, (size_t)1, size, pf->fp); + *buf = (char*) xmalloc(size); + + rsize = pst_getAtPos(pf, offset, *buf, size); if (rsize != size) { - DEBUG_WARN(("Didn't read all that I could. fread returned less [%i instead of %i]\n", rsize, size)); + DEBUG_WARN(("Didn't read all the data. fread returned less [%i instead of %i]\n", rsize, size)); if (feof(pf->fp)) { DEBUG_WARN(("We tried to read past the end of the file at [offset %#x, size %#x]\n", offset, size)); } else if (ferror(pf->fp)) { @@ -4158,12 +4161,10 @@ } else { DEBUG_WARN(("I can't tell why it failed\n")); } - size = rsize; } - (void)fseek(pf->fp, fpos, SEEK_SET); DEBUG_RET(); - return size; + return rsize; } @@ -4214,51 +4215,81 @@ uint64_t buf64; uint32_t buf32; if (pf->do_read64) { - (void)pst_getAtPos(pf->fp, pos, &buf64, sizeof(buf64)); + (void)pst_getAtPos(pf, pos, &buf64, sizeof(buf64)); LE64_CPU(buf64); return buf64; } else { - (void)pst_getAtPos(pf->fp, pos, &buf32, sizeof(buf32)); + (void)pst_getAtPos(pf, pos, &buf32, sizeof(buf32)); LE32_CPU(buf32); return buf32; } } - -int pst_getAtPos(FILE *fp, off_t pos, void* buf, size_t size) { +/** + * Read part of the pst file. + * + * @param pf PST file structure + * @param pos offset of the data in the pst file + * @param buf buffer to contain the data + * @param size size of the buffer and the amount of data to be read + * @return actual read size, 0 if seek error + */ + +size_t pst_getAtPos(pst_file *pf, off_t pos, void* buf, size_t size) { + size_t rc; DEBUG_ENT("pst_getAtPos"); - if (fseek(fp, pos, SEEK_SET) == -1) { +// pst_block_recorder **t = &pf->block_head; +// pst_block_recorder *p = pf->block_head; +// while (p && ((p->offset+p->size) <= pos)) { +// t = &p->next; +// p = p->next; +// } +// if (p && (p->offset <= pos) && (pos < (p->offset+p->size))) { +// // bump the count +// p->readcount++; +// } else { +// // add a new block +// pst_block_recorder *tail = *t; +// p = (pst_block_recorder*)xmalloc(sizeof(*p)); +// *t = p; +// p->next = tail; +// p->offset = pos; +// p->size = size; +// p->readcount = 1; +// } +// DEBUG_MAIN(("pst file old offset %#llx old size %#x read count %i offset %#llx size %#x\n", +// p->offset, p->size, p->readcount, pos, size)); + + if (fseek(pf->fp, pos, SEEK_SET) == -1) { DEBUG_RET(); - return 1; + return 0; } - if (fread(buf, (size_t)1, size, fp) < size) { - DEBUG_RET(); - return 2; - } + rc = fread(buf, (size_t)1, size, pf->fp); DEBUG_RET(); - return 0; + return rc; } /** * Get an ID block from file using _pst_ff_getIDblock and decrypt if necessary - * @param pf PST file structure - * @param id ID of block to retrieve - * @param b Reference to pointer that will be set to new block. Any memory - pointed to by buffer will be free()d beforehand - * @return Size of block pointed to by *b + * + * @param pf PST file structure + * @param id ID of block to retrieve + * @param buf Reference to pointer that will be set to new block. Any memory + pointed to by buffer will be free()d beforehand + * @return Size of block pointed to by *b */ -size_t pst_ff_getIDblock_dec(pst_file *pf, uint64_t id, unsigned char **b) { +size_t pst_ff_getIDblock_dec(pst_file *pf, uint64_t id, char **buf) { size_t r; int noenc = (int)(id & 2); // disable encryption DEBUG_ENT("pst_ff_getIDblock_dec"); DEBUG_INDEX(("for id %#x\n", id)); - r = pst_ff_getIDblock(pf, id, b); + r = pst_ff_getIDblock(pf, id, buf); if ((pf->encryption) && !(noenc)) { - (void)pst_decrypt(*b, r, pf->encryption); + (void)pst_decrypt(*buf, r, pf->encryption); } - DEBUG_HEXDUMPC(*b, r, 16); + DEBUG_HEXDUMPC(*buf, r, 16); DEBUG_RET(); return r; } @@ -4266,47 +4297,31 @@ /** * Read a block of data from file into memory - * @param pf PST file - * @param id identifier of block to read - * @param b reference to pointer to buffer. If this pointer - is non-NULL, it will first be free()d - * @return size of block read into memory + * @param pf PST file + * @param id identifier of block to read + * @param buf reference to pointer to buffer. If this pointer + is non-NULL, it will first be free()d + * @return size of block read into memory */ -size_t pst_ff_getIDblock(pst_file *pf, uint64_t id, unsigned char** b) { +size_t pst_ff_getIDblock(pst_file *pf, uint64_t id, char** buf) { pst_index_ll *rec; - size_t rsize = 0; + size_t rsize; DEBUG_ENT("pst_ff_getIDblock"); - if ((rec = pst_getID(pf, id)) == NULL) { + rec = pst_getID(pf, id); + if (!rec) { DEBUG_INDEX(("Cannot find ID %#llx\n", id)); DEBUG_RET(); return 0; } - (void)fseek(pf->fp, rec->offset, SEEK_SET); - if (*b) { - DEBUG_INDEX(("freeing old memory in b\n")); - free(*b); - } - DEBUG_INDEX(("id = %#llx, record size = %#x, offset = %#x\n", id, rec->size, rec->offset)); - *b = (char*) xmalloc(rec->size+1); - rsize = fread(*b, (size_t)1, rec->size, pf->fp); - if (rsize != rec->size) { - DEBUG_WARN(("Didn't read all the size. fread returned less [%i instead of %i]\n", rsize, rec->size)); - if (feof(pf->fp)) { - DEBUG_WARN(("We tried to read past the end of the file [offset %#x, size %#x]\n", rec->offset, rec->size)); - } else if (ferror(pf->fp)) { - DEBUG_WARN(("Some error occured on the file stream\n")); - } else { - DEBUG_WARN(("No error has been set on the file stream\n")); - } - } + rsize = pst_read_block_size(pf, rec->offset, rec->size, buf); DEBUG_RET(); return rsize; } #define PST_PTR_BLOCK_SIZE 0x120 -size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_index2_ll *id2_head, unsigned char** buf) { +size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_index2_ll *id2_head, char** buf) { size_t ret; pst_index_ll* ptr; pst_holder h = {buf, NULL, 0, "", 0}; @@ -4326,7 +4341,7 @@ size_t pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, pst_holder *h) { size_t ret; - unsigned char *b = NULL, *t; + char *b = NULL, *t; DEBUG_ENT("pst_ff_getID2data"); if (!(ptr->id & 0x02)) { ret = pst_ff_getIDblock_dec(pf, ptr->id, &b); @@ -4351,8 +4366,8 @@ DEBUG_READ(("Assuming it is a multi-block record because of it's id\n")); ret = pst_ff_compile_ID(pf, ptr->id, h, (size_t)0); } - if (h->buf && *h->buf) - (*(h->buf))[ret]='\0'; + // bogus null termination off the end of the buffer!! + //if (h->buf && *h->buf) (*(h->buf))[ret]='\0'; DEBUG_RET(); return ret; } @@ -4361,8 +4376,8 @@ size_t pst_ff_compile_ID(pst_file *pf, uint64_t id, pst_holder *h, size_t size) { size_t z, a, b; uint16_t count, y; - unsigned char * buf3 = NULL, *buf2 = NULL, *t; - unsigned char *b_ptr; + char * buf3 = NULL, *buf2 = NULL, *t; + char *b_ptr; pst_block_hdr block_hdr; pst_table3_rec table3_rec; //for type 3 (0x0101) blocks @@ -4370,6 +4385,7 @@ a = pst_ff_getIDblock(pf, id, &buf3); if (!a) { if (buf3) free(buf3); + DEBUG_RET(); return 0; } DEBUG_HEXDUMPC(buf3, a, 0x10); @@ -4409,6 +4425,7 @@ DEBUG_WARN(("call to getIDblock returned zero %i\n", z)); if (buf2) free(buf2); free(buf3); + DEBUG_RET(); return z; } if (h->buf) {
--- a/src/libpst.h Tue Jan 22 14:39:02 2008 -0800 +++ b/src/libpst.h Thu Jan 31 08:03:30 2008 -0800 @@ -480,11 +480,19 @@ } pst_x_attrib_ll; +typedef struct pst_block_recorder { + struct pst_block_recorder *next; + off_t offset; + size_t size; + int readcount; +} pst_block_recorder; + + typedef struct pst_file { pst_index_ll *i_head, *i_tail; - pst_index2_ll *i2_head; - pst_desc_ll *d_head, *d_tail; + pst_desc_ll *d_head, *d_tail; pst_x_attrib_ll *x_head; + pst_block_recorder *block_head; //set this to 0 to read 32-bit pst files (pre Outlook 2003) //set this to 1 to read 64-bit pst files (Outlook 2003 and later) @@ -508,18 +516,18 @@ typedef struct pst_block_offset_pointer { - unsigned char *from; - unsigned char *to; - int needfree; + char *from; + char *to; + int needfree; } pst_block_offset_pointer; typedef struct pst_num_item { - uint32_t id; // not an id1 or id2, this is actually some sort of type code - unsigned char *data; - uint32_t type; - size_t size; - char *extra; + uint32_t id; // not an id1 or id2, this is actually some sort of type code + char *data; + uint32_t type; + size_t size; + char *extra; } pst_num_item; @@ -533,7 +541,7 @@ typedef struct pst_holder { - unsigned char **buf; + char **buf; FILE * fp; int base64; char base64_extra_chars[3]; @@ -542,9 +550,9 @@ typedef struct pst_subblock { - unsigned char *buf; - size_t read_size; - size_t i_offset; + char *buf; + size_t read_size; + size_t i_offset; } pst_subblock; @@ -558,7 +566,7 @@ int pst_open(pst_file *pf, char *name, char *mode); int pst_close(pst_file *pf); pst_desc_ll * pst_getTopOfFolders(pst_file *pf, pst_item *root); -size_t pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, unsigned char **b); +size_t pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, char **b); size_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp); size_t pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp); int pst_load_index (pst_file *pf); @@ -578,7 +586,7 @@ void pst_free_desc (pst_desc_ll *head); void pst_free_xattrib(pst_x_attrib_ll *x); int pst_getBlockOffsetPointer(pst_file *pf, pst_index2_ll *i2_head, pst_subblocks *subblocks, uint32_t offset, pst_block_offset_pointer *p); -int pst_getBlockOffset(unsigned char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p); +int pst_getBlockOffset(char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p); pst_index2_ll* pst_build_id2(pst_file *pf, pst_index_ll* list, pst_index2_ll* head_ptr); pst_index_ll* pst_getID(pst_file* pf, uint64_t id); pst_index_ll* pst_getID2(pst_index2_ll * ptr, uint64_t id); @@ -587,10 +595,10 @@ int pst_decrypt(unsigned char *buf, size_t size, unsigned char type); uint64_t pst_getIntAt(pst_file *pf, char *buf); uint64_t pst_getIntAtPos(pst_file *pf, off_t pos); -int pst_getAtPos(FILE *fp, off_t pos, void* buf, size_t size); -size_t pst_ff_getIDblock_dec(pst_file *pf, uint64_t id, unsigned char **b); -size_t pst_ff_getIDblock(pst_file *pf, uint64_t id, unsigned char** b); -size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_index2_ll *id2_head, unsigned char** buf); +size_t pst_getAtPos(pst_file *pf, off_t pos, void* buf, size_t size); +size_t pst_ff_getIDblock_dec(pst_file *pf, uint64_t id, char **b); +size_t pst_ff_getIDblock(pst_file *pf, uint64_t id, char** b); +size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_index2_ll *id2_head, char** buf); size_t pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, pst_holder *h); size_t pst_ff_compile_ID(pst_file *pf, uint64_t id, pst_holder *h, size_t size);
--- a/src/lspst.c Tue Jan 22 14:39:02 2008 -0800 +++ b/src/lspst.c Thu Jan 31 08:03:30 2008 -0800 @@ -145,6 +145,7 @@ } } close_enter_dir(&ff); + DEBUG_RET(); }
--- a/src/pst2ldif.cpp Tue Jan 22 14:39:02 2008 -0800 +++ b/src/pst2ldif.cpp Thu Jan 31 08:03:30 2008 -0800 @@ -147,7 +147,7 @@ pst_item *item = NULL; while (d_ptr) { if (d_ptr->desc) { - item = (pst_item*)pst_parse_item(&pstfile, d_ptr); + item = pst_parse_item(&pstfile, d_ptr); DEBUG_INFO(("item pointer is %p\n", item)); if (item) { if (item->message_store) {
--- a/src/readpst.c Tue Jan 22 14:39:02 2008 -0800 +++ b/src/readpst.c Thu Jan 31 08:03:30 2008 -0800 @@ -330,6 +330,7 @@ int l=0; if (NULL == (fp = fopen(fname, "rb"))) { fprintf(stderr, "Couldn't open file %s\n", fname ); + DEBUG_RET(); return 1; } @@ -339,9 +340,11 @@ if (l != fwrite( buf, 1, l, stdout)) { fprintf(stderr, "Couldn't output to stdout?\n"); + DEBUG_RET(); return 1; } } + DEBUG_RET(); return 0; } @@ -662,8 +665,10 @@ // my_stristr varies from strstr in that its searches are case-insensitive char *x=haystack, *y=needle, *z = NULL; DEBUG_ENT("my_stristr"); - if (!haystack || !needle) + if (!haystack || !needle) { + DEBUG_RET(); return NULL; + } while (*y != '\0' && *x != '\0') { if (tolower(*y) == tolower(*x)) { // move y on one @@ -687,6 +692,7 @@ DEBUG_ENT("check_filename"); if (!t) { DEBUG_RET(); + return; } while ((t = strpbrk(t, "/\\:"))) { // while there are characters in the second string that we don't want @@ -767,6 +773,7 @@ enc = base64_encode (current_attach->data, current_attach->size); if (!enc) { DEBUG_EMAIL(("ERROR base64_encode returned NULL. Must have failed\n")); + DEBUG_RET(); return; } }
--- a/src/readpstlog.c Tue Jan 22 14:39:02 2008 -0800 +++ b/src/readpstlog.c Thu Jan 31 08:03:30 2008 -0800 @@ -21,219 +21,223 @@ int is_in(int a, int *b, int c); int main(int argc, char** argv) { - int level = 0; + int identity = 0; + int level = 0; off_t *i = NULL; - int x, ptr, stop=0, flag; - char *fname, *buf, rec_type; - unsigned char version; - int *show_type=NULL, show_size=0; - int *ex_type=NULL, ex_size=0; - unsigned int funcname=0, filename=0, text=0, end=0, dtype=0, line=0, c; - FILE *fp; - struct pst_debug_file_rec_m mfile_rec; - struct pst_debug_file_rec_l lfile_rec; - char format = 'D'; // default - while ((c = getopt(argc, argv, "f:t:x:")) != -1) { - switch(c) { - case 'f': - // change the output format - format = toupper(optarg[0]); - break; - case 't': - //change the type of statements shown - show_size = split_args(optarg, &show_type); - // type = atoi(optarg); - break; - case 'x': - // change the type of statements excluded - ex_size = split_args(optarg, &ex_type); - break; - } - } - if (argc > optind) { - fname = argv[optind++]; - } else { - usage(); - exit(2); - } + int x, ptr, stop=0, flag; + char *fname, *buf, rec_type; + unsigned char version; + int *show_type=NULL, show_size=0; + int *ex_type=NULL, ex_size=0; + unsigned int funcname=0, filename=0, text=0, end=0, dtype=0, line=0, c; + FILE *fp; + struct pst_debug_file_rec_m mfile_rec; + struct pst_debug_file_rec_l lfile_rec; + char format = 'D'; // default + while ((c = getopt(argc, argv, "f:t:x:")) != -1) { + switch(c) { + case 'f': + // change the output format + format = toupper(optarg[0]); + break; + case 't': + //change the type of statements shown + show_size = split_args(optarg, &show_type); + // type = atoi(optarg); + break; + case 'x': + // change the type of statements excluded + ex_size = split_args(optarg, &ex_type); + break; + } + } + if (argc > optind) { + fname = argv[optind++]; + } else { + usage(); + exit(2); + } - fp = fopen(fname, "rb"); - if (fp == NULL) { - printf("Error. couldn't open debug file\n"); - return 2; - } - if (get(&version, sizeof(char), 1, fp)==0) { - printf("Error. could not read version byte from front of file"); - return 3; - } + fp = fopen(fname, "rb"); + if (fp == NULL) { + printf("Error. couldn't open debug file\n"); + return 2; + } + if (get(&version, sizeof(char), 1, fp)==0) { + printf("Error. could not read version byte from front of file"); + return 3; + } - if (version > DEBUG_VERSION) { - printf("Version number is higher than the format I know about."); - return 4; - } + if (version > DEBUG_VERSION) { + printf("Version number is higher than the format I know about."); + return 4; + } - buf = (char*) xmalloc(BUF_SIZE); + buf = (char*) xmalloc(BUF_SIZE); - while (!stop) { + while (!stop) { off_t temp; - if (fread(&temp, sizeof(off_t), 1, fp)<=0) break; + if (fread(&temp, sizeof(off_t), 1, fp)<=0) break; x = (int)temp; - ptr = 0; - if (x > 0) { - if (i) free(i); - i = (off_t*)xmalloc(sizeof(off_t)*(x+1)); - // plus 1 cause we want to read the offset of the next index - if (get(i, sizeof(off_t), x+1, fp)==0) { - // we have reached the end of the debug file - printf("oh dear. we must now end\n"); - break; - } - while (ptr < x) { - fseek(fp, i[ptr++], SEEK_SET); - get(&rec_type, 1, sizeof(char), fp); - if (rec_type == 'L') { - get(&lfile_rec, sizeof(lfile_rec), 1, fp); - funcname=lfile_rec.funcname; - filename=lfile_rec.filename; - text = lfile_rec.text; - end = lfile_rec.end; - dtype = lfile_rec.type; - line = lfile_rec.line; - } else if (rec_type == 'M') { - get(&mfile_rec, sizeof(mfile_rec), 1, fp); - funcname = mfile_rec.funcname; - filename = mfile_rec.filename; - text = mfile_rec.text; - end = mfile_rec.end; - dtype = mfile_rec.type; - line = mfile_rec.line; - } - if (dtype == DEBUG_FUNCENT_NO) level++; - if ((show_type == NULL || is_in(dtype, show_type, show_size)) && - (ex_type == NULL || !is_in(dtype, ex_type, ex_size))) { - c = 0; flag = 0; - while (c < end) { - int ii = (level-1) * 4; - if (ii < 0) ii = 0; - if (ii > 64) ii = 64; - char indent[ii+1]; - memset(indent, ' ', ii); - indent[ii] = '\0'; - if (c + (BUF_SIZE-1) < end) { - get(buf, 1, BUF_SIZE-1, fp); - buf[BUF_SIZE-1] = '\0'; - c += BUF_SIZE-1; - } else { - get(buf, 1, end-c, fp); - buf[end-c] = '\0'; - c = end; - } - if (flag == 0) { - if (format == 'I') { // indented text format - char *b = buf+text; - printf("%s %s/%s[%d]: ", indent, &buf[filename], &buf[funcname], line); - while (b) { - char *p = strchr(b, '\n'); - if (p) { - *p = '\0'; - printf("%s\n%s ", b, indent); - b = p + 1; - } - else { - printf("%s", b); - b = NULL; - } - } - } - else if (format == 'T') { // text format - printf("%s/%s[%d]: %s", &buf[filename], &buf[funcname], line, &buf[text]); - } else { - printf("Type: %d\nFile[line]: %s[%d]\nFunction:%s\nText:%s", dtype, - &buf[filename], line, &buf[funcname], &buf[text]); - } - flag = 1; - } else { - if (format == 'I') { - char *b = buf; - while (b) { - char *p = strchr(b, '\n'); - if (p) { - *p = '\0'; - printf("%s\n%s ", b, indent); - b = p + 1; - } - else { - printf("%s", b); - b = NULL; - } - } - } - else printf("%s", buf); - } - } - printf("\n"); - } - if (dtype == DEBUG_FUNCRET_NO) level--; - } - if (fseek(fp, i[ptr], SEEK_SET)==-1) { - printf("finished\n"); - break; - } - } else { - printf("...no more items\n"); - break; - } - } - free(buf); - fclose(fp); - return 0; + ptr = 0; + if (x > 0) { + if (i) free(i); + i = (off_t*)xmalloc(sizeof(off_t)*(x+1)); + // plus 1 cause we want to read the offset of the next index + if (get(i, sizeof(off_t), x+1, fp)==0) { + // we have reached the end of the debug file + printf("oh dear. we must now end\n"); + break; + } + while (ptr < x) { + fseek(fp, i[ptr++], SEEK_SET); + get(&rec_type, 1, sizeof(char), fp); + if (rec_type == 'L') { + get(&lfile_rec, sizeof(lfile_rec), 1, fp); + funcname=lfile_rec.funcname; + filename=lfile_rec.filename; + text = lfile_rec.text; + end = lfile_rec.end; + dtype = lfile_rec.type; + line = lfile_rec.line; + } else if (rec_type == 'M') { + get(&mfile_rec, sizeof(mfile_rec), 1, fp); + funcname = mfile_rec.funcname; + filename = mfile_rec.filename; + text = mfile_rec.text; + end = mfile_rec.end; + dtype = mfile_rec.type; + line = mfile_rec.line; + } + if (dtype == DEBUG_FUNCENT_NO) level++; + if ((show_type == NULL || is_in(dtype, show_type, show_size)) && + (ex_type == NULL || !is_in(dtype, ex_type, ex_size))) { + c = 0; flag = 0; + while (c < end) { + int ii = (level-1) * 4; + if (ii < 0) ii = 0; + if (ii > 64) ii = 64; + char indent[ii+1]; + memset(indent, ' ', ii); + indent[ii] = '\0'; + if (c + (BUF_SIZE-1) < end) { + get(buf, 1, BUF_SIZE-1, fp); + buf[BUF_SIZE-1] = '\0'; + c += BUF_SIZE-1; + } else { + get(buf, 1, end-c, fp); + buf[end-c] = '\0'; + c = end; + } + if (flag == 0) { + if (format == 'I') { // indented text format + char *b = buf+text; + identity++; + //printf("%s %d %s/%s[%d]: ", indent, identity, &buf[filename], &buf[funcname], line); + printf("%s %s/%s[%d]: ", indent, &buf[filename], &buf[funcname], line); + while (b) { + char *p = strchr(b, '\n'); + if (p) { + *p = '\0'; + printf("%s\n%s ", b, indent); + b = p + 1; + } + else { + printf("%s", b); + b = NULL; + } + } + } + else if (format == 'T') { // text format + printf("%s/%s[%d]: %s", &buf[filename], &buf[funcname], line, &buf[text]); + } else { + printf("Type: %d\nFile[line]: %s[%d]\nFunction:%s\nText:%s", dtype, + &buf[filename], line, &buf[funcname], &buf[text]); + } + flag = 1; + } else { + if (format == 'I') { + char *b = buf; + while (b) { + char *p = strchr(b, '\n'); + if (p) { + *p = '\0'; + printf("%s\n%s ", b, indent); + b = p + 1; + } + else { + printf("%s", b); + b = NULL; + } + } + } + else printf("%s", buf); + } + } + printf("\n"); + } + if (dtype == DEBUG_FUNCRET_NO) level--; + } + if (fseek(fp, i[ptr], SEEK_SET)==-1) { + printf("finished\n"); + break; + } + } else { + printf("...no more items\n"); + break; + } + } + free(buf); + fclose(fp); + if (format == 'I') printf("final indent level = %i\n", level); + return 0; } size_t get(void *buf, int size, unsigned int count, FILE *fp) { - size_t z; - if ((z=fread(buf, size, count, fp)) < count) { - printf("Read Failed! (size=%d, count=%d,z=%ld)\n", size, count, (long)z); - exit(1); - } - return z; + size_t z; + if ((z=fread(buf, size, count, fp)) < count) { + printf("Read Failed! (size=%d, count=%d,z=%ld)\n", size, count, (long)z); + exit(1); + } + return z; } int usage() { - printf("readlog -t[show_type] -x[exclude_type] -f[format] filename\n"); - printf("\tformat:\n\t\tt: text log format\n"); - printf("\t\ti: indented text log format\n"); - printf("\tshow_type:\n\t\tcomma separated list of types to show " - "[ie, 2,4,1,6]\n"); - printf("\texclude_type:\n\t\tcomma separated list of types to exclude " - "[ie, 1,5,3,7]\n"); - return 0; + printf("readlog -t[show_type] -x[exclude_type] -f[format] filename\n"); + printf("\tformat:\n\t\tt: text log format\n"); + printf("\t\ti: indented text log format\n"); + printf("\tshow_type:\n\t\tcomma separated list of types to show " + "[ie, 2,4,1,6]\n"); + printf("\texclude_type:\n\t\tcomma separated list of types to exclude " + "[ie, 1,5,3,7]\n"); + return 0; } int split_args(char *args, int **targ) { - int count = 1, *i, x, z; - char *tmp = args, *y; - if (*targ != NULL) { - free(*targ); - } - // find the number of tokens in the string. Starting - // from 1 cause there will always be one - while ((tmp = strchr(tmp, ',')) != NULL) { - tmp++; count++; - } - *targ = (int*)xmalloc(count * sizeof(int)); - i = *targ; // for convienience - tmp = args; - z = 0; - for (x = 0; x < count; x++) { - y = strtok(tmp, ","); - tmp = NULL; // must be done after first call - if (y != NULL) { - i[x] = atoi(y); - z++; - } - } - return z; + int count = 1, *i, x, z; + char *tmp = args, *y; + if (*targ != NULL) { + free(*targ); + } + // find the number of tokens in the string. Starting + // from 1 cause there will always be one + while ((tmp = strchr(tmp, ',')) != NULL) { + tmp++; count++; + } + *targ = (int*)xmalloc(count * sizeof(int)); + i = *targ; // for convienience + tmp = args; + z = 0; + for (x = 0; x < count; x++) { + y = strtok(tmp, ","); + tmp = NULL; // must be done after first call + if (y != NULL) { + i[x] = atoi(y); + z++; + } + } + return z; } @@ -241,13 +245,13 @@ // the size of which is specified with the third arg. If the second // arg is NULL, then it is obvious that it is not there. int is_in(int a, int *b, int c){ - int d = 0; - if (b == NULL || c == 0) { // no array or no items in array - return 0; - } - while (d < c) { - if (a == b[d]) return 1; - d++; - } - return 0; + int d = 0; + if (b == NULL || c == 0) { // no array or no items in array + return 0; + } + while (d < c) { + if (a == b[d]) return 1; + d++; + } + return 0; }
--- a/xml/libpst.in Tue Jan 22 14:39:02 2008 -0800 +++ b/xml/libpst.in Thu Jan 31 08:03:30 2008 -0800 @@ -23,7 +23,7 @@ <refentry id="readpst.1"> <refentryinfo> - <date>2008-01-19</date> + <date>2008-01-27</date> </refentryinfo> <refmeta> @@ -206,9 +206,9 @@ </refsect1> <refsect1 id='readpst.version.1'> - <title>CVS Version</title> + <title>Version</title> <para> - $Id$ + @VERSION@ </para> </refsect1> </refentry> @@ -216,7 +216,7 @@ <refentry id="lspst.1"> <refentryinfo> - <date>2008-01-19</date> + <date>2008-01-27</date> </refentryinfo> <refmeta> @@ -309,9 +309,9 @@ </refsect1> <refsect1 id='lspst.version.1'> - <title>CVS Version</title> + <title>Version</title> <para> - $Id$ + @VERSION@ </para> </refsect1> </refentry> @@ -319,7 +319,7 @@ <refentry id="readpstlog.1"> <refentryinfo> - <date>2008-01-19</date> + <date>2008-01-27</date> </refentryinfo> <refmeta> @@ -484,9 +484,9 @@ </refsect1> <refsect1 id='readpstlog.version.1'> - <title>CVS Version</title> + <title>Version</title> <para> - $Id$ + @VERSION@ </para> </refsect1> </refentry> @@ -494,7 +494,7 @@ <refentry id="pst2ldif.1"> <refentryinfo> - <date>2008-01-19</date> + <date>2008-01-27</date> </refentryinfo> <refmeta> @@ -608,9 +608,9 @@ </refsect1> <refsect1 id='pst2ldif.version.1'> - <title>CVS Version</title> + <title>Version</title> <para> - $Id$ + @VERSION@ </para> </refsect1> </refentry> @@ -618,7 +618,7 @@ <refentry id="pst.5"> <refentryinfo> - <date>2008-01-19</date> + <date>2008-01-27</date> </refentryinfo> <refmeta> @@ -772,7 +772,7 @@ <refsect1 id='pst.file.node1.32.5'> <title>32 bit Index 1 Node</title> <para> - The 32 bit index1 b-tree nodes are 516 byte blocks with the + The 32 bit index1 b-tree nodes are 512 byte blocks with the following format. </para> <literallayout class="monospaced"><![CDATA[ @@ -818,7 +818,7 @@ 01d4 00 00 00 00 00 00 00 00 00 00 00 00 01e0 00 00 00 00 00 00 00 00 00 00 00 00 01ec 00 00 00 00 02 29 0c 02 80 80 b6 4a -01f8 b4 1e 02 00 27 9c cc 56 58 27 03 00 +01f8 b4 1e 02 00 27 9c cc 56 01f0 itemCount [1 byte] 0x02 in this case 01f1 maxItemCount [1 byte] 0x29 constant @@ -912,7 +912,7 @@ <refsect1 id='pst.file.leaf1.32.5'> <title>32 bit Index 1 Leaf Node</title> <para> - The 32 bit index1 b-tree leaf nodes are 516 byte blocks with the + The 32 bit index1 b-tree leaf nodes are 512 byte blocks with the following format. </para> <literallayout class="monospaced"><![CDATA[ @@ -958,7 +958,7 @@ 01d4 64 02 00 00 80 fb 00 00 bf 07 02 00 01e0 64 02 00 00 80 fb 00 00 bf 07 02 00 01ec 00 00 00 00 1f 29 0c 00 80 80 5b b3 -01f8 5a 67 01 00 4f ae 70 a7 92 06 00 00 +01f8 5a 67 01 00 4f ae 70 a7 01f0 itemCount [1 byte] 0x1f in this case 01f1 maxItemCount [1 byte] 0x29 constant @@ -1058,7 +1058,7 @@ <refsect1 id='pst.file.node2.32.5'> <title>32 bit Index 2 Node</title> <para> - The 32 bit index2 b-tree nodes are 516 byte blocks with the + The 32 bit index2 b-tree nodes are 512 byte blocks with the following format. </para> <literallayout class="monospaced"><![CDATA[ @@ -1104,7 +1104,7 @@ 01d4 00 00 00 00 00 00 00 00 00 00 00 00 01e0 00 00 00 00 00 00 00 00 00 00 00 00 01ec 00 00 00 00 02 29 0c 02 81 81 b2 60 -01f8 bc 1e 02 00 7e 70 dc e3 21 00 00 00 +01f8 bc 1e 02 00 7e 70 dc e3 01f0 itemCount [1 byte] 0x02 in this case 01f1 maxItemCount [1 byte] 0x29 constant @@ -1198,7 +1198,7 @@ <refsect1 id='pst.file.leaf2.32.5'> <title>32 bit Index 2 Leaf Node</title> <para> - The 32 bit index2 b-tree leaf nodes are 516 byte blocks with the + The 32 bit index2 b-tree leaf nodes are 512 byte blocks with the following format. </para> <literallayout class="monospaced"><![CDATA[ @@ -1234,7 +1234,6 @@ 01D0 6d 80 00 00 34 78 02 00 00 00 00 00 00 00 00 00 01E0 6e 80 00 00 08 00 00 00 00 00 00 00 00 00 00 00 01F0 10 1f 10 00 81 81 a0 9a ae 1e 02 00 89 44 6a 0f -0200 b8 b1 03 00 01f0 itemCount [1 byte] 0x10 in this case 01f1 maxItemCount [1 byte] 0x1f constant @@ -1515,8 +1514,8 @@ 0078 Second Recipient Address 007d Email Header. This is the header that was attached to the email 0c17 Reply Requested -0c19 Second sender struct -0c1a Name of second sender struct +0c19 Second sender structure +0c1a Name of second sender structure 0c1d Second outlook name of sender 0c1e Second sender access method (SMTP, EX) 0c1f Second Sender Address