comparison src/libpst.c @ 93:cb14583c119a

iconv changes for Mac
author Carl Byington <carl@five-ten-sg.com>
date Thu, 28 Aug 2008 15:25:53 -0700
parents 3ec5ad97e926
children 997cf1373f9e
comparison
equal deleted inserted replaced
92:93ce964a3f92 93:cb14583c119a
288 288
289 289
290 size_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp) { 290 size_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp) {
291 pst_index_ll *ptr; 291 pst_index_ll *ptr;
292 pst_holder h = {NULL, fp, 0, "", 0}; 292 pst_holder h = {NULL, fp, 0, "", 0};
293 size_t size; 293 size_t size = 0;
294 int32_t x;
294 DEBUG_ENT("pst_attach_to_file"); 295 DEBUG_ENT("pst_attach_to_file");
295 if (attach->id_val != (uint64_t)-1) { 296 if (attach->id_val != (uint64_t)-1) {
296 ptr = pst_getID(pf, attach->id_val); 297 ptr = pst_getID(pf, attach->id_val);
297 if (ptr) { 298 if (ptr) {
299 // pst_num_array *list = pst_parse_block(pf, ptr->id, NULL, NULL);
300 // DEBUG_WARN(("writing file data attachment\n"));
301 // for (x=0; x<list->count_item; x++) {
302 // DEBUG_HEXDUMPC(list->items[x]->data, list->items[x]->size, 0x10);
303 // (void)pst_fwrite(list->items[x]->data, (size_t)1, list->items[x]->size, fp);
304 // }
298 size = pst_ff_getID2data(pf, ptr, &h); 305 size = pst_ff_getID2data(pf, ptr, &h);
299 } else { 306 } else {
300 DEBUG_WARN(("Couldn't find ID pointer. Cannot save attachment to file\n")); 307 DEBUG_WARN(("Couldn't find ID pointer. Cannot save attachment to file\n"));
301 size = 0;
302 } 308 }
303 attach->size = size; 309 attach->size = size;
304 } else { 310 } else {
305 // save the attachment to file 311 // save the attachment to file
306 size = attach->size; 312 size = attach->size;
312 318
313 319
314 size_t pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp) { 320 size_t pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp) {
315 pst_index_ll *ptr; 321 pst_index_ll *ptr;
316 pst_holder h = {NULL, fp, 1, "", 0}; 322 pst_holder h = {NULL, fp, 1, "", 0};
317 size_t size; 323 size_t size = 0;
324 int32_t x;
318 char *c; 325 char *c;
319 DEBUG_ENT("pst_attach_to_file_base64"); 326 DEBUG_ENT("pst_attach_to_file_base64");
320 if (attach->id_val != (uint64_t)-1) { 327 if (attach->id_val != (uint64_t)-1) {
321 ptr = pst_getID(pf, attach->id_val); 328 ptr = pst_getID(pf, attach->id_val);
322 if (ptr) { 329 if (ptr) {
330 // pst_num_array *list = pst_parse_block(pf, ptr->id, NULL, NULL);
331 // DEBUG_WARN(("writing base64 data attachment\n"));
332 // for (x=0; x<list->count_item; x++) {
333 // DEBUG_HEXDUMPC(list->items[x]->data, list->items[x]->size, 0x10);
334 // c = base64_encode(list->items[x]->data, list->items[x]->size);
335 // if (c) {
336 // (void)pst_fwrite(c, (size_t)1, strlen(c), fp);
337 // free(c); // caught by valgrind
338 // }
339 // }
323 size = pst_ff_getID2data(pf, ptr, &h); 340 size = pst_ff_getID2data(pf, ptr, &h);
324 // will need to encode any bytes left over 341 // will need to encode any bytes left over
325 c = base64_encode(h.base64_extra_chars, (size_t)h.base64_extra); 342 c = base64_encode(h.base64_extra_chars, (size_t)h.base64_extra);
326 if (c) { 343 if (c) {
327 (void)pst_fwrite(c, (size_t)1, strlen(c), fp); 344 (void)pst_fwrite(c, (size_t)1, strlen(c), fp);
328 free(c); // caught by valgrind 345 free(c); // caught by valgrind
329 } 346 }
330 } else { 347 } else {
331 DEBUG_WARN (("Couldn't find ID pointer. Cannot save attachment to Base64\n")); 348 DEBUG_WARN(("Couldn't find ID pointer. Cannot save attachment to Base64\n"));
332 size = 0;
333 } 349 }
334 attach->size = size; 350 attach->size = size;
335 } else { 351 } else {
336 // encode the attachment to the file 352 // encode the attachment to the file
337 c = base64_encode(attach->data, attach->size); 353 c = base64_encode(attach->data, attach->size);
429 if (id2_head) pst_free_id2(id2_head); 445 if (id2_head) pst_free_id2(id2_head);
430 DEBUG_RET(); 446 DEBUG_RET();
431 return 0; 447 return 0;
432 } 448 }
433 449
434 x = 0; 450 for (x=0; x < na->count_item; x++) {
435 while (x < na->count_item) {
436 if (na->items[x]->id == (uint32_t)0x0003) { 451 if (na->items[x]->id == (uint32_t)0x0003) {
437 buffer = na->items[x]->data; 452 buffer = na->items[x]->data;
438 bsize = na->items[x]->size; 453 bsize = na->items[x]->size;
439 } else if (na->items[x]->id == (uint32_t)0x0004) { 454 } else if (na->items[x]->id == (uint32_t)0x0004) {
440 headerbuffer = na->items[x]->data; 455 headerbuffer = na->items[x]->data;
441 hsize = na->items[x]->size; 456 hsize = na->items[x]->size;
442 } else { 457 } else {
443 // leave them null 458 // leave them null
444 } 459 }
445 x++;
446 } 460 }
447 461
448 if (!buffer) { 462 if (!buffer) {
449 if (na) pst_free_list(na); 463 if (na) pst_free_list(na);
450 DEBUG_WARN(("No extended attributes buffer found. Not processing\n")); 464 DEBUG_WARN(("No extended attributes buffer found. Not processing\n"));
1202 DEBUG_RET(); 1216 DEBUG_RET();
1203 //return NULL; 1217 //return NULL;
1204 return item; 1218 return item;
1205 } 1219 }
1206 else { 1220 else {
1207 x = 0; 1221 for (x=0; x < list->count_array; x++) {
1208 while (x < list->count_array) { 1222 attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach));
1209 attach = (pst_item_attach*) xmalloc (sizeof(pst_item_attach)); 1223 memset(attach, 0, sizeof(pst_item_attach));
1210 memset (attach, 0, sizeof(pst_item_attach));
1211 attach->next = item->attach; 1224 attach->next = item->attach;
1212 item->attach = attach; 1225 item->attach = attach;
1213 x++;
1214 } 1226 }
1215 1227
1216 if (pst_process(list, item, item->attach)) { 1228 if (pst_process(list, item, item->attach)) {
1217 DEBUG_WARN(("ERROR pst_process() failed with attachments\n")); 1229 DEBUG_WARN(("ERROR pst_process() failed with attachments\n"));
1218 if (item) pst_freeItem(item); 1230 if (item) pst_freeItem(item);
4434 } else { 4446 } else {
4435 // here we will assume it is a block that points to others 4447 // here we will assume it is a block that points to others
4436 DEBUG_READ(("Assuming it is a multi-block record because of it's id\n")); 4448 DEBUG_READ(("Assuming it is a multi-block record because of it's id\n"));
4437 ret = pst_ff_compile_ID(pf, ptr->id, h, (size_t)0); 4449 ret = pst_ff_compile_ID(pf, ptr->id, h, (size_t)0);
4438 } 4450 }
4439 // bogus null termination off the end of the buffer!!
4440 //if (h->buf && *h->buf) (*(h->buf))[ret]='\0';
4441 DEBUG_RET(); 4451 DEBUG_RET();
4442 return ret; 4452 return ret;
4443 } 4453 }
4444 4454
4445 4455