Mercurial > libpst
comparison src/libpst.c @ 186:0a4f7ecd7452
more cleanup of external names in the shared library
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Mon, 13 Apr 2009 19:14:30 -0700 |
parents | b65e8d0a088a |
children | d588dafd03e8 |
comparison
equal
deleted
inserted
replaced
185:e0392999e9b8 | 186:0a4f7ecd7452 |
---|---|
167 0xf1, 0x5a, 0xef, 0xcf, 0x90, 0xb6, 0x8b, 0xb5, 0xbd, 0xc0, 0xbf, 0x08, 0x97, 0x1e, 0x6c, 0xe2, | 167 0xf1, 0x5a, 0xef, 0xcf, 0x90, 0xb6, 0x8b, 0xb5, 0xbd, 0xc0, 0xbf, 0x08, 0x97, 0x1e, 0x6c, 0xe2, |
168 0x61, 0xe0, 0xc6, 0xc1, 0x59, 0xab, 0xbb, 0x58, 0xde, 0x5f, 0xdf, 0x60, 0x79, 0x7e, 0xb2, 0x8a | 168 0x61, 0xe0, 0xc6, 0xc1, 0x59, 0xab, 0xbb, 0x58, 0xde, 0x5f, 0xdf, 0x60, 0x79, 0x7e, 0xb2, 0x8a |
169 }; | 169 }; |
170 | 170 |
171 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); | 171 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); |
172 static pst_id2_ll* pst_build_id2(pst_file *pf, pst_index_ll* list); | 172 static pst_id2_tree* pst_build_id2(pst_file *pf, pst_index_ll* list); |
173 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); | 173 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); |
174 static int pst_chr_count(char *str, char x); | 174 static int pst_chr_count(char *str, char x); |
175 static size_t pst_ff_compile_ID(pst_file *pf, uint64_t id, pst_holder *h, size_t size); | 175 static size_t pst_ff_compile_ID(pst_file *pf, uint64_t id, pst_holder *h, size_t size); |
176 static size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_id2_ll *id2_head, char** buf); | 176 static size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_id2_tree *id2_head, char** buf); |
177 static size_t pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, pst_holder *h); | 177 static size_t pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, pst_holder *h); |
178 static void pst_free_attach(pst_item_attach *attach); | 178 static void pst_free_attach(pst_item_attach *attach); |
179 static void pst_free_desc (pst_desc_ll *head); | 179 static void pst_free_desc (pst_desc_tree *head); |
180 static void pst_free_id2(pst_id2_ll * head); | 180 static void pst_free_id2(pst_id2_tree * head); |
181 static void pst_free_id (pst_index_ll *head); | 181 static void pst_free_id (pst_index_ll *head); |
182 static void pst_free_list(pst_mapi_object *list); | 182 static void pst_free_list(pst_mapi_object *list); |
183 static void pst_free_xattrib(pst_x_attrib_ll *x); | 183 static void pst_free_xattrib(pst_x_attrib_ll *x); |
184 static size_t pst_getAtPos(pst_file *pf, int64_t pos, void* buf, size_t size); | 184 static size_t pst_getAtPos(pst_file *pf, int64_t pos, void* buf, size_t size); |
185 static int pst_getBlockOffsetPointer(pst_file *pf, pst_id2_ll *i2_head, pst_subblocks *subblocks, uint32_t offset, pst_block_offset_pointer *p); | 185 static int pst_getBlockOffsetPointer(pst_file *pf, pst_id2_tree *i2_head, pst_subblocks *subblocks, uint32_t offset, pst_block_offset_pointer *p); |
186 static int pst_getBlockOffset(char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p); | 186 static int pst_getBlockOffset(char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p); |
187 static pst_id2_ll* pst_getID2(pst_id2_ll * ptr, uint64_t id); | 187 static pst_id2_tree* pst_getID2(pst_id2_tree * ptr, uint64_t id); |
188 static pst_desc_ll* pst_getDptr(pst_file *pf, uint64_t d_id); | 188 static pst_desc_tree* pst_getDptr(pst_file *pf, uint64_t d_id); |
189 static uint64_t pst_getIntAt(pst_file *pf, char *buf); | 189 static uint64_t pst_getIntAt(pst_file *pf, char *buf); |
190 static uint64_t pst_getIntAtPos(pst_file *pf, int64_t pos); | 190 static uint64_t pst_getIntAtPos(pst_file *pf, int64_t pos); |
191 static pst_mapi_object* pst_parse_block(pst_file *pf, uint64_t block_id, pst_id2_ll *i2_head); | 191 static pst_mapi_object* pst_parse_block(pst_file *pf, uint64_t block_id, pst_id2_tree *i2_head); |
192 static void pst_printDptr(pst_file *pf, pst_desc_ll *ptr); | 192 static void pst_printDptr(pst_file *pf, pst_desc_tree *ptr); |
193 static void pst_printIDptr(pst_file* pf); | 193 static void pst_printIDptr(pst_file* pf); |
194 static void pst_printID2ptr(pst_id2_ll *ptr); | 194 static void pst_printID2ptr(pst_id2_tree *ptr); |
195 static int pst_process(pst_mapi_object *list, pst_item *item, pst_item_attach *attach); | 195 static int pst_process(pst_mapi_object *list, pst_item *item, pst_item_attach *attach); |
196 static size_t pst_read_block_size(pst_file *pf, int64_t offset, size_t size, char **buf); | 196 static size_t pst_read_block_size(pst_file *pf, int64_t offset, size_t size, char **buf); |
197 static int pst_stricmp(char *a, char *b); | 197 static int pst_stricmp(char *a, char *b); |
198 static int pst_strincmp(char *a, char *b, size_t x); | 198 static int pst_strincmp(char *a, char *b, size_t x); |
199 static char* pst_wide_to_single(char *wt, size_t size); | 199 static char* pst_wide_to_single(char *wt, size_t size); |
299 * | 299 * |
300 * @param node pointer to the node to be added to the list | 300 * @param node pointer to the node to be added to the list |
301 * @param head pointer to the list head pointer | 301 * @param head pointer to the list head pointer |
302 * @param tail pointer to the list tail pointer | 302 * @param tail pointer to the list tail pointer |
303 */ | 303 */ |
304 static void add_descriptor_to_list(pst_desc_ll *node, pst_desc_ll **head, pst_desc_ll **tail); | 304 static void add_descriptor_to_list(pst_desc_tree *node, pst_desc_tree **head, pst_desc_tree **tail); |
305 static void add_descriptor_to_list(pst_desc_ll *node, pst_desc_ll **head, pst_desc_ll **tail) | 305 static void add_descriptor_to_list(pst_desc_tree *node, pst_desc_tree **head, pst_desc_tree **tail) |
306 { | 306 { |
307 DEBUG_ENT("add_descriptor_to_list"); | 307 DEBUG_ENT("add_descriptor_to_list"); |
308 //DEBUG_INDEX(("Added node %#"PRIx64" parent %#"PRIx64" real parent %#"PRIx64" prev %#"PRIx64" next %#"PRIx64"\n", | 308 //DEBUG_INDEX(("Added node %#"PRIx64" parent %#"PRIx64" real parent %#"PRIx64" prev %#"PRIx64" next %#"PRIx64"\n", |
309 // node->id, node->parent_d_id, | 309 // node->id, node->parent_d_id, |
310 // (node->parent ? node->parent->id : (uint64_t)0), | 310 // (node->parent ? node->parent->id : (uint64_t)0), |
323 * add a pst descriptor node into the global tree. | 323 * add a pst descriptor node into the global tree. |
324 * | 324 * |
325 * @param pf global pst file pointer | 325 * @param pf global pst file pointer |
326 * @param node pointer to the new node to be added to the tree | 326 * @param node pointer to the new node to be added to the tree |
327 */ | 327 */ |
328 static void record_descriptor(pst_file *pf, pst_desc_ll *node); | 328 static void record_descriptor(pst_file *pf, pst_desc_tree *node); |
329 static void record_descriptor(pst_file *pf, pst_desc_ll *node) | 329 static void record_descriptor(pst_file *pf, pst_desc_tree *node) |
330 { | 330 { |
331 DEBUG_ENT("record_descriptor"); | 331 DEBUG_ENT("record_descriptor"); |
332 // finish node initialization | 332 // finish node initialization |
333 node->parent = NULL; | 333 node->parent = NULL; |
334 node->child = NULL; | 334 node->child = NULL; |
335 node->child_tail = NULL; | 335 node->child_tail = NULL; |
336 node->no_child = 0; | 336 node->no_child = 0; |
337 | 337 |
338 // find any orphan children of this node, and collect them | 338 // find any orphan children of this node, and collect them |
339 pst_desc_ll *n = pf->d_head; | 339 pst_desc_tree *n = pf->d_head; |
340 while (n) { | 340 while (n) { |
341 if (n->parent_d_id == node->d_id) { | 341 if (n->parent_d_id == node->d_id) { |
342 // found a child of this node | 342 // found a child of this node |
343 DEBUG_INDEX(("Found orphan child %#"PRIx64" of parent %#"PRIx64"\n", n->d_id, node->d_id)); | 343 DEBUG_INDEX(("Found orphan child %#"PRIx64" of parent %#"PRIx64"\n", n->d_id, node->d_id)); |
344 pst_desc_ll *nn = n->next; | 344 pst_desc_tree *nn = n->next; |
345 pst_desc_ll *pp = n->prev; | 345 pst_desc_tree *pp = n->prev; |
346 node->no_child++; | 346 node->no_child++; |
347 n->parent = node; | 347 n->parent = node; |
348 add_descriptor_to_list(n, &node->child, &node->child_tail); | 348 add_descriptor_to_list(n, &node->child, &node->child_tail); |
349 if (pp) pp->next = nn; else pf->d_head = nn; | 349 if (pp) pp->next = nn; else pf->d_head = nn; |
350 if (nn) nn->prev = pp; else pf->d_tail = pp; | 350 if (nn) nn->prev = pp; else pf->d_tail = pp; |
365 // add top level node to the descriptor tree | 365 // add top level node to the descriptor tree |
366 DEBUG_INDEX(("%#"PRIx64" is its own parent. What is this world coming to?\n")); | 366 DEBUG_INDEX(("%#"PRIx64" is its own parent. What is this world coming to?\n")); |
367 add_descriptor_to_list(node, &pf->d_head, &pf->d_tail); | 367 add_descriptor_to_list(node, &pf->d_head, &pf->d_tail); |
368 } else { | 368 } else { |
369 //DEBUG_INDEX(("Searching for parent %#"PRIx64" of %#"PRIx64"\n", node->parent_d_id, node->d_id)); | 369 //DEBUG_INDEX(("Searching for parent %#"PRIx64" of %#"PRIx64"\n", node->parent_d_id, node->d_id)); |
370 pst_desc_ll *parent = pst_getDptr(pf, node->parent_d_id); | 370 pst_desc_tree *parent = pst_getDptr(pf, node->parent_d_id); |
371 if (parent) { | 371 if (parent) { |
372 //DEBUG_INDEX(("Found parent %#"PRIx64"\n", node->parent_d_id)); | 372 //DEBUG_INDEX(("Found parent %#"PRIx64"\n", node->parent_d_id)); |
373 parent->no_child++; | 373 parent->no_child++; |
374 node->parent = parent; | 374 node->parent = parent; |
375 add_descriptor_to_list(node, &parent->child, &parent->child_tail); | 375 add_descriptor_to_list(node, &parent->child, &parent->child_tail); |
388 * by an attachment containing an embedded rfc822 message. | 388 * by an attachment containing an embedded rfc822 message. |
389 * | 389 * |
390 * @param head pointer to the subtree to be copied | 390 * @param head pointer to the subtree to be copied |
391 * @return pointer to the new copy of the subtree | 391 * @return pointer to the new copy of the subtree |
392 */ | 392 */ |
393 static pst_id2_ll* deep_copy(pst_id2_ll *head); | 393 static pst_id2_tree* deep_copy(pst_id2_tree *head); |
394 static pst_id2_ll* deep_copy(pst_id2_ll *head) | 394 static pst_id2_tree* deep_copy(pst_id2_tree *head) |
395 { | 395 { |
396 if (!head) return NULL; | 396 if (!head) return NULL; |
397 pst_id2_ll* me = (pst_id2_ll*) pst_malloc(sizeof(pst_id2_ll)); | 397 pst_id2_tree* me = (pst_id2_tree*) pst_malloc(sizeof(pst_id2_tree)); |
398 me->id2 = head->id2; | 398 me->id2 = head->id2; |
399 me->id = head->id; | 399 me->id = head->id; |
400 me->child = deep_copy(head->child); | 400 me->child = deep_copy(head->child); |
401 me->next = deep_copy(head->next); | 401 me->next = deep_copy(head->next); |
402 return me; | 402 return me; |
403 } | 403 } |
404 | 404 |
405 | 405 |
406 pst_desc_ll* pst_getTopOfFolders(pst_file *pf, pst_item *root) { | 406 pst_desc_tree* pst_getTopOfFolders(pst_file *pf, pst_item *root) { |
407 pst_desc_ll *topnode; | 407 pst_desc_tree *topnode; |
408 uint32_t topid; | 408 uint32_t topid; |
409 DEBUG_ENT("pst_getTopOfFolders"); | 409 DEBUG_ENT("pst_getTopOfFolders"); |
410 if (!root || !root->message_store) { | 410 if (!root || !root->message_store) { |
411 DEBUG_INDEX(("There isn't a top of folder record here.\n")); | 411 DEBUG_INDEX(("There isn't a top of folder record here.\n")); |
412 DEBUG_RET(); | 412 DEBUG_RET(); |
421 } | 421 } |
422 DEBUG_INDEX(("looking for top of folder descriptor %#"PRIx32"\n", topid)); | 422 DEBUG_INDEX(("looking for top of folder descriptor %#"PRIx32"\n", topid)); |
423 topnode = pst_getDptr(pf, (uint64_t)topid); | 423 topnode = pst_getDptr(pf, (uint64_t)topid); |
424 if (!topnode) { | 424 if (!topnode) { |
425 // add dummy top record to pickup orphan children | 425 // add dummy top record to pickup orphan children |
426 topnode = (pst_desc_ll*) pst_malloc(sizeof(pst_desc_ll)); | 426 topnode = (pst_desc_tree*) pst_malloc(sizeof(pst_desc_tree)); |
427 topnode->d_id = topid; | 427 topnode->d_id = topid; |
428 topnode->parent_d_id = 0; | 428 topnode->parent_d_id = 0; |
429 topnode->assoc_tree = NULL; | 429 topnode->assoc_tree = NULL; |
430 topnode->desc = NULL; | 430 topnode->desc = NULL; |
431 record_descriptor(pf, topnode); // add to the global tree | 431 record_descriptor(pf, topnode); // add to the global tree |
504 DEBUG_RET(); | 504 DEBUG_RET(); |
505 return 0; | 505 return 0; |
506 } | 506 } |
507 | 507 |
508 | 508 |
509 pst_desc_ll* pst_getNextDptr(pst_desc_ll* d) { | 509 pst_desc_tree* pst_getNextDptr(pst_desc_tree* d) { |
510 pst_desc_ll* r = NULL; | 510 pst_desc_tree* r = NULL; |
511 DEBUG_ENT("pst_getNextDptr"); | 511 DEBUG_ENT("pst_getNextDptr"); |
512 if (d) { | 512 if (d) { |
513 if ((r = d->child) == NULL) { | 513 if ((r = d->child) == NULL) { |
514 while (!d->next && d->parent) d = d->parent; | 514 while (!d->next && d->parent) d = d->parent; |
515 r = d->next; | 515 r = d->next; |
530 /** Try to load the extended attributes from the pst file. | 530 /** Try to load the extended attributes from the pst file. |
531 @return true(1) or false(0) to indicate whether the extended attributes have been loaded | 531 @return true(1) or false(0) to indicate whether the extended attributes have been loaded |
532 */ | 532 */ |
533 int pst_load_extended_attributes(pst_file *pf) { | 533 int pst_load_extended_attributes(pst_file *pf) { |
534 // for PST files this will load up d_id 0x61 and check it's "assoc_tree" attribute. | 534 // for PST files this will load up d_id 0x61 and check it's "assoc_tree" attribute. |
535 pst_desc_ll *p; | 535 pst_desc_tree *p; |
536 pst_mapi_object *list; | 536 pst_mapi_object *list; |
537 pst_id2_ll *id2_head = NULL; | 537 pst_id2_tree *id2_head = NULL; |
538 char *buffer=NULL, *headerbuffer=NULL; | 538 char *buffer=NULL, *headerbuffer=NULL; |
539 size_t bsize=0, hsize=0, bptr=0; | 539 size_t bsize=0, hsize=0, bptr=0; |
540 pst_x_attrib xattrib; | 540 pst_x_attrib xattrib; |
541 int32_t tint, err=0, x; | 541 int32_t tint, err=0, x; |
542 pst_x_attrib_ll *ptr, *p_head=NULL; | 542 pst_x_attrib_ll *ptr, *p_head=NULL; |
687 #define DESC_SIZE (size_t)((pf->do_read64) ? DESC_SIZE64 : DESC_SIZE32) | 687 #define DESC_SIZE (size_t)((pf->do_read64) ? DESC_SIZE64 : DESC_SIZE32) |
688 #define INDEX_COUNT_MAX (int32_t)((pf->do_read64) ? INDEX_COUNT_MAX64 : INDEX_COUNT_MAX32) | 688 #define INDEX_COUNT_MAX (int32_t)((pf->do_read64) ? INDEX_COUNT_MAX64 : INDEX_COUNT_MAX32) |
689 #define DESC_COUNT_MAX (int32_t)((pf->do_read64) ? DESC_COUNT_MAX64 : DESC_COUNT_MAX32) | 689 #define DESC_COUNT_MAX (int32_t)((pf->do_read64) ? DESC_COUNT_MAX64 : DESC_COUNT_MAX32) |
690 | 690 |
691 | 691 |
692 static size_t pst_decode_desc(pst_file *pf, pst_descn *desc, char *buf); | 692 static size_t pst_decode_desc(pst_file *pf, pst_desc *desc, char *buf); |
693 static size_t pst_decode_desc(pst_file *pf, pst_descn *desc, char *buf) { | 693 static size_t pst_decode_desc(pst_file *pf, pst_desc *desc, char *buf) { |
694 size_t r; | 694 size_t r; |
695 if (pf->do_read64) { | 695 if (pf->do_read64) { |
696 DEBUG_INDEX(("Decoding desc64\n")); | 696 DEBUG_INDEX(("Decoding desc64\n")); |
697 DEBUG_HEXDUMPC(buf, sizeof(pst_descn), 0x10); | 697 DEBUG_HEXDUMPC(buf, sizeof(pst_desc), 0x10); |
698 memcpy(desc, buf, sizeof(pst_descn)); | 698 memcpy(desc, buf, sizeof(pst_desc)); |
699 LE64_CPU(desc->d_id); | 699 LE64_CPU(desc->d_id); |
700 LE64_CPU(desc->desc_id); | 700 LE64_CPU(desc->desc_id); |
701 LE64_CPU(desc->tree_id); | 701 LE64_CPU(desc->tree_id); |
702 LE32_CPU(desc->parent_d_id); | 702 LE32_CPU(desc->parent_d_id); |
703 LE32_CPU(desc->u1); | 703 LE32_CPU(desc->u1); |
704 r = sizeof(pst_descn); | 704 r = sizeof(pst_desc); |
705 } | 705 } |
706 else { | 706 else { |
707 pst_desc32 d32; | 707 pst_desc32 d32; |
708 DEBUG_INDEX(("Decoding desc32\n")); | 708 DEBUG_INDEX(("Decoding desc32\n")); |
709 DEBUG_HEXDUMPC(buf, sizeof(pst_desc32), 0x10); | 709 DEBUG_HEXDUMPC(buf, sizeof(pst_desc32), 0x10); |
957 * pf->d_head tree from it. This tree holds descriptions of the | 957 * pf->d_head tree from it. This tree holds descriptions of the |
958 * higher level objects (email, contact, etc) in the pst file. | 958 * higher level objects (email, contact, etc) in the pst file. |
959 */ | 959 */ |
960 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) { | 960 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) { |
961 struct pst_table_ptr_structn table, table2; | 961 struct pst_table_ptr_structn table, table2; |
962 pst_descn desc_rec; | 962 pst_desc desc_rec; |
963 int32_t item_count; | 963 int32_t item_count; |
964 uint64_t old = start_val; | 964 uint64_t old = start_val; |
965 int x; | 965 int x; |
966 char *buf = NULL, *bptr; | 966 char *buf = NULL, *bptr; |
967 | 967 |
1018 return -1; | 1018 return -1; |
1019 } | 1019 } |
1020 } | 1020 } |
1021 DEBUG_INDEX(("New Record %#"PRIx64" with parent %#x\n", desc_rec.d_id, desc_rec.parent_d_id)); | 1021 DEBUG_INDEX(("New Record %#"PRIx64" with parent %#x\n", desc_rec.d_id, desc_rec.parent_d_id)); |
1022 { | 1022 { |
1023 pst_desc_ll *d_ptr = (pst_desc_ll*) pst_malloc(sizeof(pst_desc_ll)); | 1023 pst_desc_tree *d_ptr = (pst_desc_tree*) pst_malloc(sizeof(pst_desc_tree)); |
1024 d_ptr->d_id = desc_rec.d_id; | 1024 d_ptr->d_id = desc_rec.d_id; |
1025 d_ptr->parent_d_id = desc_rec.parent_d_id; | 1025 d_ptr->parent_d_id = desc_rec.parent_d_id; |
1026 d_ptr->assoc_tree = pst_getID(pf, desc_rec.tree_id); | 1026 d_ptr->assoc_tree = pst_getID(pf, desc_rec.tree_id); |
1027 d_ptr->desc = pst_getID(pf, desc_rec.desc_id); | 1027 d_ptr->desc = pst_getID(pf, desc_rec.desc_id); |
1028 record_descriptor(pf, d_ptr); // add to the global tree | 1028 record_descriptor(pf, d_ptr); // add to the global tree |
1072 } | 1072 } |
1073 | 1073 |
1074 | 1074 |
1075 /** Process a high level object from the pst file. | 1075 /** Process a high level object from the pst file. |
1076 */ | 1076 */ |
1077 pst_item* pst_parse_item(pst_file *pf, pst_desc_ll *d_ptr, pst_id2_ll *m_head) { | 1077 pst_item* pst_parse_item(pst_file *pf, pst_desc_tree *d_ptr, pst_id2_tree *m_head) { |
1078 pst_mapi_object * list; | 1078 pst_mapi_object * list; |
1079 pst_id2_ll *id2_head = m_head; | 1079 pst_id2_tree *id2_head = m_head; |
1080 pst_id2_ll *id2_ptr = NULL; | 1080 pst_id2_tree *id2_ptr = NULL; |
1081 pst_item *item = NULL; | 1081 pst_item *item = NULL; |
1082 pst_item_attach *attach = NULL; | 1082 pst_item_attach *attach = NULL; |
1083 int32_t x; | 1083 int32_t x; |
1084 DEBUG_ENT("pst_parse_item"); | 1084 DEBUG_ENT("pst_parse_item"); |
1085 if (!d_ptr) { | 1085 if (!d_ptr) { |
1259 /** Process a low level descriptor block (0x0101, 0xbcec, 0x7cec) into a | 1259 /** Process a low level descriptor block (0x0101, 0xbcec, 0x7cec) into a |
1260 * list of MAPI objects, each of which contains a list of MAPI elements. | 1260 * list of MAPI objects, each of which contains a list of MAPI elements. |
1261 * | 1261 * |
1262 * @return list of MAPI objects | 1262 * @return list of MAPI objects |
1263 */ | 1263 */ |
1264 static pst_mapi_object* pst_parse_block(pst_file *pf, uint64_t block_id, pst_id2_ll *i2_head) { | 1264 static pst_mapi_object* pst_parse_block(pst_file *pf, uint64_t block_id, pst_id2_tree *i2_head) { |
1265 pst_mapi_object *mo_head = NULL; | 1265 pst_mapi_object *mo_head = NULL; |
1266 char *buf = NULL; | 1266 char *buf = NULL; |
1267 size_t read_size = 0; | 1267 size_t read_size = 0; |
1268 pst_subblocks subblocks; | 1268 pst_subblocks subblocks; |
1269 pst_mapi_object *mo_ptr = NULL; | 1269 pst_mapi_object *mo_ptr = NULL; |
3018 } | 3018 } |
3019 DEBUG_RET(); | 3019 DEBUG_RET(); |
3020 } | 3020 } |
3021 | 3021 |
3022 | 3022 |
3023 static void pst_free_id2(pst_id2_ll * head) { | 3023 static void pst_free_id2(pst_id2_tree * head) { |
3024 pst_id2_ll *t; | 3024 pst_id2_tree *t; |
3025 DEBUG_ENT("pst_free_id2"); | 3025 DEBUG_ENT("pst_free_id2"); |
3026 while (head) { | 3026 while (head) { |
3027 if (head->child) pst_free_id2(head->child); | 3027 if (head->child) pst_free_id2(head->child); |
3028 t = head->next; | 3028 t = head->next; |
3029 free(head); | 3029 free(head); |
3043 } | 3043 } |
3044 DEBUG_RET(); | 3044 DEBUG_RET(); |
3045 } | 3045 } |
3046 | 3046 |
3047 | 3047 |
3048 static void pst_free_desc (pst_desc_ll *head) { | 3048 static void pst_free_desc (pst_desc_tree *head) { |
3049 pst_desc_ll *t; | 3049 pst_desc_tree *t; |
3050 DEBUG_ENT("pst_free_desc"); | 3050 DEBUG_ENT("pst_free_desc"); |
3051 while (head) { | 3051 while (head) { |
3052 while (head->child) { | 3052 while (head->child) { |
3053 head = head->child; | 3053 head = head->child; |
3054 } | 3054 } |
3080 } | 3080 } |
3081 DEBUG_RET(); | 3081 DEBUG_RET(); |
3082 } | 3082 } |
3083 | 3083 |
3084 | 3084 |
3085 static pst_id2_ll * pst_build_id2(pst_file *pf, pst_index_ll* list) { | 3085 static pst_id2_tree * pst_build_id2(pst_file *pf, pst_index_ll* list) { |
3086 pst_block_header block_head; | 3086 pst_block_header block_head; |
3087 pst_id2_ll *head = NULL, *tail = NULL; | 3087 pst_id2_tree *head = NULL, *tail = NULL; |
3088 uint16_t x = 0; | 3088 uint16_t x = 0; |
3089 char *b_ptr = NULL; | 3089 char *b_ptr = NULL; |
3090 char *buf = NULL; | 3090 char *buf = NULL; |
3091 pst_id2_assoc id2_rec; | 3091 pst_id2_assoc id2_rec; |
3092 pst_index_ll *i_ptr = NULL; | 3092 pst_index_ll *i_ptr = NULL; |
3093 pst_id2_ll *i2_ptr = NULL; | 3093 pst_id2_tree *i2_ptr = NULL; |
3094 DEBUG_ENT("pst_build_id2"); | 3094 DEBUG_ENT("pst_build_id2"); |
3095 | 3095 |
3096 if (pst_read_block_size(pf, list->offset, list->size, &buf) < list->size) { | 3096 if (pst_read_block_size(pf, list->offset, list->size, &buf) < list->size) { |
3097 //an error occured in block read | 3097 //an error occured in block read |
3098 WARN(("block read error occured. offset = %#"PRIx64", size = %#"PRIx64"\n", list->offset, list->size)); | 3098 WARN(("block read error occured. offset = %#"PRIx64", size = %#"PRIx64"\n", list->offset, list->size)); |
3124 DEBUG_WARN(("%#"PRIx64" - Not Found\n", id2_rec.id)); | 3124 DEBUG_WARN(("%#"PRIx64" - Not Found\n", id2_rec.id)); |
3125 } else { | 3125 } else { |
3126 DEBUG_INDEX(("%#"PRIx64" - Offset %#"PRIx64", u1 %#"PRIx64", Size %"PRIi64"(%#"PRIx64")\n", | 3126 DEBUG_INDEX(("%#"PRIx64" - Offset %#"PRIx64", u1 %#"PRIx64", Size %"PRIi64"(%#"PRIx64")\n", |
3127 i_ptr->i_id, i_ptr->offset, i_ptr->u1, i_ptr->size, i_ptr->size)); | 3127 i_ptr->i_id, i_ptr->offset, i_ptr->u1, i_ptr->size, i_ptr->size)); |
3128 // add it to the tree | 3128 // add it to the tree |
3129 i2_ptr = (pst_id2_ll*) pst_malloc(sizeof(pst_id2_ll)); | 3129 i2_ptr = (pst_id2_tree*) pst_malloc(sizeof(pst_id2_tree)); |
3130 i2_ptr->id2 = id2_rec.id2; | 3130 i2_ptr->id2 = id2_rec.id2; |
3131 i2_ptr->id = i_ptr; | 3131 i2_ptr->id = i_ptr; |
3132 i2_ptr->child = NULL; | 3132 i2_ptr->child = NULL; |
3133 i2_ptr->next = NULL; | 3133 i2_ptr->next = NULL; |
3134 if (!head) head = i2_ptr; | 3134 if (!head) head = i2_ptr; |
3375 * The offset might be zero, in which case we have no data, so return a pair of null pointers. | 3375 * The offset might be zero, in which case we have no data, so return a pair of null pointers. |
3376 * Or, the offset might end in 0xf, so it is an id2 pointer, in which case we read the id2 block. | 3376 * Or, the offset might end in 0xf, so it is an id2 pointer, in which case we read the id2 block. |
3377 * Otherwise, the high order 16 bits of offset is the index into the subblocks, and | 3377 * Otherwise, the high order 16 bits of offset is the index into the subblocks, and |
3378 * the (low order 16 bits of offset)>>4 is an index into the table of offsets in the subblock. | 3378 * the (low order 16 bits of offset)>>4 is an index into the table of offsets in the subblock. |
3379 */ | 3379 */ |
3380 static int pst_getBlockOffsetPointer(pst_file *pf, pst_id2_ll *i2_head, pst_subblocks *subblocks, uint32_t offset, pst_block_offset_pointer *p) { | 3380 static int pst_getBlockOffsetPointer(pst_file *pf, pst_id2_tree *i2_head, pst_subblocks *subblocks, uint32_t offset, pst_block_offset_pointer *p) { |
3381 size_t size; | 3381 size_t size; |
3382 pst_block_offset block_offset; | 3382 pst_block_offset block_offset; |
3383 DEBUG_ENT("pst_getBlockOffsetPointer"); | 3383 DEBUG_ENT("pst_getBlockOffsetPointer"); |
3384 if (p->needfree) free(p->from); | 3384 if (p->needfree) free(p->from); |
3385 p->from = NULL; | 3385 p->from = NULL; |
3470 DEBUG_RET(); | 3470 DEBUG_RET(); |
3471 return ptr; | 3471 return ptr; |
3472 } | 3472 } |
3473 | 3473 |
3474 | 3474 |
3475 static pst_id2_ll *pst_getID2(pst_id2_ll *head, uint64_t id2) { | 3475 static pst_id2_tree *pst_getID2(pst_id2_tree *head, uint64_t id2) { |
3476 DEBUG_ENT("pst_getID2"); | 3476 DEBUG_ENT("pst_getID2"); |
3477 DEBUG_INDEX(("looking for id2 = %#"PRIx64"\n", id2)); | 3477 DEBUG_INDEX(("looking for id2 = %#"PRIx64"\n", id2)); |
3478 pst_id2_ll *ptr = head; | 3478 pst_id2_tree *ptr = head; |
3479 while (ptr) { | 3479 while (ptr) { |
3480 if (ptr->id2 == id2) break; | 3480 if (ptr->id2 == id2) break; |
3481 if (ptr->child) { | 3481 if (ptr->child) { |
3482 pst_id2_ll *rc = pst_getID2(ptr->child, id2); | 3482 pst_id2_tree *rc = pst_getID2(ptr->child, id2); |
3483 if (rc) { | 3483 if (rc) { |
3484 DEBUG_RET(); | 3484 DEBUG_RET(); |
3485 return rc; | 3485 return rc; |
3486 } | 3486 } |
3487 } | 3487 } |
3502 * find the id in the descriptor tree rooted at pf->d_head | 3502 * find the id in the descriptor tree rooted at pf->d_head |
3503 * | 3503 * |
3504 * @param pf global pst file pointer | 3504 * @param pf global pst file pointer |
3505 * @param d_id the id we are looking for | 3505 * @param d_id the id we are looking for |
3506 * | 3506 * |
3507 * @return pointer to the pst_desc_ll node in the descriptor tree | 3507 * @return pointer to the pst_desc_tree node in the descriptor tree |
3508 */ | 3508 */ |
3509 static pst_desc_ll* pst_getDptr(pst_file *pf, uint64_t d_id) { | 3509 static pst_desc_tree* pst_getDptr(pst_file *pf, uint64_t d_id) { |
3510 pst_desc_ll *ptr = pf->d_head; | 3510 pst_desc_tree *ptr = pf->d_head; |
3511 DEBUG_ENT("pst_getDptr"); | 3511 DEBUG_ENT("pst_getDptr"); |
3512 while (ptr && (ptr->d_id != d_id)) { | 3512 while (ptr && (ptr->d_id != d_id)) { |
3513 //DEBUG_INDEX(("Looking for %#"PRIx64" at node %#"PRIx64" with parent %#"PRIx64"\n", id, ptr->d_id, ptr->parent_d_id)); | 3513 //DEBUG_INDEX(("Looking for %#"PRIx64" at node %#"PRIx64" with parent %#"PRIx64"\n", id, ptr->d_id, ptr->parent_d_id)); |
3514 if (ptr->child) { | 3514 if (ptr->child) { |
3515 ptr = ptr->child; | 3515 ptr = ptr->child; |
3523 DEBUG_RET(); | 3523 DEBUG_RET(); |
3524 return ptr; // will be NULL or record we are looking for | 3524 return ptr; // will be NULL or record we are looking for |
3525 } | 3525 } |
3526 | 3526 |
3527 | 3527 |
3528 static void pst_printDptr(pst_file *pf, pst_desc_ll *ptr) { | 3528 static void pst_printDptr(pst_file *pf, pst_desc_tree *ptr) { |
3529 DEBUG_ENT("pst_printDptr"); | 3529 DEBUG_ENT("pst_printDptr"); |
3530 while (ptr) { | 3530 while (ptr) { |
3531 DEBUG_INDEX(("%#"PRIx64" [%i] desc=%#"PRIx64", assoc tree=%#"PRIx64"\n", ptr->d_id, ptr->no_child, | 3531 DEBUG_INDEX(("%#"PRIx64" [%i] desc=%#"PRIx64", assoc tree=%#"PRIx64"\n", ptr->d_id, ptr->no_child, |
3532 (ptr->desc ? ptr->desc->i_id : (uint64_t)0), | 3532 (ptr->desc ? ptr->desc->i_id : (uint64_t)0), |
3533 (ptr->assoc_tree ? ptr->assoc_tree->i_id : (uint64_t)0))); | 3533 (ptr->assoc_tree ? ptr->assoc_tree->i_id : (uint64_t)0))); |
3549 } | 3549 } |
3550 DEBUG_RET(); | 3550 DEBUG_RET(); |
3551 } | 3551 } |
3552 | 3552 |
3553 | 3553 |
3554 static void pst_printID2ptr(pst_id2_ll *ptr) { | 3554 static void pst_printID2ptr(pst_id2_tree *ptr) { |
3555 DEBUG_ENT("pst_printID2ptr"); | 3555 DEBUG_ENT("pst_printID2ptr"); |
3556 while (ptr) { | 3556 while (ptr) { |
3557 DEBUG_INDEX(("%#"PRIx64" id=%#"PRIx64"\n", ptr->id2, (ptr->id ? ptr->id->i_id : (uint64_t)0))); | 3557 DEBUG_INDEX(("%#"PRIx64" id=%#"PRIx64"\n", ptr->id2, (ptr->id ? ptr->id->i_id : (uint64_t)0))); |
3558 if (ptr->child) pst_printID2ptr(ptr->child); | 3558 if (ptr->child) pst_printID2ptr(ptr->child); |
3559 ptr = ptr->next; | 3559 ptr = ptr->next; |
3769 DEBUG_RET(); | 3769 DEBUG_RET(); |
3770 return rsize; | 3770 return rsize; |
3771 } | 3771 } |
3772 | 3772 |
3773 | 3773 |
3774 static size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_id2_ll *id2_head, char** buf) { | 3774 static size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_id2_tree *id2_head, char** buf) { |
3775 size_t ret; | 3775 size_t ret; |
3776 pst_id2_ll* ptr; | 3776 pst_id2_tree* ptr; |
3777 pst_holder h = {buf, NULL, 0}; | 3777 pst_holder h = {buf, NULL, 0}; |
3778 DEBUG_ENT("pst_ff_getID2block"); | 3778 DEBUG_ENT("pst_ff_getID2block"); |
3779 ptr = pst_getID2(id2_head, id2); | 3779 ptr = pst_getID2(id2_head, id2); |
3780 | 3780 |
3781 if (!ptr) { | 3781 if (!ptr) { |