comparison src/libpst.c @ 204:268458c79e9b

more cleanup of the shared library interface, but still not fully thread safe
author Carl Byington <carl@five-ten-sg.com>
date Sat, 06 Jun 2009 11:39:02 -0700
parents 9fb600ef4e03
children 94bde95d7e18
comparison
equal deleted inserted replaced
203:9fb600ef4e03 204:268458c79e9b
255 static int pst_build_desc_ptr(pst_file *pf, int64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val); 255 static int pst_build_desc_ptr(pst_file *pf, int64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val);
256 static pst_id2_tree* pst_build_id2(pst_file *pf, pst_index_ll* list); 256 static pst_id2_tree* pst_build_id2(pst_file *pf, pst_index_ll* list);
257 static int pst_build_id_ptr(pst_file *pf, int64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val); 257 static int pst_build_id_ptr(pst_file *pf, int64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val);
258 static int pst_chr_count(char *str, char x); 258 static int pst_chr_count(char *str, char x);
259 static size_t pst_ff_compile_ID(pst_file *pf, uint64_t i_id, pst_holder *h, size_t size); 259 static size_t pst_ff_compile_ID(pst_file *pf, uint64_t i_id, pst_holder *h, size_t size);
260 static size_t pst_ff_getIDblock(pst_file *pf, uint64_t i_id, char** buf);
260 static size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_id2_tree *id2_head, char** buf); 261 static size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_id2_tree *id2_head, char** buf);
261 static size_t pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, pst_holder *h); 262 static size_t pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, pst_holder *h);
262 static void pst_free_attach(pst_item_attach *attach); 263 static void pst_free_attach(pst_item_attach *attach);
263 static void pst_free_desc (pst_desc_tree *head); 264 static void pst_free_desc (pst_desc_tree *head);
264 static void pst_free_id2(pst_id2_tree * head); 265 static void pst_free_id2(pst_id2_tree * head);
276 static void pst_printDptr(pst_file *pf, pst_desc_tree *ptr); 277 static void pst_printDptr(pst_file *pf, pst_desc_tree *ptr);
277 static void pst_printIDptr(pst_file* pf); 278 static void pst_printIDptr(pst_file* pf);
278 static void pst_printID2ptr(pst_id2_tree *ptr); 279 static void pst_printID2ptr(pst_id2_tree *ptr);
279 static int pst_process(pst_mapi_object *list, pst_item *item, pst_item_attach *attach); 280 static int pst_process(pst_mapi_object *list, pst_item *item, pst_item_attach *attach);
280 static size_t pst_read_block_size(pst_file *pf, int64_t offset, size_t size, char **buf); 281 static size_t pst_read_block_size(pst_file *pf, int64_t offset, size_t size, char **buf);
282 static int pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type);
281 static int pst_stricmp(char *a, char *b); 283 static int pst_stricmp(char *a, char *b);
282 static int pst_strincmp(char *a, char *b, size_t x); 284 static int pst_strincmp(char *a, char *b, size_t x);
283 static char* pst_wide_to_single(char *wt, size_t size); 285 static char* pst_wide_to_single(char *wt, size_t size);
284 286
285 287
3506 DEBUG_RET(); 3508 DEBUG_RET();
3507 } 3509 }
3508 3510
3509 3511
3510 /** 3512 /**
3511 * The offset might be zero, in which case we have no data, so return a pair of null pointers. 3513 * The offset might be zero, in which case we have no data, so return a pair of null pointers.
3512 * Or, the offset might end in 0xf, so it is an id2 pointer, in which case we read the id2 block. 3514 * Or, the offset might end in 0xf, so it is an id2 pointer, in which case we read the id2 block.
3513 * Otherwise, the high order 16 bits of offset is the index into the subblocks, and 3515 * Otherwise, the high order 16 bits of offset is the index into the subblocks, and
3514 * the (low order 16 bits of offset)>>4 is an index into the table of offsets in the subblock. 3516 * the (low order 16 bits of offset)>>4 is an index into the table of offsets in the subblock.
3515 */ 3517 */
3516 static int pst_getBlockOffsetPointer(pst_file *pf, pst_id2_tree *i2_head, pst_subblocks *subblocks, uint32_t offset, pst_block_offset_pointer *p) { 3518 static int pst_getBlockOffsetPointer(pst_file *pf, pst_id2_tree *i2_head, pst_subblocks *subblocks, uint32_t offset, pst_block_offset_pointer *p) {
3517 size_t size; 3519 size_t size;
3518 pst_block_offset block_offset; 3520 pst_block_offset block_offset;
3519 DEBUG_ENT("pst_getBlockOffsetPointer"); 3521 DEBUG_ENT("pst_getBlockOffsetPointer");
3520 if (p->needfree) free(p->from); 3522 if (p->needfree) free(p->from);
3558 DEBUG_RET(); 3560 DEBUG_RET();
3559 return (p->from) ? 0 : 1; 3561 return (p->from) ? 0 : 1;
3560 } 3562 }
3561 3563
3562 3564
3565 /** */
3563 static int pst_getBlockOffset(char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p) { 3566 static int pst_getBlockOffset(char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p) {
3564 uint32_t low = offset & 0xf; 3567 uint32_t low = offset & 0xf;
3565 uint32_t of1 = offset >> 4; 3568 uint32_t of1 = offset >> 4;
3566 DEBUG_ENT("pst_getBlockOffset"); 3569 DEBUG_ENT("pst_getBlockOffset");
3567 if (!p || !buf || !i_offset || low || (i_offset+2+of1+sizeof(*p) > read_size)) { 3570 if (!p || !buf || !i_offset || low || (i_offset+2+of1+sizeof(*p) > read_size)) {
3582 DEBUG_RET(); 3585 DEBUG_RET();
3583 return 1; 3586 return 1;
3584 } 3587 }
3585 3588
3586 3589
3590 /** */
3587 pst_index_ll* pst_getID(pst_file* pf, uint64_t i_id) { 3591 pst_index_ll* pst_getID(pst_file* pf, uint64_t i_id) {
3588 pst_index_ll *ptr; 3592 pst_index_ll *ptr;
3589 DEBUG_ENT("pst_getID"); 3593 DEBUG_ENT("pst_getID");
3590 if (i_id == 0) { 3594 if (i_id == 0) {
3591 DEBUG_RET(); 3595 DEBUG_RET();
3733 DEBUG_RET(); 3737 DEBUG_RET();
3734 return rsize; 3738 return rsize;
3735 } 3739 }
3736 3740
3737 3741
3738 int pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type) { 3742 /** Decrypt a block of data from the pst file.
3743 * @param i_id identifier of this block, needed as part of the key for the enigma cipher
3744 * @param buf pointer to the buffer to be decrypted in place
3745 * @param size size of the buffer
3746 * @param type
3747 @li 0 PST_NO_ENCRYPT, none
3748 @li 1 PST_COMP_ENCRYPT, simple byte substitution cipher with fixed key
3749 @li 2 PST_ENCRYPT, german enigma 3 rotor cipher with fixed key
3750 * @return 0 if ok, -1 if error (NULL buffer or unknown encryption type)
3751 */
3752 static int pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type) {
3739 size_t x = 0; 3753 size_t x = 0;
3740 unsigned char y; 3754 unsigned char y;
3741 DEBUG_ENT("pst_decrypt"); 3755 DEBUG_ENT("pst_decrypt");
3742 if (!buf) { 3756 if (!buf) {
3743 DEBUG_RET(); 3757 DEBUG_RET();
3887 * @param i_id ID of block to read 3901 * @param i_id ID of block to read
3888 * @param buf reference to pointer to buffer that will contain the data block. 3902 * @param buf reference to pointer to buffer that will contain the data block.
3889 * If this pointer is non-NULL, it will first be free()d. 3903 * If this pointer is non-NULL, it will first be free()d.
3890 * @return size of block read into memory 3904 * @return size of block read into memory
3891 */ 3905 */
3892 size_t pst_ff_getIDblock(pst_file *pf, uint64_t i_id, char** buf) { 3906 static size_t pst_ff_getIDblock(pst_file *pf, uint64_t i_id, char** buf) {
3893 pst_index_ll *rec; 3907 pst_index_ll *rec;
3894 size_t rsize; 3908 size_t rsize;
3895 DEBUG_ENT("pst_ff_getIDblock"); 3909 DEBUG_ENT("pst_ff_getIDblock");
3896 rec = pst_getID(pf, i_id); 3910 rec = pst_getID(pf, i_id);
3897 if (!rec) { 3911 if (!rec) {