comparison src/libpst.c @ 73:3cb02cb1e6cd stable-0-6-10

Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them). More changes for Fedora packaging (#434727) Fixes for const correctness.
author Carl Byington <carl@five-ten-sg.com>
date Thu, 29 May 2008 18:51:02 -0700
parents 63c02a242ca9
children 987aa872294e
comparison
equal deleted inserted replaced
72:c21e9c001256 73:3cb02cb1e6cd
867 DEBUG_INDEX(("Cache addition\n")); 867 DEBUG_INDEX(("Cache addition\n"));
868 cache_ptr = (struct cache_list_node*) xmalloc(sizeof(struct cache_list_node)); 868 cache_ptr = (struct cache_list_node*) xmalloc(sizeof(struct cache_list_node));
869 cache_ptr->prev = NULL; 869 cache_ptr->prev = NULL;
870 cache_ptr->next = cache_head; 870 cache_ptr->next = cache_head;
871 cache_ptr->ptr = parent; 871 cache_ptr->ptr = parent;
872 if (cache_head) cache_head->prev = cache_ptr;
873 if (!cache_tail) cache_tail = cache_ptr;
872 cache_head = cache_ptr; 874 cache_head = cache_ptr;
873 if (!cache_tail) cache_tail = cache_ptr;
874 cache_count++; 875 cache_count++;
875 if (cache_count > 100) { 876 if (cache_count > 100) {
876 DEBUG_INDEX(("trimming quick cache\n")); 877 DEBUG_INDEX(("trimming quick cache\n"));
877 //remove one from the end 878 //remove one from the end
878 cache_ptr = cache_tail; 879 cache_ptr = cache_tail;
879 cache_tail = cache_ptr->prev; 880 cache_tail = cache_ptr->prev;
881 if (cache_tail) cache_tail->next = NULL;
880 free (cache_ptr); 882 free (cache_ptr);
881 cache_count--; 883 cache_count--;
882 } 884 }
883 } 885 }
884 DEBUG_INDEX(("Found a parent\n")); 886 DEBUG_INDEX(("Found a parent\n"));
1289 int count_rec; 1291 int count_rec;
1290 int32_t num_list; 1292 int32_t num_list;
1291 int32_t cur_list; 1293 int32_t cur_list;
1292 int block_type; 1294 int block_type;
1293 uint32_t rec_size = 0; 1295 uint32_t rec_size = 0;
1294 unsigned char* list_start; 1296 char* list_start;
1295 unsigned char* fr_ptr; 1297 char* fr_ptr;
1296 unsigned char* to_ptr; 1298 char* to_ptr;
1297 unsigned char* ind2_end = NULL; 1299 char* ind2_end = NULL;
1298 unsigned char* ind2_ptr = NULL; 1300 char* ind2_ptr = NULL;
1299 pst_x_attrib_ll *mapptr; 1301 pst_x_attrib_ll *mapptr;
1300 pst_block_hdr block_hdr; 1302 pst_block_hdr block_hdr;
1301 pst_table3_rec table3_rec; //for type 3 (0x0101) blocks 1303 pst_table3_rec table3_rec; //for type 3 (0x0101) blocks
1302 1304
1303 struct { 1305 struct {
1515 1517
1516 DEBUG_EMAIL(("going to read %i (%#x) items\n", na_ptr->count_item, na_ptr->count_item)); 1518 DEBUG_EMAIL(("going to read %i (%#x) items\n", na_ptr->count_item, na_ptr->count_item));
1517 1519
1518 fr_ptr = list_start; // initialize fr_ptr to the start of the list. 1520 fr_ptr = list_start; // initialize fr_ptr to the start of the list.
1519 for (cur_list=0; cur_list<num_list; cur_list++) { //we will increase fr_ptr as we progress through index 1521 for (cur_list=0; cur_list<num_list; cur_list++) { //we will increase fr_ptr as we progress through index
1520 unsigned char* value_pointer = NULL; // needed for block type 2 with values larger than 4 bytes 1522 char* value_pointer = NULL; // needed for block type 2 with values larger than 4 bytes
1521 size_t value_size = 0; 1523 size_t value_size = 0;
1522 if (block_type == 1) { 1524 if (block_type == 1) {
1523 memcpy(&table_rec, fr_ptr, sizeof(table_rec)); 1525 memcpy(&table_rec, fr_ptr, sizeof(table_rec));
1524 LE16_CPU(table_rec.type); 1526 LE16_CPU(table_rec.type);
1525 LE16_CPU(table_rec.ref_type); 1527 LE16_CPU(table_rec.ref_type);
1629 table_rec.ref_type == (uint16_t)0x0048 || 1631 table_rec.ref_type == (uint16_t)0x0048 ||
1630 table_rec.ref_type == (uint16_t)0x0102 || 1632 table_rec.ref_type == (uint16_t)0x0102 ||
1631 table_rec.ref_type == (uint16_t)0x1003 || 1633 table_rec.ref_type == (uint16_t)0x1003 ||
1632 table_rec.ref_type == (uint16_t)0x1014 || 1634 table_rec.ref_type == (uint16_t)0x1014 ||
1633 table_rec.ref_type == (uint16_t)0x101e || 1635 table_rec.ref_type == (uint16_t)0x101e ||
1636 table_rec.ref_type == (uint16_t)0x101f ||
1634 table_rec.ref_type == (uint16_t)0x1102) { 1637 table_rec.ref_type == (uint16_t)0x1102) {
1635 //contains index reference to data 1638 //contains index reference to data
1636 LE32_CPU(table_rec.value); 1639 LE32_CPU(table_rec.value);
1637 if (value_pointer) { 1640 if (value_pointer) {
1638 // in a type 2 block, with a value that is more than 4 bytes 1641 // in a type 2 block, with a value that is more than 4 bytes
3557 list->items[x]->size)); 3560 list->items[x]->size));
3558 DEBUG_HEXDUMP(list->items[x]->data, list->items[x]->size); 3561 DEBUG_HEXDUMP(list->items[x]->data, list->items[x]->size);
3559 3562
3560 } else if (list->items[x]->type == (uint32_t)0x101E) { 3563 } else if (list->items[x]->type == (uint32_t)0x101E) {
3561 DEBUG_EMAIL(("Unknown type %#x Array of Strings [size = %#x]\n", list->items[x]->id, 3564 DEBUG_EMAIL(("Unknown type %#x Array of Strings [size = %#x]\n", list->items[x]->id,
3565 list->items[x]->size));
3566 DEBUG_HEXDUMP(list->items[x]->data, list->items[x]->size);
3567
3568 } else if (list->items[x]->type == (uint32_t)0x101F) {
3569 DEBUG_EMAIL(("Unknown type %#x Array of Unicode Strings [size = %#x]\n", list->items[x]->id,
3562 list->items[x]->size)); 3570 list->items[x]->size));
3563 DEBUG_HEXDUMP(list->items[x]->data, list->items[x]->size); 3571 DEBUG_HEXDUMP(list->items[x]->data, list->items[x]->size);
3564 3572
3565 } else if (list->items[x]->type == (uint32_t)0x1102) { 3573 } else if (list->items[x]->type == (uint32_t)0x1102) {
3566 DEBUG_EMAIL(("Unknown type %#x Array of binary data blobs [size = %#x]\n", list->items[x]->id, 3574 DEBUG_EMAIL(("Unknown type %#x Array of binary data blobs [size = %#x]\n", list->items[x]->id,
4182 DEBUG_RET(); 4190 DEBUG_RET();
4183 return rsize; 4191 return rsize;
4184 } 4192 }
4185 4193
4186 4194
4187 int pst_decrypt(unsigned char *buf, size_t size, unsigned char type) { 4195 int pst_decrypt(char *buf, size_t size, unsigned char type) {
4188 size_t x = 0; 4196 size_t x = 0;
4189 unsigned char y; 4197 unsigned char y;
4190 DEBUG_ENT("pst_decrypt"); 4198 DEBUG_ENT("pst_decrypt");
4191 if (!buf) { 4199 if (!buf) {
4192 DEBUG_RET(); 4200 DEBUG_RET();
4194 } 4202 }
4195 4203
4196 if (type == PST_COMP_ENCRYPT) { 4204 if (type == PST_COMP_ENCRYPT) {
4197 x = 0; 4205 x = 0;
4198 while (x < size) { 4206 while (x < size) {
4199 y = buf[x]; 4207 y = (unsigned char)(buf[x]);
4200 DEBUG_DECRYPT(("Transposing %#hhx to %#hhx [%#x]\n", buf[x], comp_enc[y], y)); 4208 DEBUG_DECRYPT(("Transposing %#hhx to %#hhx [%#x]\n", buf[x], comp_enc[y], y));
4201 buf[x] = comp_enc[y]; // transpose from encrypt array 4209 buf[x] = (char)comp_enc[y]; // transpose from encrypt array
4202 x++; 4210 x++;
4203 } 4211 }
4204 } else { 4212 } else {
4205 WARN(("Unknown encryption: %i. Cannot decrypt\n", type)); 4213 WARN(("Unknown encryption: %i. Cannot decrypt\n", type));
4206 DEBUG_RET(); 4214 DEBUG_RET();
4390 4398
4391 4399
4392 size_t pst_ff_compile_ID(pst_file *pf, uint64_t id, pst_holder *h, size_t size) { 4400 size_t pst_ff_compile_ID(pst_file *pf, uint64_t id, pst_holder *h, size_t size) {
4393 size_t z, a, b; 4401 size_t z, a, b;
4394 uint16_t count, y; 4402 uint16_t count, y;
4395 char * buf3 = NULL, *buf2 = NULL, *t; 4403 char *buf3 = NULL, *buf2 = NULL, *t;
4396 char *b_ptr; 4404 char *b_ptr;
4397 pst_block_hdr block_hdr; 4405 pst_block_hdr block_hdr;
4398 pst_table3_rec table3_rec; //for type 3 (0x0101) blocks 4406 pst_table3_rec table3_rec; //for type 3 (0x0101) blocks
4399 4407
4400 DEBUG_ENT("pst_ff_compile_ID"); 4408 DEBUG_ENT("pst_ff_compile_ID");
4548 else 4556 else
4549 return 1; 4557 return 1;
4550 } 4558 }
4551 4559
4552 4560
4553 size_t pst_fwrite(const void*ptr, size_t size, size_t nmemb, FILE*stream) { 4561 size_t pst_fwrite(const void* ptr, size_t size, size_t nmemb, FILE *stream) {
4554 size_t r; 4562 size_t r;
4555 DEBUG_ENT("pst_fwrite"); 4563 DEBUG_ENT("pst_fwrite");
4556 if (ptr) 4564 if (ptr)
4557 r = fwrite(ptr, size, nmemb, stream); 4565 r = fwrite(ptr, size, nmemb, stream);
4558 else { 4566 else {