Mercurial > libpst
comparison src/libpst.c @ 143:fdc58ad2c758 stable-0-6-28
fix embedded rfc822 messages with attachments
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 24 Feb 2009 12:33:49 -0800 |
parents | 2189a6b8134e |
children | b47d04257b43 |
comparison
equal
deleted
inserted
replaced
142:2189a6b8134e | 143:fdc58ad2c758 |
---|---|
347 } | 347 } |
348 DEBUG_RET(); | 348 DEBUG_RET(); |
349 } | 349 } |
350 | 350 |
351 | 351 |
352 /** | |
353 * make a deep copy of part of the id2 mapping tree, for use | |
354 * by an attachment containing an embedded rfc822 message. | |
355 * | |
356 * @param head pointer to the subtree to be copied | |
357 * @return pointer to the new copy of the subtree | |
358 */ | |
359 static pst_index2_ll* deep_copy(pst_index2_ll *head); | |
360 static pst_index2_ll* deep_copy(pst_index2_ll *head) | |
361 { | |
362 if (!head) return NULL; | |
363 pst_index2_ll* me = (pst_index2_ll*) xmalloc(sizeof(pst_index2_ll)); | |
364 me->id2 = head->id2; | |
365 me->id = head->id; | |
366 me->child = deep_copy(head->child); | |
367 me->next = deep_copy(head->next); | |
368 return me; | |
369 } | |
370 | |
371 | |
352 pst_desc_ll* pst_getTopOfFolders(pst_file *pf, pst_item *root) { | 372 pst_desc_ll* pst_getTopOfFolders(pst_file *pf, pst_item *root) { |
353 pst_desc_ll *topnode; | 373 pst_desc_ll *topnode; |
354 uint32_t topid; | 374 uint32_t topid; |
355 DEBUG_ENT("pst_getTopOfFolders"); | 375 DEBUG_ENT("pst_getTopOfFolders"); |
356 if (!root || !root->message_store) { | 376 if (!root || !root->message_store) { |
528 } | 548 } |
529 | 549 |
530 na = pst_parse_block(pf, p->desc->id, id2_head, NULL); | 550 na = pst_parse_block(pf, p->desc->id, id2_head, NULL); |
531 if (!na) { | 551 if (!na) { |
532 DEBUG_WARN(("Cannot process desc block for item 0x61. Not loading extended Attributes\n")); | 552 DEBUG_WARN(("Cannot process desc block for item 0x61. Not loading extended Attributes\n")); |
533 if (id2_head) pst_free_id2(id2_head); | 553 pst_free_id2(id2_head); |
534 DEBUG_RET(); | 554 DEBUG_RET(); |
535 return 0; | 555 return 0; |
536 } | 556 } |
537 | 557 |
538 for (x=0; x < na->count_item; x++) { | 558 for (x=0; x < na->count_item; x++) { |
546 // leave them null | 566 // leave them null |
547 } | 567 } |
548 } | 568 } |
549 | 569 |
550 if (!buffer) { | 570 if (!buffer) { |
551 if (na) pst_free_list(na); | 571 pst_free_list(na); |
552 DEBUG_WARN(("No extended attributes buffer found. Not processing\n")); | 572 DEBUG_WARN(("No extended attributes buffer found. Not processing\n")); |
553 DEBUG_RET(); | 573 DEBUG_RET(); |
554 return 0; | 574 return 0; |
555 } | 575 } |
556 | 576 |
618 LE32_CPU(xattrib.extended); | 638 LE32_CPU(xattrib.extended); |
619 LE16_CPU(xattrib.type); | 639 LE16_CPU(xattrib.type); |
620 LE16_CPU(xattrib.map); | 640 LE16_CPU(xattrib.map); |
621 bptr += sizeof(xattrib); | 641 bptr += sizeof(xattrib); |
622 } | 642 } |
623 if (id2_head) pst_free_id2(id2_head); | 643 pst_free_id2(id2_head); |
624 if (na) pst_free_list(na); | 644 pst_free_list(na); |
625 pf->x_head = p_head; | 645 pf->x_head = p_head; |
626 DEBUG_RET(); | 646 DEBUG_RET(); |
627 return 1; | 647 return 1; |
628 } | 648 } |
629 | 649 |
1026 DEBUG_RET(); | 1046 DEBUG_RET(); |
1027 return 0; | 1047 return 0; |
1028 } | 1048 } |
1029 | 1049 |
1030 | 1050 |
1031 pst_item* pst_parse_item(pst_file *pf, pst_desc_ll *d_ptr) { | 1051 pst_item* pst_parse_item(pst_file *pf, pst_desc_ll *d_ptr, pst_index2_ll *m_head) { |
1032 pst_num_array * list; | 1052 pst_num_array * list; |
1033 pst_index2_ll *id2_head = NULL; | 1053 pst_index2_ll *id2_head = m_head; |
1034 pst_index_ll *id_ptr = NULL; | 1054 pst_index2_ll *id2_ptr = NULL; |
1035 pst_item *item = NULL; | 1055 pst_item *item = NULL; |
1036 pst_item_attach *attach = NULL; | 1056 pst_item_attach *attach = NULL; |
1037 int32_t x; | 1057 int32_t x; |
1038 DEBUG_ENT("pst_parse_item"); | 1058 DEBUG_ENT("pst_parse_item"); |
1039 if (!d_ptr) { | 1059 if (!d_ptr) { |
1047 DEBUG_RET(); | 1067 DEBUG_RET(); |
1048 return NULL; | 1068 return NULL; |
1049 } | 1069 } |
1050 | 1070 |
1051 if (d_ptr->list_index) { | 1071 if (d_ptr->list_index) { |
1072 if (m_head) { | |
1073 DEBUG_WARN(("supplied master head, but have a list that is building a new id2_head")); | |
1074 m_head = NULL; | |
1075 } | |
1052 id2_head = pst_build_id2(pf, d_ptr->list_index); | 1076 id2_head = pst_build_id2(pf, d_ptr->list_index); |
1053 (void)pst_printID2ptr(id2_head); | 1077 } |
1054 } | 1078 pst_printID2ptr(id2_head); |
1055 | 1079 |
1056 list = pst_parse_block(pf, d_ptr->desc->id, id2_head, NULL); | 1080 list = pst_parse_block(pf, d_ptr->desc->id, id2_head, NULL); |
1057 if (!list) { | 1081 if (!list) { |
1058 DEBUG_WARN(("pst_parse_block() returned an error for d_ptr->desc->id [%#"PRIx64"]\n", d_ptr->desc->id)); | 1082 DEBUG_WARN(("pst_parse_block() returned an error for d_ptr->desc->id [%#"PRIx64"]\n", d_ptr->desc->id)); |
1059 if (id2_head) pst_free_id2(id2_head); | 1083 if (!m_head) pst_free_id2(id2_head); |
1060 DEBUG_RET(); | 1084 DEBUG_RET(); |
1061 return NULL; | 1085 return NULL; |
1062 } | 1086 } |
1063 | 1087 |
1064 item = (pst_item*) xmalloc(sizeof(pst_item)); | 1088 item = (pst_item*) xmalloc(sizeof(pst_item)); |
1065 memset(item, 0, sizeof(pst_item)); | 1089 memset(item, 0, sizeof(pst_item)); |
1066 | 1090 |
1067 if (pst_process(list, item, NULL)) { | 1091 if (pst_process(list, item, NULL)) { |
1068 DEBUG_WARN(("pst_process() returned non-zero value. That is an error\n")); | 1092 DEBUG_WARN(("pst_process() returned non-zero value. That is an error\n")); |
1069 if (item) pst_freeItem(item); | 1093 pst_freeItem(item); |
1070 if (list) pst_free_list(list); | 1094 pst_free_list(list); |
1071 if (id2_head) pst_free_id2(id2_head); | 1095 if (!m_head) pst_free_id2(id2_head); |
1072 DEBUG_RET(); | 1096 DEBUG_RET(); |
1073 return NULL; | 1097 return NULL; |
1074 } | 1098 } |
1075 if (list) pst_free_list(list); | 1099 pst_free_list(list); |
1076 list = NULL; | 1100 |
1077 | 1101 if ((id2_ptr = pst_getID2(id2_head, (uint64_t)0x692))) { |
1078 if ((id_ptr = pst_getID2(id2_head, (uint64_t)0x692))) { | |
1079 // DSN/MDN reports? | 1102 // DSN/MDN reports? |
1080 DEBUG_EMAIL(("DSN/MDN processing \n")); | 1103 DEBUG_EMAIL(("DSN/MDN processing \n")); |
1081 if ((list = pst_parse_block(pf, id_ptr->id, id2_head, NULL)) == NULL) { | 1104 list = pst_parse_block(pf, id2_ptr->id->id, id2_head, NULL); |
1105 if (!list) { | |
1082 DEBUG_WARN(("ERROR error processing main DSN/MDN record\n")); | 1106 DEBUG_WARN(("ERROR error processing main DSN/MDN record\n")); |
1083 if (item) pst_freeItem(item); | 1107 if (!m_head) pst_free_id2(id2_head); |
1084 if (list) pst_free_list(list); | |
1085 if (id2_head) pst_free_id2(id2_head); | |
1086 DEBUG_RET(); | 1108 DEBUG_RET(); |
1087 return item; | 1109 return item; |
1088 } | 1110 } |
1089 else { | 1111 for (x=0; x < list->count_array; x++) { |
1090 for (x=0; x < list->count_array; x++) { | 1112 attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach)); |
1091 attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach)); | 1113 memset(attach, 0, sizeof(pst_item_attach)); |
1092 memset(attach, 0, sizeof(pst_item_attach)); | 1114 attach->next = item->attach; |
1093 attach->next = item->attach; | 1115 item->attach = attach; |
1094 item->attach = attach; | 1116 } |
1095 } | 1117 if (pst_process(list, item, item->attach)) { |
1096 | 1118 DEBUG_WARN(("ERROR pst_process() failed with DSN/MDN attachments\n")); |
1097 if (pst_process(list, item, item->attach)) { | 1119 pst_freeItem(item); |
1098 DEBUG_WARN(("ERROR pst_process() failed with attachments\n")); | 1120 pst_free_list(list); |
1099 if (item) pst_freeItem(item); | 1121 if (!m_head) pst_free_id2(id2_head); |
1100 if (list) pst_free_list(list); | 1122 DEBUG_RET(); |
1101 if (id2_head) pst_free_id2(id2_head); | 1123 return NULL; |
1102 DEBUG_RET(); | 1124 } |
1103 return NULL; | 1125 pst_free_list(list); |
1104 } | 1126 } |
1105 if (list) pst_free_list(list); | 1127 |
1106 list = NULL; | 1128 if ((id2_ptr = pst_getID2(id2_head, (uint64_t)0x671))) { |
1107 } | |
1108 } | |
1109 | |
1110 if ((id_ptr = pst_getID2(id2_head, (uint64_t)0x671))) { | |
1111 // should not have any existing attachments anyway | 1129 // should not have any existing attachments anyway |
1112 //while (item->attach) { | 1130 //while (item->attach) { |
1113 // DEBUG_EMAIL(("throw away existing attachment\n")); | 1131 // DEBUG_EMAIL(("throw away existing attachment\n")); |
1114 // attach = item->attach->next; | 1132 // attach = item->attach->next; |
1115 // free(item->attach); | 1133 // free(item->attach); |
1116 // item->attach = attach; | 1134 // item->attach = attach; |
1117 //} | 1135 //} |
1118 | 1136 |
1119 DEBUG_EMAIL(("ATTACHMENT processing attachment\n")); | 1137 DEBUG_EMAIL(("ATTACHMENT processing attachment\n")); |
1120 if ((list = pst_parse_block(pf, id_ptr->id, id2_head, NULL)) == NULL) { | 1138 list = pst_parse_block(pf, id2_ptr->id->id, id2_head, NULL); |
1139 if (!list) { | |
1121 DEBUG_WARN(("ERROR error processing main attachment record\n")); | 1140 DEBUG_WARN(("ERROR error processing main attachment record\n")); |
1122 if (id2_head) pst_free_id2(id2_head); | 1141 if (!m_head) pst_free_id2(id2_head); |
1123 DEBUG_RET(); | 1142 DEBUG_RET(); |
1124 return item; | 1143 return item; |
1125 } | 1144 } |
1126 else { | 1145 for (x=0; x < list->count_array; x++) { |
1127 for (x=0; x < list->count_array; x++) { | 1146 attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach)); |
1128 attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach)); | 1147 memset(attach, 0, sizeof(pst_item_attach)); |
1129 memset(attach, 0, sizeof(pst_item_attach)); | 1148 attach->next = item->attach; |
1130 attach->next = item->attach; | 1149 item->attach = attach; |
1131 item->attach = attach; | 1150 } |
1151 if (pst_process(list, item, item->attach)) { | |
1152 DEBUG_WARN(("ERROR pst_process() failed with attachments\n")); | |
1153 pst_freeItem(item); | |
1154 pst_free_list(list); | |
1155 if (!m_head) pst_free_id2(id2_head); | |
1156 DEBUG_RET(); | |
1157 return NULL; | |
1158 } | |
1159 pst_free_list(list); | |
1160 | |
1161 // now we will have initial information of each attachment stored in item->attach... | |
1162 // we must now read the secondary record for each based on the id2 val associated with | |
1163 // each attachment | |
1164 attach = item->attach; | |
1165 while (attach) { | |
1166 DEBUG_WARN(("initial attachment id2 %#"PRIx64"\n", attach->id2_val)); | |
1167 if ((id2_ptr = pst_getID2(id2_head, attach->id2_val))) { | |
1168 DEBUG_WARN(("initial attachment id2 found id %#"PRIx64"\n", id2_ptr->id->id)); | |
1169 // id_ptr is a record describing the attachment | |
1170 // we pass NULL instead of id2_head cause we don't want it to | |
1171 // load all the extra stuff here. | |
1172 list = pst_parse_block(pf, id2_ptr->id->id, NULL, NULL); | |
1173 if (!list) { | |
1174 DEBUG_WARN(("ERROR error processing an attachment record\n")); | |
1175 attach = attach->next; | |
1176 continue; | |
1177 } | |
1178 if (list->count_array > 1) { | |
1179 DEBUG_WARN(("ERROR probably fatal, list count array will overrun attach structure.\n")); | |
1180 } | |
1181 if (pst_process(list, item, attach)) { | |
1182 DEBUG_WARN(("ERROR pst_process() failed with an attachment\n")); | |
1183 pst_free_list(list); | |
1184 attach = attach->next; | |
1185 continue; | |
1186 } | |
1187 pst_free_list(list); | |
1188 id2_ptr = pst_getID2(id2_head, attach->id2_val); | |
1189 if (id2_ptr) { | |
1190 DEBUG_WARN(("second pass attachment updating id2 found id %#"PRIx64"\n", id2_ptr->id->id)); | |
1191 // id2_val has been updated to the ID2 value of the datablock containing the | |
1192 // attachment data | |
1193 attach->id_val = id2_ptr->id->id; | |
1194 attach->id2_head = deep_copy(id2_ptr->child); | |
1195 } else { | |
1196 DEBUG_WARN(("have not located the correct value for the attachment [%#"PRIx64"]\n", attach->id2_val)); | |
1197 } | |
1198 } else { | |
1199 DEBUG_WARN(("ERROR cannot locate id2 value %#"PRIx64"\n", attach->id2_val)); | |
1200 attach->id2_val = 0; // suppress this missing attachment | |
1132 } | 1201 } |
1133 | 1202 attach = attach->next; |
1134 if (pst_process(list, item, item->attach)) { | 1203 } |
1135 DEBUG_WARN(("ERROR pst_process() failed with attachments\n")); | 1204 } |
1136 if (item) pst_freeItem(item); | 1205 |
1137 if (list) pst_free_list(list); | 1206 if (!m_head) pst_free_id2(id2_head); |
1138 if (id2_head) pst_free_id2(id2_head); | |
1139 DEBUG_RET(); | |
1140 return NULL; | |
1141 } | |
1142 if (list) pst_free_list(list); | |
1143 list = NULL; | |
1144 | |
1145 // now we will have initial information of each attachment stored in item->attach... | |
1146 // we must now read the secondary record for each based on the id2 val associated with | |
1147 // each attachment | |
1148 attach = item->attach; | |
1149 while (attach) { | |
1150 DEBUG_WARN(("initial attachment id2 %#"PRIx64"\n", attach->id2_val)); | |
1151 if ((id_ptr = pst_getID2(id2_head, attach->id2_val))) { | |
1152 DEBUG_WARN(("initial attachment id2 found id %#"PRIx64"\n", id_ptr->id)); | |
1153 // id_ptr is a record describing the attachment | |
1154 // we pass NULL instead of id2_head cause we don't want it to | |
1155 // load all the extra stuff here. | |
1156 if ((list = pst_parse_block(pf, id_ptr->id, NULL, NULL)) == NULL) { | |
1157 DEBUG_WARN(("ERROR error processing an attachment record\n")); | |
1158 attach = attach->next; | |
1159 continue; | |
1160 } | |
1161 if (list->count_array > 1) { | |
1162 DEBUG_WARN(("ERROR probably fatal, list count array will overrun attach structure.\n")); | |
1163 } | |
1164 if (pst_process(list, item, attach)) { | |
1165 DEBUG_WARN(("ERROR pst_process() failed with an attachment\n")); | |
1166 if (list) pst_free_list(list); | |
1167 list = NULL; | |
1168 attach = attach->next; | |
1169 continue; | |
1170 } | |
1171 if (list) pst_free_list(list); | |
1172 list = NULL; | |
1173 id_ptr = pst_getID2(id2_head, attach->id2_val); | |
1174 if (id_ptr) { | |
1175 DEBUG_WARN(("second pass attachment updating id2 found id %#"PRIx64"\n", id_ptr->id)); | |
1176 // id2_val has been updated to the ID2 value of the datablock containing the | |
1177 // attachment data | |
1178 attach->id_val = id_ptr->id; | |
1179 } else { | |
1180 DEBUG_WARN(("have not located the correct value for the attachment [%#"PRIx64"]\n", attach->id2_val)); | |
1181 } | |
1182 } else { | |
1183 DEBUG_WARN(("ERROR cannot locate id2 value %#"PRIx64"\n", attach->id2_val)); | |
1184 attach->id2_val = 0; // suppress this missing attachment | |
1185 } | |
1186 attach = attach->next; | |
1187 } | |
1188 } | |
1189 } | |
1190 | |
1191 if (id2_head) pst_free_id2(id2_head); | |
1192 DEBUG_RET(); | 1207 DEBUG_RET(); |
1193 return item; | 1208 return item; |
1194 } | 1209 } |
1195 | 1210 |
1196 | 1211 |
1506 } | 1521 } |
1507 fr_ptr += sizeof(table2_rec); | 1522 fr_ptr += sizeof(table2_rec); |
1508 } else { | 1523 } else { |
1509 WARN(("Missing code for block_type %i\n", block_type)); | 1524 WARN(("Missing code for block_type %i\n", block_type)); |
1510 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | 1525 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); |
1511 if (na_head) pst_free_list(na_head); | 1526 pst_free_list(na_head); |
1512 DEBUG_RET(); | 1527 DEBUG_RET(); |
1513 return NULL; | 1528 return NULL; |
1514 } | 1529 } |
1515 DEBUG_EMAIL(("reading block %i (type=%#x, ref_type=%#x, value=%#x)\n", | 1530 DEBUG_EMAIL(("reading block %i (type=%#x, ref_type=%#x, value=%#x)\n", |
1516 x, table_rec.type, table_rec.ref_type, table_rec.value)); | 1531 x, table_rec.type, table_rec.ref_type, table_rec.value)); |
1664 } | 1679 } |
1665 if (na_ptr->items[x]->type == 0) na_ptr->items[x]->type = table_rec.ref_type; | 1680 if (na_ptr->items[x]->type == 0) na_ptr->items[x]->type = table_rec.ref_type; |
1666 } else { | 1681 } else { |
1667 WARN(("ERROR Unknown ref_type %#hx\n", table_rec.ref_type)); | 1682 WARN(("ERROR Unknown ref_type %#hx\n", table_rec.ref_type)); |
1668 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | 1683 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); |
1669 if (na_head) pst_free_list(na_head); | 1684 pst_free_list(na_head); |
1670 DEBUG_RET(); | 1685 DEBUG_RET(); |
1671 return NULL; | 1686 return NULL; |
1672 } | 1687 } |
1673 x++; | 1688 x++; |
1674 } | 1689 } |
3637 free(list->items[x]); | 3652 free(list->items[x]); |
3638 } | 3653 } |
3639 } | 3654 } |
3640 free(list->items); | 3655 free(list->items); |
3641 } | 3656 } |
3642 l = list; | 3657 l = list->next; |
3643 list = list->next; | 3658 free (list); |
3644 free (l); | 3659 list = l; |
3645 } | 3660 } |
3646 DEBUG_RET(); | 3661 DEBUG_RET(); |
3647 } | 3662 } |
3648 | 3663 |
3649 | 3664 |
3777 DEBUG_RET(); | 3792 DEBUG_RET(); |
3778 return head; | 3793 return head; |
3779 } | 3794 } |
3780 | 3795 |
3781 | 3796 |
3797 void pst_free_attach(pst_item_attach *attach) { | |
3798 while (attach) { | |
3799 pst_item_attach *t; | |
3800 SAFE_FREE(attach->filename1); | |
3801 SAFE_FREE(attach->filename2); | |
3802 SAFE_FREE(attach->mimetype); | |
3803 SAFE_FREE(attach->data); | |
3804 pst_free_id2(attach->id2_head); | |
3805 t = attach->next; | |
3806 free(attach); | |
3807 attach = t; | |
3808 } | |
3809 } | |
3810 | |
3811 | |
3782 void pst_freeItem(pst_item *item) { | 3812 void pst_freeItem(pst_item *item) { |
3783 pst_item_attach *t; | |
3784 pst_item_extra_field *et; | 3813 pst_item_extra_field *et; |
3785 | 3814 |
3786 DEBUG_ENT("pst_freeItem"); | 3815 DEBUG_ENT("pst_freeItem"); |
3787 if (item) { | 3816 if (item) { |
3788 if (item->email) { | 3817 if (item->email) { |
3942 SAFE_FREE(item->contact->work_address_postalcode); | 3971 SAFE_FREE(item->contact->work_address_postalcode); |
3943 SAFE_FREE(item->contact->work_address_country); | 3972 SAFE_FREE(item->contact->work_address_country); |
3944 SAFE_FREE(item->contact->work_address_postofficebox); | 3973 SAFE_FREE(item->contact->work_address_postofficebox); |
3945 free(item->contact); | 3974 free(item->contact); |
3946 } | 3975 } |
3947 while (item->attach) { | 3976 |
3948 SAFE_FREE(item->attach->filename1); | 3977 pst_free_attach(item->attach); |
3949 SAFE_FREE(item->attach->filename2); | 3978 |
3950 SAFE_FREE(item->attach->mimetype); | |
3951 SAFE_FREE(item->attach->data); | |
3952 t = item->attach->next; | |
3953 free(item->attach); | |
3954 item->attach = t; | |
3955 } | |
3956 while (item->extra_fields) { | 3979 while (item->extra_fields) { |
3957 SAFE_FREE(item->extra_fields->field_name); | 3980 SAFE_FREE(item->extra_fields->field_name); |
3958 SAFE_FREE(item->extra_fields->value); | 3981 SAFE_FREE(item->extra_fields->value); |
3959 et = item->extra_fields->next; | 3982 et = item->extra_fields->next; |
3960 free(item->extra_fields); | 3983 free(item->extra_fields); |
4090 DEBUG_RET(); | 4113 DEBUG_RET(); |
4091 return ptr; | 4114 return ptr; |
4092 } | 4115 } |
4093 | 4116 |
4094 | 4117 |
4095 pst_index_ll *pst_getID2(pst_index2_ll *head, uint64_t id) { | 4118 pst_index2_ll *pst_getID2(pst_index2_ll *head, uint64_t id2) { |
4096 DEBUG_ENT("pst_getID2"); | 4119 DEBUG_ENT("pst_getID2"); |
4097 DEBUG_INDEX(("looking for id = %#"PRIx64"\n", id)); | 4120 DEBUG_INDEX(("looking for id2 = %#"PRIx64"\n", id2)); |
4098 pst_index2_ll *ptr = head; | 4121 pst_index2_ll *ptr = head; |
4099 while (ptr) { | 4122 while (ptr) { |
4100 if (ptr->id2 == id) break; | 4123 if (ptr->id2 == id2) break; |
4101 if (ptr->child) { | 4124 if (ptr->child) { |
4102 pst_index_ll *rc = pst_getID2(ptr->child, id); | 4125 pst_index2_ll *rc = pst_getID2(ptr->child, id2); |
4103 if (rc) { | 4126 if (rc) { |
4104 DEBUG_RET(); | 4127 DEBUG_RET(); |
4105 return rc; | 4128 return rc; |
4106 } | 4129 } |
4107 } | 4130 } |
4108 ptr = ptr->next; | 4131 ptr = ptr->next; |
4109 } | 4132 } |
4110 if (ptr) { | 4133 if (ptr && ptr->id) { |
4111 if (ptr->id) {DEBUG_INDEX(("Found value %#"PRIx64"\n", ptr->id->id)); } | 4134 DEBUG_INDEX(("Found value %#"PRIx64"\n", ptr->id->id)); |
4112 else {DEBUG_INDEX(("Found value, though it is NULL!\n"));} | |
4113 DEBUG_RET(); | 4135 DEBUG_RET(); |
4114 return ptr->id; | 4136 return ptr; |
4115 } | 4137 } |
4116 //DEBUG_INDEX(("ERROR Not Found\n")); | 4138 DEBUG_INDEX(("ERROR Not Found\n")); |
4117 DEBUG_RET(); | 4139 DEBUG_RET(); |
4118 return NULL; | 4140 return NULL; |
4119 } | 4141 } |
4120 | 4142 |
4121 | 4143 |
4394 | 4416 |
4395 | 4417 |
4396 #define PST_PTR_BLOCK_SIZE 0x120 | 4418 #define PST_PTR_BLOCK_SIZE 0x120 |
4397 size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_index2_ll *id2_head, char** buf) { | 4419 size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_index2_ll *id2_head, char** buf) { |
4398 size_t ret; | 4420 size_t ret; |
4399 pst_index_ll* ptr; | 4421 pst_index2_ll* ptr; |
4400 pst_holder h = {buf, NULL, 0}; | 4422 pst_holder h = {buf, NULL, 0}; |
4401 DEBUG_ENT("pst_ff_getID2block"); | 4423 DEBUG_ENT("pst_ff_getID2block"); |
4402 ptr = pst_getID2(id2_head, id2); | 4424 ptr = pst_getID2(id2_head, id2); |
4403 | 4425 |
4404 if (!ptr) { | 4426 if (!ptr) { |
4405 DEBUG_INDEX(("Cannot find id2 value %#x\n", id2)); | 4427 DEBUG_INDEX(("Cannot find id2 value %#x\n", id2)); |
4406 DEBUG_RET(); | 4428 DEBUG_RET(); |
4407 return 0; | 4429 return 0; |
4408 } | 4430 } |
4409 ret = pst_ff_getID2data(pf, ptr, &h); | 4431 ret = pst_ff_getID2data(pf, ptr->id, &h); |
4410 DEBUG_RET(); | 4432 DEBUG_RET(); |
4411 return ret; | 4433 return ret; |
4412 } | 4434 } |
4413 | 4435 |
4414 | 4436 |