Mercurial > libpst
annotate src/libpst.c @ 45:b961bcdadd0e
more fixes for 64 bit format
author | carl |
---|---|
date | Tue, 08 Jan 2008 16:33:23 -0800 |
parents | d4606d460daf |
children | b2a7f2e0926a |
rev | line source |
---|---|
16 | 1 /*** |
2 * libpst.c | |
3 * Part of the LibPST project | |
4 * Written by David Smith | |
43 | 5 * dave.s@earthcorp.com |
16 | 6 */ |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <time.h> | |
10 #include <string.h> | |
11 #include <ctype.h> | |
12 #include <limits.h> | |
13 #include <wchar.h> | |
43 | 14 #include <signal.h> |
16 | 15 #include <errno.h> |
43 | 16 #include <sys/stat.h> // mkdir |
17 #include <fcntl.h> // for Win32 definition of _O_BINARY | |
16 | 18 #include "define.h" |
19 #include "libstrfunc.h" | |
43 | 20 #include "vbuf.h" |
21 | |
22 #define ASSERT(x) { if(!(x)) raise( SIGSEGV ); } | |
16 | 23 |
24 #ifdef _MSC_VER | |
25 # include <windows.h> | |
26 #else | |
27 # include <unistd.h> | |
28 #endif //ifdef _MSC_VER | |
29 | |
30 #include "libpst.h" | |
31 #include "timeconv.h" | |
44 | 32 //efine INDEX_DEPTH 0x4C |
33 //efine SECOND_DEPTH 0x5C | |
43 | 34 #define INDEX_TYPE32 0x0E |
35 #define INDEX_TYPE64 0x17 | |
36 | |
37 #define FILE_SIZE_POINTER32 0xA8 | |
38 #define INDEX_POINTER32 0xC4 | |
39 #define INDEX_COUNT32 0xC0 | |
40 #define SECOND_POINTER32 0xBC | |
41 #define SECOND_COUNT32 0xB8 | |
42 #define INDEX_TYPE_OFFSET32 0x0A | |
43 #define ENC_OFFSET32 0x1CD | |
44 | |
45 #define FILE_SIZE_POINTER64 0xB8 | |
46 #define INDEX_POINTER64 0xF0 | |
47 #define INDEX_COUNT64 0xE8 | |
48 #define SECOND_POINTER64 0xE0 | |
49 #define SECOND_COUNT64 0xD8 | |
50 #define INDEX_TYPE_OFFSET64 0x0A | |
51 #define ENC_OFFSET64 0x201 | |
52 | |
53 #define FILE_SIZE_POINTER ((do_read64) ? FILE_SIZE_POINTER64 : FILE_SIZE_POINTER32) | |
54 #define INDEX_POINTER ((do_read64) ? INDEX_POINTER64 : INDEX_POINTER32) | |
55 #define INDEX_COUNT ((do_read64) ? INDEX_COUNT64 : INDEX_COUNT32) | |
56 #define SECOND_POINTER ((do_read64) ? SECOND_POINTER64 : SECOND_POINTER32) | |
57 #define SECOND_COUNT ((do_read64) ? SECOND_COUNT64 : SECOND_COUNT32) | |
58 #define INDEX_TYPE_OFFSET ((do_read64) ? INDEX_TYPE_OFFSET64 : INDEX_TYPE_OFFSET32) | |
59 #define INDEX_TYPE ((do_read64) ? INDEX_TYPE64 : INDEX_TYPE32) | |
60 #define ENC_OFFSET ((do_read64) ? ENC_OFFSET64 : ENC_OFFSET32) | |
16 | 61 |
62 #define PST_SIGNATURE 0x4E444221 | |
63 | |
43 | 64 int do_read64 = 0; //set this to 1 in order to try and read 64-bit pst files (Outlook 2003) |
65 | |
66 struct _pst_table_ptr_struct32{ | |
67 int32_t start; | |
68 int32_t u1; | |
69 int32_t offset; | |
70 }; | |
71 struct _pst_table_ptr_structn{ | |
72 int64_t start; | |
73 int64_t u1; | |
74 int64_t offset; | |
16 | 75 }; |
76 | |
77 typedef struct _pst_block_header { | |
43 | 78 int16_t type; |
79 int16_t count; | |
16 | 80 } pst_block_header; |
81 | |
82 typedef struct _pst_id2_assoc { | |
43 | 83 uint32_t id2; |
84 uint32_t id; | |
85 int32_t table2; | |
16 | 86 } pst_id2_assoc; |
87 | |
35 | 88 // this is an array of the un-encrypted values. the un-encrypted value is in the position |
16 | 89 // of the encrypted value. ie the encrypted value 0x13 represents 0x02 |
43 | 90 // 0 1 2 3 4 5 6 7 |
91 // 8 9 a b c d e f | |
16 | 92 unsigned char comp_enc [] = |
93 { 0x47, 0xf1, 0xb4, 0xe6, 0x0b, 0x6a, 0x72, 0x48, | |
43 | 94 0x85, 0x4e, 0x9e, 0xeb, 0xe2, 0xf8, 0x94, 0x53, /*0x0f*/ |
95 0xe0, 0xbb, 0xa0, 0x02, 0xe8, 0x5a, 0x09, 0xab, | |
96 0xdb, 0xe3, 0xba, 0xc6, 0x7c, 0xc3, 0x10, 0xdd, /*0x1f*/ | |
97 0x39, 0x05, 0x96, 0x30, 0xf5, 0x37, 0x60, 0x82, | |
98 0x8c, 0xc9, 0x13, 0x4a, 0x6b, 0x1d, 0xf3, 0xfb, /*0x2f*/ | |
99 0x8f, 0x26, 0x97, 0xca, 0x91, 0x17, 0x01, 0xc4, | |
100 0x32, 0x2d, 0x6e, 0x31, 0x95, 0xff, 0xd9, 0x23, /*0x3f*/ | |
101 0xd1, 0x00, 0x5e, 0x79, 0xdc, 0x44, 0x3b, 0x1a, | |
102 0x28, 0xc5, 0x61, 0x57, 0x20, 0x90, 0x3d, 0x83, /*0x4f*/ | |
103 0xb9, 0x43, 0xbe, 0x67, 0xd2, 0x46, 0x42, 0x76, | |
104 0xc0, 0x6d, 0x5b, 0x7e, 0xb2, 0x0f, 0x16, 0x29, /*0x5f*/ | |
105 0x3c, 0xa9, 0x03, 0x54, 0x0d, 0xda, 0x5d, 0xdf, | |
106 0xf6, 0xb7, 0xc7, 0x62, 0xcd, 0x8d, 0x06, 0xd3, /*0x6f*/ | |
107 0x69, 0x5c, 0x86, 0xd6, 0x14, 0xf7, 0xa5, 0x66, | |
108 0x75, 0xac, 0xb1, 0xe9, 0x45, 0x21, 0x70, 0x0c, /*0x7f*/ | |
109 0x87, 0x9f, 0x74, 0xa4, 0x22, 0x4c, 0x6f, 0xbf, | |
110 0x1f, 0x56, 0xaa, 0x2e, 0xb3, 0x78, 0x33, 0x50, /*0x8f*/ | |
111 0xb0, 0xa3, 0x92, 0xbc, 0xcf, 0x19, 0x1c, 0xa7, | |
112 0x63, 0xcb, 0x1e, 0x4d, 0x3e, 0x4b, 0x1b, 0x9b, /*0x9f*/ | |
113 0x4f, 0xe7, 0xf0, 0xee, 0xad, 0x3a, 0xb5, 0x59, | |
114 0x04, 0xea, 0x40, 0x55, 0x25, 0x51, 0xe5, 0x7a, /*0xaf*/ | |
115 0x89, 0x38, 0x68, 0x52, 0x7b, 0xfc, 0x27, 0xae, | |
116 0xd7, 0xbd, 0xfa, 0x07, 0xf4, 0xcc, 0x8e, 0x5f, /*0xbf*/ | |
117 0xef, 0x35, 0x9c, 0x84, 0x2b, 0x15, 0xd5, 0x77, | |
118 0x34, 0x49, 0xb6, 0x12, 0x0a, 0x7f, 0x71, 0x88, /*0xcf*/ | |
119 0xfd, 0x9d, 0x18, 0x41, 0x7d, 0x93, 0xd8, 0x58, | |
120 0x2c, 0xce, 0xfe, 0x24, 0xaf, 0xde, 0xb8, 0x36, /*0xdf*/ | |
121 0xc8, 0xa1, 0x80, 0xa6, 0x99, 0x98, 0xa8, 0x2f, | |
122 0x0e, 0x81, 0x65, 0x73, 0xe4, 0xc2, 0xa2, 0x8a, /*0xef*/ | |
123 0xd4, 0xe1, 0x11, 0xd0, 0x08, 0x8b, 0x2a, 0xf2, | |
124 0xed, 0x9a, 0x64, 0x3f, 0xc1, 0x6c, 0xf9, 0xec}; /*0xff*/ | |
125 | |
126 | |
44 | 127 void dump_desc(off_t off, int depth, int i, pst_descn *desc_rec ) { |
43 | 128 //desc_rec->d_id = 0x0102030405060708; |
129 DEBUG_INDEX(("%08x [%i] Item(%#x) = [d_id = %#llx, desc_id = %#llx, " | |
130 "list_id = %#llx, parent_id = %#x, u1 = %#x] %#x %p %p\n", | |
131 off, | |
132 depth, i, desc_rec->d_id, | |
133 desc_rec->desc_id, desc_rec->list_id, desc_rec->parent_id, desc_rec->u1)); | |
134 DEBUG_HEXDUMPC( (char*)desc_rec, sizeof( pst_descn ), 0x10 ); | |
135 DEBUG_INDEX(("WTF? %d %x %x %x %x %x\n", | |
136 sizeof( uint32_t ), | |
137 (int)(&desc_rec->d_id) - (int)desc_rec, | |
138 (int)(&desc_rec->desc_id) - (int)desc_rec, | |
139 (int)(&desc_rec->list_id) - (int)desc_rec, | |
140 (int)(&desc_rec->parent_id) - (int)desc_rec, | |
141 (int)(&desc_rec->u1) - (int)desc_rec )); | |
142 } | |
143 | |
16 | 144 |
145 int32_t pst_open(pst_file *pf, char *name, char *mode) { | |
43 | 146 uint32_t sig; |
147 | |
45 | 148 unicode_init(); |
149 | |
43 | 150 DEBUG_ENT("pst_open"); |
151 | |
152 if (!pf) { | |
153 WARN (("cannot be passed a NULL pst_file\n")); | |
154 DEBUG_RET(); | |
155 return -1; | |
156 } | |
157 memset(pf, 0, sizeof(pst_file)); | |
16 | 158 |
31 | 159 #ifdef _MSC_VER |
43 | 160 // set the default open mode for windows |
161 _fmode = _O_BINARY; | |
31 | 162 #endif //_MSC_VER |
43 | 163 if ((pf->fp = fopen(name, mode)) == NULL) { |
164 WARN(("cannot open PST file. Error\n")); | |
165 DEBUG_RET(); | |
166 return -1; | |
167 } | |
168 | |
169 // Check pst file magic | |
170 if (fread(&sig, sizeof(sig), 1, pf->fp) == 0) { | |
171 fclose(pf->fp); | |
172 WARN(("cannot read signature from PST file. Closing on error\n")); | |
173 DEBUG_RET(); | |
174 return -1; | |
175 } | |
176 LE32_CPU(sig); | |
177 DEBUG_INFO(("sig = %X\n", sig)); | |
178 if (sig != PST_SIGNATURE) { | |
179 fclose(pf->fp); | |
180 WARN(("not a PST file that I know. Closing with error\n")); | |
181 DEBUG_RET(); | |
182 return -1; | |
183 } | |
184 | |
185 // read index type | |
186 do_read64 = 0; // start with 32 bit format | |
187 _pst_getAtPos(pf->fp, INDEX_TYPE_OFFSET, &(pf->ind_type), sizeof(unsigned char)); | |
188 DEBUG_INFO(("index_type = %i\n", pf->ind_type)); | |
189 if (pf->ind_type != INDEX_TYPE) { | |
190 // try with 64 bit format | |
191 do_read64 = 1; | |
192 if (pf->ind_type != INDEX_TYPE) { | |
193 WARN(("unknown .pst format, possibly newer than Outlook 2003 PST file?\n")); | |
194 DEBUG_RET(); | |
195 return -1; | |
196 } | |
44 | 197 else { |
198 WARN(("switching to 64 bit format...\n")); | |
199 } | |
43 | 200 } |
201 | |
202 // read encryption setting | |
203 _pst_getAtPos(pf->fp, ENC_OFFSET, &(pf->encryption), sizeof(unsigned char)); | |
204 DEBUG_INFO(("encrypt = %i\n", pf->encryption)); | |
205 | |
206 pf->index2_count = _pst_getIntAtPos(pf->fp, SECOND_COUNT); | |
207 pf->index2 = _pst_getIntAtPos(pf->fp, SECOND_POINTER ); | |
208 pf->size = _pst_getIntAtPos( pf->fp, FILE_SIZE_POINTER ); | |
209 DEBUG_INFO(("Pointer2 is %#X, count %i[%#x]\n", pf->index2, pf->index2_count, pf->index2_count)); | |
210 | |
211 pf->index1_count = _pst_getIntAtPos(pf->fp, INDEX_COUNT); | |
212 pf->index1 = _pst_getIntAtPos(pf->fp, INDEX_POINTER); | |
213 DEBUG_INFO(("Pointer1 is %#X, count %i[%#x]\n", pf->index1, pf->index1_count, pf->index1_count)); | |
214 | |
215 DEBUG_RET(); | |
216 return 0; | |
16 | 217 } |
218 | |
219 | |
220 int32_t pst_close(pst_file *pf) { | |
43 | 221 DEBUG_ENT("pst_close"); |
222 if (!pf->fp) { | |
223 WARN(("cannot close NULL fp\n")); | |
224 DEBUG_RET(); | |
225 return -1; | |
226 } | |
227 if (fclose(pf->fp)) { | |
228 WARN(("fclose returned non-zero value\n")); | |
229 DEBUG_RET(); | |
230 return -1; | |
231 } | |
232 // we must free the id linklist and the desc tree | |
233 _pst_free_id (pf->i_head); | |
234 _pst_free_desc (pf->d_head); | |
235 _pst_free_xattrib (pf->x_head); | |
236 DEBUG_RET(); | |
237 return 0; | |
16 | 238 } |
239 | |
240 | |
241 pst_desc_ll* pst_getTopOfFolders(pst_file *pf, pst_item *root) { | |
43 | 242 pst_desc_ll *ret; |
243 DEBUG_ENT("pst_getTopOfFolders"); | |
244 if (!root || !root->message_store) { | |
245 DEBUG_INDEX(("There isn't a top of folder record here.\n")); | |
246 ret = NULL; | |
247 } else if (!root->message_store->top_of_personal_folder) { | |
248 // this is the OST way | |
249 // ASSUMPTION: Top Of Folders record in PST files is *always* descid 0x2142 | |
250 ret = _pst_getDptr(pf, 0x2142); | |
251 } else { | |
252 ret = _pst_getDptr(pf, root->message_store->top_of_personal_folder->id); | |
253 } | |
254 DEBUG_RET(); | |
255 return ret; | |
16 | 256 } |
257 | |
258 | |
259 int32_t pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, unsigned char **b){ | |
43 | 260 int32_t size=0; |
261 pst_index_ll *ptr; | |
262 struct holder h = {b, NULL, 0, "", 0}; | |
263 DEBUG_ENT("pst_attach_to_mem"); | |
264 if (attach->id_val != -1) { | |
265 ptr = _pst_getID(pf, attach->id_val); | |
266 if (ptr) { | |
267 size = _pst_ff_getID2data(pf, ptr, &h); | |
268 } else { | |
269 DEBUG_WARN(("Couldn't find ID pointer. Cannot handle attachment\n")); | |
270 size = 0; | |
271 } | |
272 attach->size = size; // may as well update it to what is correct for this instance | |
273 } else { | |
274 size = attach->size; | |
275 } | |
276 DEBUG_RET(); | |
277 return size; | |
16 | 278 } |
279 | |
280 | |
281 int32_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp) { | |
43 | 282 pst_index_ll *ptr; |
283 struct holder h = {NULL, fp, 0, "", 0}; | |
284 int32_t size; | |
285 DEBUG_ENT("pst_attach_to_file"); | |
286 if (attach->id_val != -1) { | |
287 ptr = _pst_getID(pf, attach->id_val); | |
288 if (ptr) { | |
289 size = _pst_ff_getID2data(pf, ptr, &h); | |
290 } else { | |
291 DEBUG_WARN(("Couldn't find ID pointer. Cannot save attachment to file\n")); | |
292 size = 0; | |
293 } | |
294 attach->size = size; | |
295 } else { | |
296 // save the attachment to file | |
297 size = attach->size; | |
298 pst_fwrite(attach->data, 1, size, fp); | |
299 } | |
300 DEBUG_RET(); | |
301 return 1; | |
16 | 302 } |
303 | |
304 | |
305 int32_t pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp) { | |
43 | 306 pst_index_ll *ptr; |
307 struct holder h = {NULL, fp, 1, "", 0}; | |
308 int32_t size; | |
309 char *c; | |
310 DEBUG_ENT("pst_attach_to_file_base64"); | |
311 if (attach->id_val != -1) { | |
312 ptr = _pst_getID(pf, attach->id_val); | |
313 if (ptr) { | |
314 size = _pst_ff_getID2data(pf, ptr, &h); | |
315 // will need to encode any bytes left over | |
316 c = base64_encode(h.base64_extra_chars, h.base64_extra); | |
317 if (c) { | |
318 pst_fwrite(c, 1, strlen(c), fp); | |
319 free(c); // caught by valgrind | |
320 } | |
321 } else { | |
322 DEBUG_WARN (("Couldn't find ID pointer. Cannot save attachment to Base64\n")); | |
323 size = 0; | |
324 } | |
325 attach->size = size; | |
326 } else { | |
327 // encode the attachment to the file | |
328 c = base64_encode(attach->data, attach->size); | |
329 if (c) { | |
330 pst_fwrite(c, 1, strlen(c), fp); | |
331 free(c); // caught by valgrind | |
332 } | |
333 size = attach->size; | |
334 } | |
335 DEBUG_RET(); | |
336 return 1; | |
16 | 337 } |
338 | |
339 | |
340 int32_t pst_load_index (pst_file *pf) { | |
43 | 341 int32_t x; |
342 uint64_t y; | |
343 DEBUG_ENT("pst_load_index"); | |
344 if (!pf) { | |
345 WARN(("Cannot load index for a NULL pst_file\n")); | |
346 DEBUG_RET(); | |
347 return -1; | |
348 } | |
349 | |
350 x = _pst_build_id_ptr(pf, pf->index1, 0, pf->index1_count, 0, UINT64_MAX); | |
351 DEBUG_INDEX(("build id ptr returns %i\n", x)); | |
352 | |
353 y = 0; | |
354 x = _pst_build_desc_ptr(pf, pf->index2, 0, pf->index2_count, &y, 0x21, UINT64_MAX); | |
355 DEBUG_INDEX(("build desc ptr returns %i\n", x)); | |
356 | |
357 DEBUG_CODE(_pst_printDptr(pf);); | |
358 DEBUG_RET(); | |
359 return 0; | |
16 | 360 } |
361 | |
362 | |
363 pst_desc_ll* pst_getNextDptr(pst_desc_ll* d) { | |
43 | 364 pst_desc_ll* r = NULL; |
365 DEBUG_ENT("pst_getNextDptr"); | |
366 if (d) { | |
367 if ((r = d->child) == NULL) { | |
368 while (!d->next && d->parent) d = d->parent; | |
369 r = d->next; | |
370 } | |
371 } | |
372 DEBUG_RET(); | |
373 return r; | |
16 | 374 } |
375 | |
376 | |
377 typedef struct _pst_x_attrib { | |
43 | 378 uint16_t extended; |
379 uint16_t zero; | |
380 uint16_t type; | |
381 uint16_t map; | |
16 | 382 } pst_x_attrib; |
383 | |
384 | |
385 int32_t pst_load_extended_attributes(pst_file *pf) { | |
43 | 386 // for PST files this will load up ID2 0x61 and check it's "list" attribute. |
387 pst_desc_ll *p; | |
388 pst_num_array *na; | |
389 pst_index2_ll *list2 = NULL; | |
390 unsigned char * buffer=NULL, *headerbuffer=NULL;//, *tc; | |
391 pst_x_attrib xattrib; | |
392 int32_t bptr = 0, bsize, hsize, tint, err=0, x; | |
393 pst_x_attrib_ll *ptr, *p_head=NULL, *p_sh=NULL, *p_sh2=NULL; | |
394 | |
395 DEBUG_ENT("pst_loadExtendedAttributes"); | |
396 if ((p = _pst_getDptr(pf, 0x61)) == NULL) { | |
397 DEBUG_WARN(("Cannot find DescID 0x61 for loading the Extended Attributes\n")); | |
398 DEBUG_RET(); | |
399 return 0; | |
400 } | |
401 | |
402 if (!p->desc) { | |
403 DEBUG_WARN(("desc is NULL for item 0x61. Cannot load Extended Attributes\n")); | |
404 DEBUG_RET(); | |
405 return 0; | |
406 } | |
407 | |
408 if (p->list_index) { | |
409 list2 = _pst_build_id2(pf, p->list_index, NULL); | |
410 _pst_printID2ptr(list2); | |
411 } else { | |
412 DEBUG_WARN(("Have not been able to fetch any id2 values for item 0x61. Brace yourself!\n")); | |
413 } | |
414 | |
415 na = _pst_parse_block(pf, p->desc->id, list2); | |
416 if (!na) { | |
417 DEBUG_WARN(("Cannot process desc block for item 0x61. Not loading extended Attributes\n")); | |
418 if (list2) _pst_free_id2(list2); | |
419 DEBUG_RET(); | |
420 return 0; | |
421 } | |
422 | |
423 x = 0; | |
424 while (x < na->count_item) { | |
425 if (na->items[x]->id == 0x0003) { | |
426 buffer = na->items[x]->data; | |
427 bsize = na->items[x]->size; | |
428 } else if (na->items[x]->id == 0x0004) { | |
429 headerbuffer = na->items[x]->data; | |
430 hsize = na->items[x]->size; | |
431 } | |
432 x++; | |
433 } | |
434 | |
435 if (!buffer) { | |
436 if (na) _pst_free_list(na); | |
437 DEBUG_WARN(("No extended attributes buffer found. Not processing\n")); | |
438 DEBUG_RET(); | |
439 return 0; | |
440 } | |
441 | |
442 memcpy(&xattrib, &(buffer[bptr]), sizeof(xattrib)); | |
443 LE16_CPU(xattrib.extended); | |
444 LE16_CPU(xattrib.zero); | |
445 LE16_CPU(xattrib.type); | |
446 LE16_CPU(xattrib.map); | |
447 bptr += sizeof(xattrib); | |
448 | |
449 while (xattrib.type != 0 && bptr < bsize) { | |
450 ptr = (pst_x_attrib_ll*) xmalloc(sizeof(pst_x_attrib_ll)); | |
451 memset(ptr, 0, sizeof(pst_x_attrib_ll)); | |
452 ptr->type = xattrib.type; | |
453 ptr->map = xattrib.map+0x8000; | |
454 ptr->next = NULL; | |
455 DEBUG_INDEX(("xattrib: ext = %#hx, zero = %#hx, type = %#hx, map = %#hx\n", | |
456 xattrib.extended, xattrib.zero, xattrib.type, xattrib.map)); | |
457 err=0; | |
458 if (xattrib.type & 0x0001) { // if the Bit 1 is set | |
459 // pointer to Unicode field in buffer | |
460 if (xattrib.extended < hsize) { | |
461 char *wt; | |
462 // copy the size of the header. It is 32 bit int | |
463 memcpy(&tint, &(headerbuffer[xattrib.extended]), sizeof(tint)); | |
464 LE32_CPU(tint); | |
465 wt = (char*) xmalloc(tint+2); // plus 2 for a uni-code zero | |
466 memset(wt, 0, tint+2); | |
467 memcpy(wt, &(headerbuffer[xattrib.extended+sizeof(tint)]), tint); | |
468 ptr->data = _pst_wide_to_single(wt, tint); | |
469 free(wt); | |
470 DEBUG_INDEX(("Read string (converted from UTF-16): %s\n", ptr->data)); | |
471 } else { | |
472 DEBUG_INDEX(("Cannot read outside of buffer [%i !< %i]\n", xattrib.extended, hsize)); | |
473 } | |
474 ptr->mytype = PST_MAP_HEADER; | |
475 } else { | |
476 // contains the attribute code to map to. | |
477 ptr->data = (int*)xmalloc(sizeof(int32_t)); | |
478 memset(ptr->data, 0, sizeof(int32_t)); | |
479 *((int32_t*)ptr->data) = xattrib.extended; | |
480 ptr->mytype = PST_MAP_ATTRIB; | |
481 DEBUG_INDEX(("Mapped attribute %#x to %#x\n", ptr->map, *((int32_t*)ptr->data))); | |
482 } | |
483 | |
484 if (err==0) { | |
485 // add it to the list | |
486 p_sh = p_head; | |
487 p_sh2 = NULL; | |
488 while (p_sh && ptr->map > p_sh->map) { | |
489 p_sh2 = p_sh; | |
490 p_sh = p_sh->next; | |
491 } | |
492 if (!p_sh2) { | |
493 // needs to go before first item | |
494 ptr->next = p_head; | |
495 p_head = ptr; | |
496 } else { | |
497 // it will go after p_sh2 | |
498 ptr->next = p_sh2->next; | |
499 p_sh2->next = ptr; | |
500 } | |
501 } else { | |
502 free(ptr); | |
503 ptr = NULL; | |
504 } | |
505 memcpy(&xattrib, &(buffer[bptr]), sizeof(xattrib)); | |
506 LE16_CPU(xattrib.extended); | |
507 LE16_CPU(xattrib.zero); | |
508 LE16_CPU(xattrib.type); | |
509 LE16_CPU(xattrib.map); | |
510 bptr += sizeof(xattrib); | |
511 } | |
512 if (list2) _pst_free_id2(list2); | |
513 if (na) _pst_free_list(na); | |
514 pf->x_head = p_head; | |
515 DEBUG_RET(); | |
516 return 1; | |
16 | 517 } |
518 | |
44 | 519 #define BLOCK_SIZE32 516 // index blocks |
520 #define DESC_BLOCK_SIZE32 516 // descriptor blocks | |
521 #define ITEM_COUNT_OFFSET32 0x1f0 // count byte | |
522 #define LEVEL_INDICATOR_OFFSET32 0x1f3 // node or leaf | |
523 #define BACKLINK_OFFSET32 0x1f8 // backlink u1 value | |
524 #define ITEM_SIZE32 12 | |
525 #define DESC_SIZE32 16 | |
526 #define INDEX_COUNT_MAX32 41 // max active items | |
527 #define DESC_COUNT_MAX32 31 // max active items | |
528 | |
529 #define BLOCK_SIZE64 512 // index blocks | |
530 #define DESC_BLOCK_SIZE64 512 // descriptor blocks | |
531 #define ITEM_COUNT_OFFSET64 0x1e8 // count byte | |
532 #define LEVEL_INDICATOR_OFFSET64 0x1eb // node or leaf | |
533 #define BACKLINK_OFFSET64 0x1f8 // backlink u1 value | |
534 #define ITEM_SIZE64 24 | |
535 #define DESC_SIZE64 32 | |
536 #define INDEX_COUNT_MAX64 20 // max active items | |
537 #define DESC_COUNT_MAX64 15 // max active items | |
538 | |
539 #define BLOCK_SIZE ((do_read64) ? BLOCK_SIZE64 : BLOCK_SIZE32) | |
540 #define DESC_BLOCK_SIZE ((do_read64) ? DESC_BLOCK_SIZE64 : DESC_BLOCK_SIZE32) | |
541 #define ITEM_COUNT_OFFSET ((do_read64) ? ITEM_COUNT_OFFSET64 : ITEM_COUNT_OFFSET32) | |
542 #define LEVEL_INDICATOR_OFFSET ((do_read64) ? LEVEL_INDICATOR_OFFSET64 : LEVEL_INDICATOR_OFFSET32) | |
543 #define BACKLINK_OFFSET ((do_read64) ? BACKLINK_OFFSET64 : BACKLINK_OFFSET32) | |
544 #define ITEM_SIZE ((do_read64) ? ITEM_SIZE64 : ITEM_SIZE32) | |
545 #define DESC_SIZE ((do_read64) ? DESC_SIZE64 : DESC_SIZE32) | |
546 #define INDEX_COUNT_MAX ((do_read64) ? INDEX_COUNT_MAX64 : INDEX_COUNT_MAX32) | |
547 #define DESC_COUNT_MAX ((do_read64) ? DESC_COUNT_MAX64 : DESC_COUNT_MAX32) | |
43 | 548 |
549 | |
550 int _pst_decode_desc( pst_descn *desc, char *buf ) { | |
551 int r; | |
552 if (do_read64) { | |
44 | 553 DEBUG_INDEX(("Decoding desc64\n")); |
43 | 554 DEBUG_HEXDUMPC(buf, sizeof(pst_descn), 0x10); |
555 memcpy(desc, buf, sizeof(pst_descn)); | |
556 LE64_CPU(desc->d_id); | |
557 LE64_CPU(desc->desc_id); | |
558 LE64_CPU(desc->list_id); | |
559 LE32_CPU(desc->parent_id); | |
560 LE32_CPU(desc->u1); | |
561 r = sizeof(pst_descn); | |
562 } | |
563 else { | |
564 pst_desc32 d32; | |
44 | 565 DEBUG_INDEX(("Decoding desc32\n")); |
43 | 566 DEBUG_HEXDUMPC(buf, sizeof(pst_desc32), 0x10); |
567 memcpy(&d32, buf, sizeof(pst_desc32)); | |
568 LE32_CPU(d32.d_id); | |
569 LE32_CPU(d32.desc_id); | |
570 LE32_CPU(d32.list_id); | |
571 LE32_CPU(d32.parent_id); | |
572 desc->d_id = d32.d_id; | |
573 desc->desc_id = d32.desc_id; | |
574 desc->list_id = d32.list_id; | |
575 desc->parent_id = d32.parent_id; | |
576 desc->u1 = 0; | |
577 r = sizeof(pst_desc32); | |
578 } | |
579 return r; | |
580 } | |
581 | |
582 | |
583 int _pst_decode_table( struct _pst_table_ptr_structn *table, char *buf ) { | |
584 int r; | |
585 if (do_read64) { | |
44 | 586 DEBUG_INDEX(("Decoding table64\n")); |
43 | 587 DEBUG_HEXDUMPC(buf, sizeof(struct _pst_table_ptr_structn), 0x10); |
588 memcpy(table, buf, sizeof(struct _pst_table_ptr_structn)); | |
589 LE64_CPU(table->start); | |
590 LE64_CPU(table->u1); | |
591 LE64_CPU(table->offset); | |
592 r =sizeof(struct _pst_table_ptr_structn); | |
593 } | |
594 else { | |
595 struct _pst_table_ptr_struct32 t32; | |
44 | 596 DEBUG_INDEX(("Decoding table32\n")); |
43 | 597 DEBUG_HEXDUMPC(buf, sizeof( struct _pst_table_ptr_struct32), 0x10); |
598 memcpy(&t32, buf, sizeof(struct _pst_table_ptr_struct32)); | |
599 LE32_CPU(t32.start); | |
600 LE32_CPU(t32.u1); | |
601 LE32_CPU(t32.offset); | |
602 table->start = t32.start; | |
603 table->u1 = t32.u1; | |
604 table->offset = t32.offset; | |
605 r = sizeof(struct _pst_table_ptr_struct32); | |
606 } | |
607 return r; | |
608 } | |
609 | |
610 | |
611 int _pst_decode_index( pst_index *index, char *buf ) { | |
612 int r; | |
613 if (do_read64) { | |
44 | 614 DEBUG_INDEX(("Decoding index64\n")); |
43 | 615 DEBUG_HEXDUMPC(buf, sizeof(pst_index), 0x10); |
616 memcpy(index, buf, sizeof(pst_index)); | |
617 LE64_CPU(index->id); | |
618 LE64_CPU(index->offset); | |
619 LE16_CPU(index->size); | |
620 LE16_CPU(index->u0); | |
621 LE16_CPU(index->u1); | |
622 r = sizeof(pst_index); | |
623 } else { | |
624 pst_index32 index32; | |
44 | 625 DEBUG_INDEX(("Decoding index32\n")); |
43 | 626 DEBUG_HEXDUMPC(buf, sizeof(pst_index32), 0x10); |
627 memcpy(&index32, buf, sizeof(pst_index32)); | |
628 LE32_CPU(index32->id); | |
629 LE32_CPU(index32->offset); | |
630 LE16_CPU(index32->size); | |
631 LE16_CPU(index32->u1); | |
632 index->id = index32.id; | |
633 index->offset = index32.offset; | |
634 index->size = index32.size; | |
635 index->u1 = index32.u1; | |
636 r = sizeof(pst_index32); | |
637 } | |
638 return r; | |
639 } | |
640 | |
641 | |
642 int32_t _pst_build_id_ptr(pst_file *pf, off_t offset, int32_t depth, int64_t linku1, uint64_t start_val, uint64_t end_val) { | |
643 struct _pst_table_ptr_structn table, table2; | |
644 pst_index_ll *i_ptr=NULL; | |
645 pst_index index; | |
646 int32_t x, item_count; | |
647 uint64_t old = start_val; | |
648 char *buf = NULL, *bptr; | |
649 | |
650 DEBUG_ENT("_pst_build_id_ptr"); | |
651 DEBUG_INDEX(("offset %x depth %i linku1 %llx start %llx end %llx\n", offset, depth, linku1, start_val, end_val)); | |
652 if (end_val <= start_val) { | |
653 DEBUG_WARN(("The end value is BEFORE the start value. This function will quit. Soz. [start:%#llx, end:%#llx]\n", start_val, end_val)); | |
654 DEBUG_RET(); | |
655 return -1; | |
656 } | |
657 DEBUG_INDEX(("Reading index block\n")); | |
658 if (_pst_read_block_size(pf, offset, BLOCK_SIZE, &buf, 0, 0) < BLOCK_SIZE) { | |
659 DEBUG_WARN(("Failed to read %i bytes\n", BLOCK_SIZE)); | |
660 if (buf) free(buf); | |
661 DEBUG_RET(); | |
662 return -1; | |
663 } | |
664 bptr = buf; | |
44 | 665 DEBUG_HEXDUMPC(buf, BLOCK_SIZE, ITEM_SIZE32); |
43 | 666 item_count = (int)(unsigned)(buf[ITEM_COUNT_OFFSET]); |
667 if (item_count > INDEX_COUNT_MAX) { | |
668 DEBUG_WARN(("Item count %i too large, max is %i\n", item_count, INDEX_COUNT_MAX)); | |
669 if (buf) free(buf); | |
670 DEBUG_RET(); | |
671 return -1; | |
672 } | |
673 index.id = _getIntAt(buf+BACKLINK_OFFSET); | |
674 if (index.id != linku1) { | |
675 DEBUG_WARN(("Backlink %#llx in this node does not match required %#llx\n", index.id, linku1)); | |
676 if (buf) free(buf); | |
677 DEBUG_RET(); | |
678 return -1; | |
679 } | |
680 | |
681 if (buf[LEVEL_INDICATOR_OFFSET] == '\0') { | |
682 // this node contains leaf pointers | |
683 x = 0; | |
684 while (x < item_count) { | |
685 bptr += _pst_decode_index(&index, bptr); | |
686 x++; | |
687 if (index.id == 0) break; | |
688 DEBUG_INDEX(("[%i]%i Item [id = %#x, offset = %#x, u1 = %#x, size = %i(%#x)]\n", | |
689 depth, x, index.id, index.offset, index.u1, index.size, index.size)); | |
690 // if (index.id & 0x02) DEBUG_INDEX(("two-bit set!!\n")); | |
691 if ((index.id >= end_val) || (index.id < old)) { | |
692 DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n")); | |
693 if (buf) free(buf); | |
694 DEBUG_RET(); | |
695 return -1; | |
696 } | |
697 old = index.id; | |
698 if (x == 1) { // first entry | |
699 if ((start_val) && (index.id != start_val)) { | |
700 DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n")); | |
701 if (buf) free(buf); | |
702 DEBUG_RET(); | |
703 return -1; | |
704 } | |
705 } | |
706 i_ptr = (pst_index_ll*) xmalloc(sizeof(pst_index_ll)); | |
707 i_ptr->id = index.id; | |
708 i_ptr->offset = index.offset; | |
709 i_ptr->u1 = index.u1; | |
710 i_ptr->size = index.size; | |
711 i_ptr->next = NULL; | |
712 if (pf->i_tail) pf->i_tail->next = i_ptr; | |
713 if (!pf->i_head) pf->i_head = i_ptr; | |
714 pf->i_tail = i_ptr; | |
715 } | |
716 } else { | |
717 // this node contains node pointers | |
718 x = 0; | |
719 while (x < item_count) { | |
720 bptr += _pst_decode_table(&table, bptr); | |
721 x++; | |
722 if (table.start == 0) break; | |
723 if (x < item_count) { | |
724 _pst_decode_table(&table2, bptr); | |
725 } | |
726 else { | |
727 table2.start = end_val; | |
728 } | |
729 DEBUG_INDEX(("[%i] %i Index Table [start id = %#x, u1 = %#x, offset = %#x, end id = %#x]\n", | |
730 depth, x, table.start, table.u1, table.offset, table2.start)); | |
731 if ((table.start >= end_val) || (table.start < old)) { | |
732 DEBUG_WARN(("This table isn't right. Must be corruption, or I got it wrong!\n")); | |
733 if (buf) free(buf); | |
734 DEBUG_RET(); | |
735 return -1; | |
736 } | |
737 old = table.start; | |
738 if (x == 1) { // first entry | |
739 if ((start_val) && (table.start != start_val)) { | |
740 DEBUG_WARN(("This table isn't right. Must be corruption, or I got it wrong!\n")); | |
741 if (buf) free(buf); | |
742 DEBUG_RET(); | |
743 return -1; | |
744 } | |
745 } | |
746 _pst_build_id_ptr(pf, table.offset, depth+1, table.u1, table.start, table2.start); | |
747 } | |
748 } | |
749 if (buf) free (buf); | |
750 DEBUG_RET(); | |
751 return 0; | |
16 | 752 } |
753 | |
754 | |
35 | 755 /** this list node type is used for a quick cache |
43 | 756 of the descriptor tree nodes (rooted at pf->d_head) |
757 and for a "lost and found" list. | |
758 If the parent isn't found yet, put it on the lost and found | |
759 list and check it each time you read a new item. | |
35 | 760 */ |
761 struct cache_list_node { | |
43 | 762 pst_desc_ll *ptr; |
763 /** only used for lost and found lists */ | |
44 | 764 uint64_t parent; |
43 | 765 struct cache_list_node *next; |
766 struct cache_list_node *prev; | |
35 | 767 }; |
768 struct cache_list_node *cache_head; | |
769 struct cache_list_node *cache_tail; | |
770 struct cache_list_node *lostfound_head; | |
771 int32_t cache_count; | |
772 | |
773 | |
774 /** | |
43 | 775 add the d_ptr descriptor into the global tree |
35 | 776 */ |
44 | 777 void record_descriptor(pst_file *pf, pst_desc_ll *d_ptr, uint64_t parent_id) { |
43 | 778 struct cache_list_node *lostfound_ptr = NULL; |
779 struct cache_list_node *cache_ptr = NULL; | |
780 pst_desc_ll *parent = NULL; | |
781 | |
782 if (parent_id == 0 || parent_id == d_ptr->id) { | |
783 // add top level node to the descriptor tree | |
784 if (parent_id == 0) { | |
785 DEBUG_INDEX(("No Parent\n")); | |
786 } else { | |
787 DEBUG_INDEX(("Record is its own parent. What is this world coming to?\n")); | |
788 } | |
789 if (pf->d_tail) pf->d_tail->next = d_ptr; | |
790 if (!pf->d_head) pf->d_head = d_ptr; | |
791 d_ptr->prev = pf->d_tail; | |
792 pf->d_tail = d_ptr; | |
793 } else { | |
794 DEBUG_INDEX(("Searching for parent\n")); | |
795 // check in the cache for the parent | |
796 cache_ptr = cache_head; | |
797 while (cache_ptr && (cache_ptr->ptr->id != parent_id)) { | |
798 cache_ptr = cache_ptr->next; | |
799 } | |
800 if (!cache_ptr && (parent = _pst_getDptr(pf, parent_id)) == NULL) { | |
801 // check in the lost/found list | |
802 lostfound_ptr = lostfound_head; | |
803 while (lostfound_ptr && (lostfound_ptr->ptr->id != parent_id)) { | |
804 lostfound_ptr = lostfound_ptr->next; | |
805 } | |
806 if (!lostfound_ptr) { | |
807 DEBUG_WARN(("ERROR -- cannot find parent with id %#x. Adding to lost/found\n", parent_id)); | |
808 lostfound_ptr = (struct cache_list_node*) xmalloc(sizeof(struct cache_list_node)); | |
809 lostfound_ptr->prev = NULL; | |
810 lostfound_ptr->next = lostfound_head; | |
811 lostfound_ptr->parent = parent_id; | |
812 lostfound_ptr->ptr = d_ptr; | |
813 lostfound_head = lostfound_ptr; | |
814 } else { | |
815 parent = lostfound_ptr->ptr; | |
816 DEBUG_INDEX(("Found parent (%#x) in Lost and Found\n", parent->id)); | |
817 } | |
818 } | |
819 | |
820 if (cache_ptr || parent) { | |
821 if (cache_ptr) | |
822 // parent is already in the cache | |
823 parent = cache_ptr->ptr; | |
824 else { | |
825 //add the parent to the cache | |
826 DEBUG_INDEX(("Cache addition\n")); | |
827 cache_ptr = (struct cache_list_node*) xmalloc(sizeof(struct cache_list_node)); | |
828 cache_ptr->prev = NULL; | |
829 cache_ptr->next = cache_head; | |
830 cache_ptr->ptr = parent; | |
831 cache_head = cache_ptr; | |
832 if (!cache_tail) cache_tail = cache_ptr; | |
833 cache_count++; | |
834 if (cache_count > 100) { | |
835 DEBUG_INDEX(("trimming quick cache\n")); | |
836 //remove one from the end | |
837 cache_ptr = cache_tail; | |
838 cache_tail = cache_ptr->prev; | |
839 free (cache_ptr); | |
840 cache_count--; | |
841 } | |
842 } | |
843 DEBUG_INDEX(("Found a parent\n")); | |
844 parent->no_child++; | |
845 d_ptr->parent = parent; | |
846 if (parent->child_tail) parent->child_tail->next = d_ptr; | |
847 if (!parent->child) parent->child = d_ptr; | |
848 d_ptr->prev = parent->child_tail; | |
849 parent->child_tail = d_ptr; | |
850 } | |
851 } | |
35 | 852 } |
853 | |
43 | 854 int32_t _pst_build_desc_ptr (pst_file *pf, off_t offset, int32_t depth, int64_t linku1, uint64_t *high_id, uint64_t start_val, uint64_t end_val) { |
855 struct _pst_table_ptr_structn table, table2; | |
856 pst_descn desc_rec; | |
857 pst_desc_ll *d_ptr=NULL, *parent=NULL; | |
858 int32_t x, item_count; | |
859 uint32_t old = start_val; | |
860 char *buf = NULL, *bptr; | |
861 struct cache_list_node *cache_ptr = NULL; | |
862 struct cache_list_node *lostfound_ptr = NULL; | |
863 struct cache_list_node *lostfound_shd = NULL; | |
864 struct cache_list_node *lostfound_tmp = NULL; | |
865 | |
866 if (depth == 0) { | |
867 // initialize the linked list and lost/found list. | |
868 cache_head = NULL; | |
869 cache_tail = NULL; | |
870 lostfound_head = NULL; | |
871 cache_count = 0; | |
872 } | |
873 | |
874 DEBUG_ENT("_pst_build_desc_ptr"); | |
875 DEBUG_INDEX(("offset %x depth %i linku1 %x start %x end %x\n", offset, depth, linku1, start_val, end_val)); | |
876 if (end_val <= start_val) { | |
877 DEBUG_WARN(("The end value is BEFORE the start value. This function will quit. Soz. [start:%#x, end:%#x]\n", start_val, end_val)); | |
878 DEBUG_RET(); | |
879 return -1; | |
880 } | |
881 DEBUG_INDEX(("Reading desc block\n")); | |
882 if (_pst_read_block_size(pf, offset, DESC_BLOCK_SIZE, &buf, 0, 0) < DESC_BLOCK_SIZE) { | |
883 DEBUG_WARN(("Failed to read %i bytes\n", DESC_BLOCK_SIZE)); | |
884 if (buf) free(buf); | |
885 DEBUG_RET(); | |
886 return -1; | |
887 } | |
888 bptr = buf; | |
889 item_count = (int)(unsigned)(buf[ITEM_COUNT_OFFSET]); | |
890 | |
891 desc_rec.d_id = _getIntAt(buf+BACKLINK_OFFSET); | |
892 if (desc_rec.d_id != linku1) { | |
893 DEBUG_WARN(("Backlink %#x in this node does not match required %#x\n", desc_rec.d_id, linku1)); | |
894 if (buf) free(buf); | |
895 DEBUG_RET(); | |
896 return -1; | |
897 } | |
898 if (buf[LEVEL_INDICATOR_OFFSET] == '\0') { | |
899 // this node contains leaf pointers | |
44 | 900 DEBUG_HEXDUMPC(buf, DESC_BLOCK_SIZE, DESC_SIZE32); |
43 | 901 if (item_count > DESC_COUNT_MAX) { |
902 DEBUG_WARN(("Item count %i too large, max is %i\n", item_count, DESC_COUNT_MAX)); | |
903 if (buf) free(buf); | |
904 DEBUG_RET(); | |
905 return -1; | |
906 } | |
907 x = 0; | |
908 while (x < item_count) { | |
909 bptr += _pst_decode_desc(&desc_rec, bptr); | |
910 x++; | |
911 if (desc_rec.d_id == 0) break; | |
912 DEBUG_INDEX(("[%i] Item(%#x) = [d_id = %#x, desc_id = %#x, list_id = %#x, parent_id = %#x]\n", | |
913 depth, x, desc_rec.d_id, desc_rec.desc_id, desc_rec.list_id, desc_rec.parent_id)); | |
914 if ((desc_rec.d_id >= end_val) || (desc_rec.d_id < old)) { | |
915 DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n")); | |
916 DEBUG_HEXDUMPC(buf, DESC_BLOCK_SIZE, 16); | |
917 if (buf) free(buf); | |
918 DEBUG_RET(); | |
919 return -1; | |
920 } | |
921 old = desc_rec.d_id; | |
922 if (x == 1) { // first entry | |
923 if (start_val && (desc_rec.d_id != start_val)) { | |
924 DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n")); | |
925 if (buf) free(buf); | |
926 DEBUG_RET(); | |
927 return -1; | |
928 } | |
929 } | |
930 // When duplicates found, just update the info.... perhaps this is correct functionality | |
931 DEBUG_INDEX(("Searching for existing record\n")); | |
932 if (desc_rec.d_id <= *high_id && (d_ptr = _pst_getDptr(pf, desc_rec.d_id))) { | |
933 DEBUG_INDEX(("Updating Existing Values\n")); | |
934 d_ptr->list_index = _pst_getID(pf, desc_rec.list_id); | |
935 d_ptr->desc = _pst_getID(pf, desc_rec.desc_id); | |
936 DEBUG_INDEX(("\tdesc = %#x\tlist_index=%#x\n", | |
937 (d_ptr->desc==NULL?0:d_ptr->desc->id), | |
938 (d_ptr->list_index==NULL?0:d_ptr->list_index->id))); | |
939 if (d_ptr->parent && desc_rec.parent_id != d_ptr->parent->id) { | |
940 DEBUG_INDEX(("WARNING -- Parent of record has changed. Moving it\n")); | |
941 //hmmm, we must move the record. | |
942 // first we must remove from current location | |
943 // change previous record to point next to our next | |
944 // if no previous, then use parent's child | |
945 // if no parent then change pf->d_head; | |
946 // change next's prev to our prev | |
947 // if no next then change parent's child_tail | |
948 // if no parent then change pf->d_tail | |
949 if (d_ptr->prev) | |
950 d_ptr->prev->next = d_ptr->next; | |
951 else if (d_ptr->parent) | |
952 d_ptr->parent->child = d_ptr->next; | |
953 else | |
954 pf->d_head = d_ptr->next; | |
955 | |
956 if (d_ptr->next) | |
957 d_ptr->next->prev = d_ptr->prev; | |
958 else if (d_ptr->parent) | |
959 d_ptr->parent->child_tail = d_ptr->prev; | |
960 else | |
961 pf->d_tail = d_ptr->prev; | |
962 | |
963 d_ptr->prev = NULL; | |
964 d_ptr->next = NULL; | |
965 d_ptr->parent = NULL; | |
966 record_descriptor(pf, d_ptr, desc_rec.parent_id); // add to the global tree | |
967 } | |
968 } else { | |
969 if (*high_id < desc_rec.d_id) { | |
970 DEBUG_INDEX(("Updating New High\n")); | |
971 *high_id = desc_rec.d_id; | |
972 } | |
973 DEBUG_INDEX(("New Record\n")); | |
974 d_ptr = (pst_desc_ll*) xmalloc(sizeof(pst_desc_ll)); | |
975 d_ptr->id = desc_rec.d_id; | |
976 d_ptr->list_index = _pst_getID(pf, desc_rec.list_id); | |
977 d_ptr->desc = _pst_getID(pf, desc_rec.desc_id); | |
978 d_ptr->prev = NULL; | |
979 d_ptr->next = NULL; | |
980 d_ptr->parent = NULL; | |
981 d_ptr->child = NULL; | |
982 d_ptr->child_tail = NULL; | |
983 d_ptr->no_child = 0; | |
984 record_descriptor(pf, d_ptr, desc_rec.parent_id); // add to the global tree | |
985 | |
986 } | |
987 // check here to see if d_ptr is the parent of any of the items in the lost / found list | |
988 lostfound_ptr = lostfound_head; | |
989 lostfound_shd = NULL; | |
990 while (lostfound_ptr) { | |
991 if (lostfound_ptr->parent == d_ptr->id) { | |
992 DEBUG_INDEX(("Found a child (%#x) of the current record. Joining to main structure.\n", lostfound_ptr->ptr->id)); | |
993 parent = d_ptr; | |
994 d_ptr = lostfound_ptr->ptr; | |
995 parent->no_child++; | |
996 d_ptr->parent = parent; | |
997 if (parent->child_tail) parent->child_tail->next = d_ptr; | |
998 if (!parent->child) parent->child = d_ptr; | |
999 d_ptr->prev = parent->child_tail; | |
1000 parent->child_tail = d_ptr; | |
1001 if (!lostfound_shd) lostfound_head = lostfound_ptr->next; | |
1002 else lostfound_shd->next = lostfound_ptr->next; | |
1003 lostfound_tmp = lostfound_ptr->next; | |
1004 free(lostfound_ptr); | |
1005 lostfound_ptr = lostfound_tmp; | |
1006 } else { | |
1007 lostfound_shd = lostfound_ptr; | |
1008 lostfound_ptr = lostfound_ptr->next; | |
1009 } | |
1010 } | |
1011 } | |
1012 } else { | |
1013 // this node contains node pointers | |
44 | 1014 DEBUG_HEXDUMPC(buf, DESC_BLOCK_SIZE, ITEM_SIZE32); |
43 | 1015 if (item_count > INDEX_COUNT_MAX) { |
1016 DEBUG_WARN(("Item count %i too large, max is %i\n", item_count, INDEX_COUNT_MAX)); | |
1017 if (buf) free(buf); | |
1018 DEBUG_RET(); | |
1019 return -1; | |
1020 } | |
1021 x = 0; | |
1022 while (x < item_count) { | |
44 | 1023 bptr += _pst_decode_table(&table, bptr); |
43 | 1024 x++; |
1025 if (table.start == 0) break; | |
1026 if (x < item_count) { | |
1027 _pst_decode_table(&table2, bptr); | |
1028 } | |
1029 else { | |
1030 table2.start = end_val; | |
1031 } | |
1032 DEBUG_INDEX(("[%i] %i Descriptor Table [start id = %#x, u1 = %#x, offset = %#x, end id = %#x]\n", | |
1033 depth, x, table.start, table.u1, table.offset, table2.start)); | |
1034 if ((table.start >= end_val) || (table.start < old)) { | |
1035 DEBUG_WARN(("This table isn't right. Must be corruption, or I got it wrong!\n")); | |
1036 if (buf) free(buf); | |
1037 DEBUG_RET(); | |
1038 return -1; | |
1039 } | |
1040 old = table.start; | |
1041 if (x == 1) { // first entry | |
1042 if (start_val != -1 && table.start != start_val) { | |
1043 DEBUG_WARN(("This table isn't right. Must be corruption, or I got it wrong!\n")); | |
1044 if (buf) free(buf); | |
1045 DEBUG_RET(); | |
1046 return -1; | |
1047 } | |
1048 } | |
1049 _pst_build_desc_ptr(pf, table.offset, depth+1, table.u1, high_id, table.start, table2.start); | |
1050 } | |
1051 } | |
1052 if (depth == 0) { | |
1053 // free the quick cache | |
1054 while (cache_head) { | |
1055 cache_ptr = cache_head->next; | |
1056 free(cache_head); | |
1057 cache_head = cache_ptr; | |
1058 } | |
1059 // free the lost and found | |
1060 while (lostfound_head) { | |
1061 lostfound_ptr = lostfound_head->next; | |
1062 WARN(("unused lost/found item with parent %d))", lostfound_head->parent)); | |
1063 free(lostfound_head); | |
1064 lostfound_head = lostfound_ptr; | |
1065 } | |
1066 } | |
1067 if (buf) free(buf); | |
1068 DEBUG_RET(); | |
1069 return 0; | |
16 | 1070 } |
1071 | |
1072 | |
44 | 1073 pst_item* _pst_parse_item(pst_file *pf, pst_desc_ll *d_ptr) { |
43 | 1074 pst_num_array * list; |
1075 pst_index2_ll *id2_head = NULL; | |
1076 pst_index_ll *id_ptr = NULL; | |
1077 pst_item *item = NULL; | |
1078 pst_item_attach *attach = NULL; | |
1079 int x; | |
1080 DEBUG_ENT("_pst_parse_item"); | |
1081 if (!d_ptr) { | |
1082 DEBUG_WARN(("you cannot pass me a NULL! I don't want it!\n")); | |
1083 DEBUG_RET(); | |
1084 return NULL; | |
1085 } | |
1086 | |
1087 if (!d_ptr->desc) { | |
1088 DEBUG_WARN(("why is d_ptr->desc == NULL? I don't want to do anything else with this record\n")); | |
1089 DEBUG_RET(); | |
1090 return NULL; | |
1091 } | |
1092 | |
1093 if (d_ptr->list_index) { | |
1094 id2_head = _pst_build_id2(pf, d_ptr->list_index, NULL); | |
1095 _pst_printID2ptr(id2_head); | |
1096 } else { | |
1097 DEBUG_WARN(("Have not been able to fetch any id2 values for this item. Brace yourself!\n")); | |
1098 } | |
1099 | |
1100 list = _pst_parse_block(pf, d_ptr->desc->id, id2_head); | |
1101 if (!list) { | |
1102 DEBUG_WARN(("_pst_parse_block() returned an error for d_ptr->desc->id [%#x]\n", d_ptr->desc->id)); | |
1103 if (id2_head) _pst_free_id2(id2_head); | |
1104 DEBUG_RET(); | |
1105 return NULL; | |
1106 } | |
1107 | |
1108 item = (pst_item*) xmalloc(sizeof(pst_item)); | |
1109 memset(item, 0, sizeof(pst_item)); | |
1110 | |
1111 if (_pst_process(list, item, NULL)) { | |
1112 DEBUG_WARN(("_pst_process() returned non-zero value. That is an error\n")); | |
1113 if (item) _pst_freeItem(item); | |
1114 if (list) _pst_free_list(list); | |
1115 if (id2_head) _pst_free_id2(id2_head); | |
1116 DEBUG_RET(); | |
1117 return NULL; | |
1118 } | |
1119 if (list) _pst_free_list(list); | |
1120 list = NULL; //_pst_process will free the items in the list | |
1121 | |
1122 if ((id_ptr = _pst_getID2(id2_head, 0x671))) { | |
1123 // attachments exist - so we will process them | |
1124 while (item->attach) { | |
1125 attach = item->attach->next; | |
1126 free(item->attach); | |
1127 item->attach = attach; | |
1128 } | |
1129 | |
1130 DEBUG_EMAIL(("ATTACHMENT processing attachment\n")); | |
1131 if ((list = _pst_parse_block(pf, id_ptr->id, id2_head)) == NULL) { | |
1132 DEBUG_WARN(("ERROR error processing main attachment record\n")); | |
1133 if (item) _pst_freeItem(item); | |
1134 if (id2_head) _pst_free_id2(id2_head); | |
1135 DEBUG_RET(); | |
1136 return NULL; | |
1137 } | |
1138 else { | |
1139 x = 0; | |
1140 while (x < list->count_array) { | |
1141 attach = (pst_item_attach*) xmalloc (sizeof(pst_item_attach)); | |
1142 memset (attach, 0, sizeof(pst_item_attach)); | |
1143 attach->next = item->attach; | |
1144 item->attach = attach; | |
1145 x++; | |
1146 } | |
1147 | |
1148 if (_pst_process(list, item, item->attach)) { | |
1149 DEBUG_WARN(("ERROR _pst_process() failed with attachments\n")); | |
1150 if (item) _pst_freeItem(item); | |
1151 if (list) _pst_free_list(list); | |
1152 if (id2_head) _pst_free_id2(id2_head); | |
1153 DEBUG_RET(); | |
1154 return NULL; | |
1155 } | |
1156 if (list) _pst_free_list(list); | |
1157 list = NULL; | |
1158 | |
1159 // now we will have initial information of each attachment stored in item->attach... | |
1160 // we must now read the secondary record for each based on the id2 val associated with | |
1161 // each attachment | |
1162 attach = item->attach; | |
1163 while (attach) { | |
1164 if ((id_ptr = _pst_getID2(id2_head, attach->id2_val))) { | |
1165 // id_ptr is a record describing the attachment | |
1166 // we pass NULL instead of id2_head cause we don't want it to | |
1167 // load all the extra stuff here. | |
1168 if ((list = _pst_parse_block(pf, id_ptr->id, NULL)) == NULL) { | |
1169 DEBUG_WARN(("ERROR error processing an attachment record\n")); | |
1170 attach = attach->next; | |
1171 continue; | |
1172 } | |
1173 if (_pst_process(list, item, attach)) { | |
1174 DEBUG_WARN(("ERROR _pst_process() failed with an attachment\n")); | |
1175 if (list) _pst_free_list(list); | |
1176 list = NULL; | |
1177 attach = attach->next; | |
1178 continue; | |
1179 } | |
1180 if (list) _pst_free_list(list); | |
1181 list = NULL; | |
1182 id_ptr = _pst_getID2(id2_head, attach->id2_val); | |
1183 if (id_ptr) { | |
1184 // id2_val has been updated to the ID2 value of the datablock containing the | |
1185 // attachment data | |
1186 attach->id_val = id_ptr->id; | |
1187 } else { | |
1188 DEBUG_WARN(("have not located the correct value for the attachment [%#x]\n", attach->id2_val)); | |
1189 } | |
1190 } else { | |
1191 DEBUG_WARN(("ERROR cannot locate id2 value %#x\n", attach->id2_val)); | |
1192 } | |
1193 attach = attach->next; | |
1194 } | |
1195 } | |
1196 } | |
1197 | |
1198 _pst_free_id2(id2_head); | |
1199 id2_head = NULL; | |
1200 DEBUG_RET(); | |
1201 return item; | |
16 | 1202 } |
1203 | |
1204 | |
35 | 1205 void freeall(unsigned char *buf, pst_block_offset_pointer *p1, |
43 | 1206 pst_block_offset_pointer *p2, |
1207 pst_block_offset_pointer *p3, | |
1208 pst_block_offset_pointer *p4, | |
1209 pst_block_offset_pointer *p5, | |
1210 pst_block_offset_pointer *p6, | |
1211 pst_block_offset_pointer *p7) { | |
1212 if (buf) free(buf); | |
1213 if (p1->needfree) free(p1->from); | |
1214 if (p2->needfree) free(p2->from); | |
1215 if (p3->needfree) free(p3->from); | |
1216 if (p4->needfree) free(p4->from); | |
1217 if (p5->needfree) free(p5->from); | |
1218 if (p6->needfree) free(p6->from); | |
1219 if (p7->needfree) free(p7->from); | |
35 | 1220 } |
1221 | |
1222 | |
43 | 1223 pst_num_array * _pst_parse_block(pst_file *pf, uint32_t block_id, pst_index2_ll *i2_head) { |
1224 unsigned char *buf = NULL; | |
1225 pst_num_array *na_ptr = NULL, *na_head = NULL; | |
1226 pst_block_offset_pointer block_offset1; | |
1227 pst_block_offset_pointer block_offset2; | |
1228 pst_block_offset_pointer block_offset3; | |
1229 pst_block_offset_pointer block_offset4; | |
1230 pst_block_offset_pointer block_offset5; | |
1231 pst_block_offset_pointer block_offset6; | |
1232 pst_block_offset_pointer block_offset7; | |
1233 uint32_t size; | |
1234 uint32_t x; | |
1235 uint32_t num_recs; | |
1236 uint32_t count_rec; | |
1237 uint32_t num_list; | |
1238 uint32_t cur_list; | |
1239 uint32_t block_type; | |
1240 uint32_t rec_size = 0; | |
1241 uint32_t ind_ptr; | |
1242 unsigned char* list_start; | |
1243 unsigned char* t_ptr; | |
1244 unsigned char* fr_ptr; | |
1245 unsigned char* to_ptr; | |
1246 unsigned char* ind2_end; | |
1247 unsigned char* ind2_ptr = NULL; | |
1248 size_t read_size=0; | |
1249 pst_x_attrib_ll *mapptr; | |
1250 | |
1251 struct { | |
1252 uint16_t type; | |
1253 uint16_t ref_type; | |
1254 uint32_t value; | |
1255 } table_rec; //for type 1 (0xBCEC) blocks | |
1256 struct { | |
1257 uint16_t ref_type; | |
1258 uint16_t type; | |
1259 uint16_t ind2_off; | |
1260 uint8_t size; | |
1261 uint8_t slot; | |
1262 } table2_rec; //for type 2 (0x7CEC) blocks | |
1263 struct { | |
1264 uint32_t id; | |
1265 } table3_rec; //for type 3 (0x0101) blocks | |
1266 struct { | |
1267 uint16_t index_offset; | |
1268 uint16_t type; | |
1269 uint32_t offset; | |
1270 } block_hdr; | |
1271 struct { | |
1272 unsigned char seven_c; | |
1273 unsigned char item_count; | |
1274 uint16_t u1; | |
1275 uint16_t u2; | |
1276 uint16_t u3; | |
1277 uint16_t rec_size; | |
1278 uint32_t b_five_offset; | |
1279 uint32_t ind2_offset; | |
1280 uint16_t u7; | |
1281 uint16_t u8; | |
1282 } seven_c_blk; | |
1283 struct _type_d_rec { | |
1284 uint32_t id; | |
1285 uint32_t u1; | |
1286 } * type_d_rec; | |
1287 | |
1288 DEBUG_ENT("_pst_parse_block"); | |
1289 if ((read_size = _pst_ff_getIDblock_dec(pf, block_id, &buf)) == 0) { | |
1290 WARN(("Error reading block id %#x\n", block_id)); | |
1291 if (buf) free (buf); | |
1292 DEBUG_RET(); | |
1293 return NULL; | |
1294 } | |
1295 | |
1296 block_offset1.needfree = 0; | |
1297 block_offset2.needfree = 0; | |
1298 block_offset3.needfree = 0; | |
1299 block_offset4.needfree = 0; | |
1300 block_offset5.needfree = 0; | |
1301 block_offset6.needfree = 0; | |
1302 block_offset7.needfree = 0; | |
1303 | |
1304 memcpy(&block_hdr, buf, sizeof(block_hdr)); | |
1305 LE16_CPU(block_hdr.index_offset); | |
1306 LE16_CPU(block_hdr.type); | |
1307 LE32_CPU(block_hdr.offset); | |
1308 DEBUG_EMAIL(("block header (index_offset=%#hx, type=%#hx, offset=%#hx\n", block_hdr.index_offset, block_hdr.type, block_hdr.offset)); | |
1309 | |
1310 ind_ptr = block_hdr.index_offset; | |
1311 | |
1312 if (block_hdr.type == 0xBCEC) { //type 1 | |
1313 block_type = 1; | |
1314 | |
1315 if (_pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, block_hdr.offset, &block_offset1)) { | |
1316 DEBUG_WARN(("internal error (bc.b5 offset %#x) in reading block id %#x\n", block_hdr.offset, block_id)); | |
1317 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | |
1318 DEBUG_RET(); | |
1319 return NULL; | |
1320 } | |
1321 memcpy(&table_rec, block_offset1.from, sizeof(table_rec)); | |
1322 LE16_CPU(table_rec.type); | |
1323 LE16_CPU(table_rec.ref_type); | |
1324 LE32_CPU(table_rec.value); | |
1325 DEBUG_EMAIL(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value)); | |
1326 | |
1327 if (table_rec.type != 0x02B5) { | |
1328 WARN(("Unknown second block constant - %#X for id %#x\n", table_rec.type, block_id)); | |
1329 DEBUG_HEXDUMPC(buf, sizeof(table_rec), 0x10); | |
1330 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | |
1331 DEBUG_RET(); | |
1332 return NULL; | |
1333 } | |
1334 | |
1335 if (_pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, table_rec.value, &block_offset2)) { | |
1336 DEBUG_WARN(("internal error (bc.b5.desc offset) in reading block id %#x\n", table_rec.value, block_id)); | |
1337 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | |
1338 DEBUG_RET(); | |
1339 return NULL; | |
1340 } | |
1341 list_start = block_offset2.from; | |
1342 to_ptr = block_offset2.to; | |
1343 num_list = (to_ptr - list_start)/sizeof(table_rec); | |
1344 num_recs = 1; // only going to be one object in these blocks | |
1345 } | |
1346 else if (block_hdr.type == 0x7CEC) { //type 2 | |
1347 block_type = 2; | |
1348 | |
1349 if (_pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, block_hdr.offset, &block_offset3)) { | |
1350 DEBUG_WARN(("internal error (7c.7c offset %#x) in reading block id %#x\n", block_hdr.offset, block_id)); | |
1351 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | |
1352 DEBUG_RET(); | |
1353 return NULL; | |
1354 } | |
1355 fr_ptr = block_offset3.from; //now got pointer to "7C block" | |
1356 memset(&seven_c_blk, 0, sizeof(seven_c_blk)); | |
1357 memcpy(&seven_c_blk, fr_ptr, sizeof(seven_c_blk)); | |
1358 LE16_CPU(seven_c_blk.u1); | |
1359 LE16_CPU(seven_c_blk.u2); | |
1360 LE16_CPU(seven_c_blk.u3); | |
1361 LE16_CPU(seven_c_blk.rec_size); | |
1362 LE32_CPU(seven_c_blk.b_five_offset); | |
1363 LE32_CPU(seven_c_blk.ind2_offset); | |
1364 LE16_CPU(seven_c_blk.u7); | |
1365 LE16_CPU(seven_c_blk.u8); | |
1366 | |
1367 list_start = fr_ptr + sizeof(seven_c_blk); // the list of item numbers start after this record | |
1368 | |
1369 if (seven_c_blk.seven_c != 0x7C) { // this would mean it isn't a 7C block! | |
1370 WARN(("Error. There isn't a 7C where I want to see 7C!\n")); | |
1371 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | |
1372 DEBUG_RET(); | |
1373 return NULL; | |
1374 } | |
1375 | |
1376 rec_size = seven_c_blk.rec_size; | |
1377 num_list = seven_c_blk.item_count; | |
1378 | |
1379 if (_pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, seven_c_blk.b_five_offset, &block_offset4)) { | |
1380 DEBUG_WARN(("internal error (7c.b5 offset %#x) in reading block id %#x\n", seven_c_blk.b_five_offset, block_id)); | |
1381 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | |
1382 DEBUG_RET(); | |
1383 return NULL; | |
1384 } | |
1385 memcpy(&table_rec, block_offset4.from, sizeof(table_rec)); | |
1386 LE16_CPU(table_rec.type); | |
1387 LE16_CPU(table_rec.ref_type); | |
1388 LE32_CPU(table_rec.value); | |
1389 | |
1390 if (table_rec.type != 0x04B5) { // different constant than a type 1 record | |
1391 WARN(("Unknown second block constant - %#X for id %#x\n", table_rec.type, block_id)); | |
1392 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | |
1393 DEBUG_RET(); | |
1394 return NULL; | |
1395 } | |
1396 | |
1397 if (_pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, table_rec.value, &block_offset5)) { | |
1398 DEBUG_WARN(("internal error (7c.5b.desc offset %#x) in reading block id %#x\n", table_rec.value, block_id)); | |
1399 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | |
1400 DEBUG_RET(); | |
1401 return NULL; | |
1402 } | |
1403 num_recs = (block_offset5.to - block_offset5.from) / 6; // this will give the number of records in this block | |
1404 | |
1405 if (_pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, seven_c_blk.ind2_offset, &block_offset6)) { | |
1406 DEBUG_WARN(("internal error (7c.ind2 offset %#x) in reading block id %#x\n", seven_c_blk.ind2_offset, block_id)); | |
1407 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | |
1408 DEBUG_RET(); | |
1409 return NULL; | |
1410 } | |
1411 ind2_ptr = block_offset6.from; | |
1412 ind2_end = block_offset6.to; | |
1413 } | |
1414 else if (block_hdr.index_offset == 0x0101) { //type 2 | |
1415 unsigned char *buf2 = NULL; | |
1416 int n = block_hdr.type; // count | |
1417 int m = sizeof(table3_rec); | |
1418 int i; | |
1419 block_type = 3; | |
1420 for (i=0; i<n; i++) { | |
1421 memcpy(&table3_rec, buf+8+i*m, m); | |
1422 LE32_CPU(table3_rec.id); | |
1423 _pst_ff_getIDblock_dec(pf, table3_rec.id, &buf2); | |
1424 if (buf2) free(buf2); | |
1425 buf2 = NULL; | |
1426 } | |
1427 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | |
1428 DEBUG_RET(); | |
1429 return NULL; | |
1430 } else { | |
1431 WARN(("ERROR: Unknown block constant - %#X for id %#x\n", block_hdr.type, block_id)); | |
1432 DEBUG_HEXDUMPC(buf, read_size,0x10); | |
1433 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | |
1434 DEBUG_RET(); | |
1435 return NULL; | |
1436 } | |
1437 | |
1438 DEBUG_EMAIL(("Mallocing number of records %i\n", num_recs)); | |
1439 for (count_rec=0; count_rec<num_recs; count_rec++) { | |
1440 na_ptr = (pst_num_array*) xmalloc(sizeof(pst_num_array)); | |
1441 memset(na_ptr, 0, sizeof(pst_num_array)); | |
1442 na_ptr->next = na_head; | |
1443 na_head = na_ptr; | |
1444 // allocate an array of count num_recs to contain sizeof(struct_pst_num_item) | |
1445 na_ptr->items = (struct _pst_num_item**) xmalloc(sizeof(struct _pst_num_item)*num_list); | |
1446 na_ptr->count_item = num_list; | |
1447 na_ptr->orig_count = num_list; | |
1448 na_ptr->count_array = num_recs; // each record will have a record of the total number of records | |
1449 for (x=0; x<num_list; x++) na_ptr->items[x] = NULL; | |
1450 x = 0; | |
1451 | |
1452 DEBUG_EMAIL(("going to read %i (%#x) items\n", na_ptr->count_item, na_ptr->count_item)); | |
1453 | |
1454 fr_ptr = list_start; // initialize fr_ptr to the start of the list. | |
1455 for (cur_list=0; cur_list<num_list; cur_list++) { //we will increase fr_ptr as we progress through index | |
1456 unsigned char* value_pointer = NULL; // needed for block type 2 with values larger than 4 bytes | |
1457 int value_size = 0; | |
1458 if (block_type == 1) { | |
1459 memcpy(&table_rec, fr_ptr, sizeof(table_rec)); | |
1460 LE16_CPU(table_rec.type); | |
1461 LE16_CPU(table_rec.ref_type); | |
1462 //LE32_CPU(table_rec.value); // done later, some may be order invariant | |
1463 fr_ptr += sizeof(table_rec); | |
1464 } else if (block_type == 2) { | |
1465 // we will copy the table2_rec values into a table_rec record so that we can keep the rest of the code | |
1466 memcpy(&table2_rec, fr_ptr, sizeof(table2_rec)); | |
1467 LE16_CPU(table2_rec.ref_type); | |
1468 LE16_CPU(table2_rec.type); | |
1469 LE16_CPU(table2_rec.ind2_off); | |
1470 | |
1471 // table_rec and table2_rec are arranged differently, so assign the values across | |
1472 table_rec.type = table2_rec.type; | |
1473 table_rec.ref_type = table2_rec.ref_type; | |
1474 table_rec.value = 0; | |
1475 if ((ind2_end - ind2_ptr) >= (table2_rec.ind2_off + table2_rec.size)) { | |
1476 int n = table2_rec.size; | |
1477 int m = sizeof(table_rec.value); | |
1478 if (n <= m) { | |
1479 memcpy(&table_rec.value, ind2_ptr + table2_rec.ind2_off, n); | |
1480 } | |
1481 else { | |
1482 value_pointer = ind2_ptr + table2_rec.ind2_off; | |
1483 value_size = n; | |
1484 } | |
1485 //LE32_CPU(table_rec.value); // done later, some may be order invariant | |
1486 } | |
1487 else { | |
1488 DEBUG_WARN (("Trying to read outside buffer, buffer size %#x, offset %#x, data size %#x\n", | |
1489 read_size, ind2_end-ind2_ptr+table2_rec.ind2_off, table2_rec.size)); | |
1490 } | |
1491 fr_ptr += sizeof(table2_rec); | |
1492 } else { | |
1493 WARN(("Missing code for block_type %i\n", block_type)); | |
1494 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | |
1495 if (na_head) _pst_free_list(na_head); | |
1496 DEBUG_RET(); | |
1497 return NULL; | |
1498 } | |
1499 DEBUG_EMAIL(("reading block %i (type=%#x, ref_type=%#x, value=%#x)\n", | |
1500 x, table_rec.type, table_rec.ref_type, table_rec.value)); | |
1501 | |
1502 if (!na_ptr->items[x]) { | |
1503 na_ptr->items[x] = (struct _pst_num_item*) xmalloc(sizeof(struct _pst_num_item)); | |
1504 } | |
1505 memset(na_ptr->items[x], 0, sizeof(struct _pst_num_item)); //init it | |
1506 | |
1507 // check here to see if the id of the attribute is a mapped one | |
1508 mapptr = pf->x_head; | |
1509 while (mapptr && (mapptr->map < table_rec.type)) mapptr = mapptr->next; | |
1510 if (mapptr && (mapptr->map == table_rec.type)) { | |
1511 if (mapptr->mytype == PST_MAP_ATTRIB) { | |
1512 na_ptr->items[x]->id = *((int*)mapptr->data); | |
1513 DEBUG_EMAIL(("Mapped attrib %#x to %#x\n", table_rec.type, na_ptr->items[x]->id)); | |
1514 } else if (mapptr->mytype == PST_MAP_HEADER) { | |
1515 DEBUG_EMAIL(("Internet Header mapping found %#x\n", table_rec.type)); | |
1516 na_ptr->items[x]->id = PST_ATTRIB_HEADER; | |
1517 na_ptr->items[x]->extra = mapptr->data; | |
1518 } | |
1519 } else { | |
1520 na_ptr->items[x]->id = table_rec.type; | |
1521 } | |
1522 na_ptr->items[x]->type = 0; // checked later before it is set | |
1523 /* Reference Types | |
1524 0x0002 - Signed 16bit value | |
1525 0x0003 - Signed 32bit value | |
1526 0x0004 - 4-byte floating point | |
1527 0x0005 - Floating point double | |
1528 0x0006 - Signed 64-bit int | |
1529 0x0007 - Application Time | |
1530 0x000A - 32-bit error value | |
1531 0x000B - Boolean (non-zero = true) | |
1532 0x000D - Embedded Object | |
1533 0x0014 - 8-byte signed integer (64-bit) | |
1534 0x001E - Null terminated String | |
1535 0x001F - Unicode string | |
1536 0x0040 - Systime - Filetime structure | |
1537 0x0048 - OLE Guid | |
1538 0x0102 - Binary data | |
1539 0x1003 - Array of 32bit values | |
1540 0x1014 - Array of 64bit values | |
1541 0x101E - Array of Strings | |
1542 0x1102 - Array of Binary data | |
1543 */ | |
1544 | |
1545 if (table_rec.ref_type == 0x0002 || | |
1546 table_rec.ref_type == 0x0003 || | |
1547 table_rec.ref_type == 0x000b) { | |
1548 //contains 32 bits of data | |
1549 na_ptr->items[x]->size = sizeof(int32_t); | |
1550 na_ptr->items[x]->type = table_rec.ref_type; | |
1551 na_ptr->items[x]->data = xmalloc(sizeof(int32_t)); | |
1552 memcpy(na_ptr->items[x]->data, &(table_rec.value), sizeof(int32_t)); | |
1553 | |
1554 } else if (table_rec.ref_type == 0x0005 || | |
1555 table_rec.ref_type == 0x000d || | |
1556 table_rec.ref_type == 0x0014 || | |
1557 table_rec.ref_type == 0x001e || | |
1558 table_rec.ref_type == 0x001f || | |
1559 table_rec.ref_type == 0x0040 || | |
1560 table_rec.ref_type == 0x0048 || | |
1561 table_rec.ref_type == 0x0102 || | |
1562 table_rec.ref_type == 0x1003 || | |
1563 table_rec.ref_type == 0x1014 || | |
1564 table_rec.ref_type == 0x101e || | |
1565 table_rec.ref_type == 0x1102) { | |
1566 //contains index reference to data | |
1567 LE32_CPU(table_rec.value); | |
1568 if (value_pointer) { | |
1569 // in a type 2 block, with a value that is more than 4 bytes | |
1570 // directly stored in this block. | |
1571 na_ptr->items[x]->size = value_size; | |
1572 na_ptr->items[x]->type = table_rec.ref_type; | |
1573 na_ptr->items[x]->data = xmalloc(value_size); | |
1574 memcpy(na_ptr->items[x]->data, value_pointer, value_size); | |
1575 } | |
1576 else if (_pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, table_rec.value, &block_offset7)) { | |
1577 if ((table_rec.value & 0xf) == 0xf) { | |
1578 DEBUG_WARN(("failed to get block offset for table_rec.value of %#x to be read later.\n", table_rec.value)); | |
1579 na_ptr->items[x]->size = 0; | |
1580 na_ptr->items[x]->data = NULL; | |
1581 na_ptr->items[x]->type = table_rec.value; | |
1582 } | |
1583 else { | |
1584 if (table_rec.value) { | |
1585 DEBUG_WARN(("failed to get block offset for table_rec.value of %#x\n", table_rec.value)); | |
1586 } | |
1587 na_ptr->count_item --; //we will be skipping a row | |
1588 continue; | |
1589 } | |
1590 } | |
1591 else { | |
1592 value_size = block_offset7.to - block_offset7.from; | |
1593 na_ptr->items[x]->size = value_size; | |
1594 na_ptr->items[x]->type = table_rec.ref_type; | |
1595 na_ptr->items[x]->data = xmalloc(value_size+1); | |
1596 memcpy(na_ptr->items[x]->data, block_offset7.from, value_size); | |
1597 na_ptr->items[x]->data[value_size] = '\0'; // it might be a string, null terminate it. | |
1598 } | |
1599 if (table_rec.ref_type == 0xd) { | |
1600 // there is still more to do for the type of 0xD embedded objects | |
1601 type_d_rec = (struct _type_d_rec*) na_ptr->items[x]->data; | |
1602 LE32_CPU(type_d_rec->id); | |
1603 na_ptr->items[x]->size = _pst_ff_getID2block(pf, type_d_rec->id, i2_head, &(na_ptr->items[x]->data)); | |
1604 if (!na_ptr->items[x]->size){ | |
1605 DEBUG_WARN(("not able to read the ID2 data. Setting to be read later. %#x\n", type_d_rec->id)); | |
1606 na_ptr->items[x]->type = type_d_rec->id; // fetch before freeing data, alias pointer | |
1607 free(na_ptr->items[x]->data); | |
1608 na_ptr->items[x]->data = NULL; | |
1609 } | |
1610 } | |
1611 if (table_rec.ref_type == 0x1f) { | |
1612 // there is more to do for the type 0x1f unicode strings | |
1613 VBUF_STATIC(strbuf, 1024); | |
1614 VBUF_STATIC(unibuf, 1024); | |
1615 //need UTF-16 zero-termination | |
1616 vbset(strbuf, na_ptr->items[x]->data, na_ptr->items[x]->size); | |
1617 vbappend(strbuf, "\0\0", 2); | |
44 | 1618 DEBUG_INDEX(("Iconv in:\n")); |
43 | 1619 DEBUG_HEXDUMPC(strbuf->b, strbuf->dlen, 0x10); |
1620 vb_utf16to8(unibuf, strbuf->b, strbuf->dlen); | |
1621 free(na_ptr->items[x]->data); | |
1622 na_ptr->items[x]->size = unibuf->dlen; | |
1623 na_ptr->items[x]->data = xmalloc(unibuf->dlen); | |
1624 memcpy(na_ptr->items[x]->data, unibuf->b, unibuf->dlen); | |
44 | 1625 DEBUG_INDEX(("Iconv out:\n")); |
43 | 1626 DEBUG_HEXDUMPC(na_ptr->items[x]->data, na_ptr->items[x]->size, 0x10); |
1627 } | |
1628 if (na_ptr->items[x]->type == 0) na_ptr->items[x]->type = table_rec.ref_type; | |
1629 } else { | |
1630 WARN(("ERROR Unknown ref_type %#x\n", table_rec.ref_type)); | |
1631 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | |
1632 if (na_head) _pst_free_list(na_head); | |
1633 DEBUG_RET(); | |
1634 return NULL; | |
1635 } | |
1636 x++; | |
1637 } | |
1638 DEBUG_EMAIL(("increasing ind2_ptr by %i [%#x] bytes. Was %#x, Now %#x\n", rec_size, rec_size, ind2_ptr, ind2_ptr+rec_size)); | |
1639 ind2_ptr += rec_size; | |
1640 } | |
1641 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); | |
1642 DEBUG_RET(); | |
1643 return na_head; | |
16 | 1644 } |
1645 | |
1646 | |
1647 // check if item->email is NULL, and init if so | |
43 | 1648 #define MALLOC_EMAIL(x) { if (!x->email) { x->email = (pst_item_email*) xmalloc(sizeof(pst_item_email)); memset(x->email, 0, sizeof(pst_item_email) );} } |
1649 #define MALLOC_FOLDER(x) { if (!x->folder) { x->folder = (pst_item_folder*) xmalloc(sizeof(pst_item_folder)); memset(x->folder, 0, sizeof(pst_item_folder) );} } | |
1650 #define MALLOC_CONTACT(x) { if (!x->contact) { x->contact = (pst_item_contact*) xmalloc(sizeof(pst_item_contact)); memset(x->contact, 0, sizeof(pst_item_contact) );} } | |
16 | 1651 #define MALLOC_MESSAGESTORE(x) { if (!x->message_store) { x->message_store = (pst_item_message_store*) xmalloc(sizeof(pst_item_message_store)); memset(x->message_store, 0, sizeof(pst_item_message_store));} } |
43 | 1652 #define MALLOC_JOURNAL(x) { if (!x->journal) { x->journal = (pst_item_journal*) xmalloc(sizeof(pst_item_journal)); memset(x->journal, 0, sizeof(pst_item_journal) );} } |
1653 #define MALLOC_APPOINTMENT(x) { if (!x->appointment) { x->appointment = (pst_item_appointment*) xmalloc(sizeof(pst_item_appointment)); memset(x->appointment, 0, sizeof(pst_item_appointment) );} } | |
41
183ae993b9ad
security fix for potential buffer overrun in lz decompress
carl
parents:
40
diff
changeset
|
1654 // malloc space and copy the current item's data null terminated |
43 | 1655 #define LIST_COPY(targ, type) { \ |
1656 targ = type realloc(targ, list->items[x]->size+1); \ | |
1657 memcpy(targ, list->items[x]->data, list->items[x]->size); \ | |
1658 memset(((char*)targ)+list->items[x]->size, 0, 1); \ | |
41
183ae993b9ad
security fix for potential buffer overrun in lz decompress
carl
parents:
40
diff
changeset
|
1659 } |
183ae993b9ad
security fix for potential buffer overrun in lz decompress
carl
parents:
40
diff
changeset
|
1660 // malloc space and copy the current item's data and size |
43 | 1661 #define LIST_COPY_SIZE(targ, type, mysize) { \ |
1662 mysize = list->items[x]->size; \ | |
1663 targ = type realloc(targ, mysize); \ | |
1664 memcpy(targ, list->items[x]->data, mysize); \ | |
16 | 1665 } |
1666 | |
1667 #define NULL_CHECK(x) { if (!x) { DEBUG_EMAIL(("NULL_CHECK: Null Found\n")); break;} } | |
1668 | |
1669 #define MOVE_NEXT(targ) { \ | |
43 | 1670 if (next){\ |
1671 if (!targ) {\ | |
1672 DEBUG_EMAIL(("MOVE_NEXT: Target is NULL. Will stop processing this option\n"));\ | |
1673 break;\ | |
1674 }\ | |
1675 targ = targ->next;\ | |
1676 if (!targ) {\ | |
1677 DEBUG_EMAIL(("MOVE_NEXT: Target is NULL after next. Will stop processing this option\n"));\ | |
1678 break;\ | |
1679 }\ | |
1680 next=0;\ | |
1681 }\ | |
16 | 1682 } |
1683 | |
1684 | |
39 | 1685 int32_t _pst_process(pst_num_array *list , pst_item *item, pst_item_attach *attach) { |
43 | 1686 int32_t x, t; |
1687 int32_t next = 0; | |
1688 pst_item_extra_field *ef; | |
1689 | |
1690 DEBUG_ENT("_pst_process"); | |
1691 if (!item) { | |
1692 DEBUG_EMAIL(("item cannot be NULL.\n")); | |
1693 DEBUG_RET(); | |
1694 return -1; | |
1695 } | |
1696 | |
1697 while (list) { | |
1698 x = 0; | |
1699 while (x < list->count_item) { | |
1700 // check here to see if the id is one that is mapped. | |
1701 DEBUG_EMAIL(("#%d - id: %#x type: %#x length: %#x\n", x, list->items[x]->id, list->items[x]->type, list->items[x]->size)); | |
1702 | |
1703 switch (list->items[x]->id) { | |
1704 case PST_ATTRIB_HEADER: // CUSTOM attribute for saying the Extra Headers | |
1705 DEBUG_EMAIL(("Extra Field - ")); | |
1706 ef = (pst_item_extra_field*) xmalloc(sizeof(pst_item_extra_field)); | |
1707 memset(ef, 0, sizeof(pst_item_extra_field)); | |
1708 ef->field_name = (char*) xmalloc(strlen(list->items[x]->extra)+1); | |
1709 strcpy(ef->field_name, list->items[x]->extra); | |
1710 LIST_COPY(ef->value, (char*)); | |
1711 ef->next = item->extra_fields; | |
1712 item->extra_fields = ef; | |
1713 DEBUG_EMAIL(("\"%s\" = \"%s\"\n", ef->field_name, ef->value)); | |
1714 break; | |
1715 case 0x0002: // PR_ALTERNATE_RECIPIENT_ALLOWED | |
1716 // If set to true, the sender allows this email to be autoforwarded | |
1717 DEBUG_EMAIL(("AutoForward allowed - ")); | |
1718 MALLOC_EMAIL(item); | |
1719 if (*((short int*)list->items[x]->data) != 0) { | |
1720 DEBUG_EMAIL(("True\n")); | |
1721 item->email->autoforward = 1; | |
1722 } else { | |
1723 DEBUG_EMAIL(("False\n")); | |
1724 item->email->autoforward = -1; | |
1725 } | |
1726 break; | |
1727 case 0x0003: // Extended Attributes table | |
1728 DEBUG_EMAIL(("Extended Attributes Table - NOT PROCESSED\n")); | |
1729 break; | |
1730 case 0x0017: // PR_IMPORTANCE | |
1731 // How important the sender deems it to be | |
1732 // 0 - Low | |
1733 // 1 - Normal | |
1734 // 2 - High | |
1735 | |
1736 DEBUG_EMAIL(("Importance Level - ")); | |
1737 MALLOC_EMAIL(item); | |
1738 memcpy(&(item->email->importance), list->items[x]->data, sizeof(item->email->importance)); | |
1739 LE32_CPU(item->email->importance); | |
1740 t = item->email->importance; | |
1741 DEBUG_EMAIL(("%s [%i]\n", (t==0?"Low":(t==1?"Normal":"High")), t)); | |
1742 break; | |
1743 case 0x001A: // PR_MESSAGE_CLASS Ascii type of messages - NOT FOLDERS | |
1744 // must be case insensitive | |
1745 DEBUG_EMAIL(("IPM.x - ")); | |
1746 LIST_COPY(item->ascii_type, (char*)); | |
1747 if (pst_strincmp("IPM.Note", item->ascii_type, 8) == 0) | |
1748 // the string begins with IPM.Note... | |
1749 item->type = PST_TYPE_NOTE; | |
1750 else if (pst_stricmp("IPM", item->ascii_type) == 0) | |
1751 // the whole string is just IPM | |
1752 item->type = PST_TYPE_NOTE; | |
1753 else if (pst_strincmp("IPM.Contact", item->ascii_type, 11) == 0) | |
1754 // the string begins with IPM.Contact... | |
1755 item->type = PST_TYPE_CONTACT; | |
1756 else if (pst_strincmp("REPORT.IPM.Note", item->ascii_type, 15) == 0) | |
1757 // the string begins with the above | |
1758 item->type = PST_TYPE_REPORT; | |
1759 else if (pst_strincmp("IPM.Activity", item->ascii_type, 12) == 0) | |
1760 item->type = PST_TYPE_JOURNAL; | |
1761 else if (pst_strincmp("IPM.Appointment", item->ascii_type, 15) == 0) | |
1762 item->type = PST_TYPE_APPOINTMENT; | |
1763 else | |
1764 item->type = PST_TYPE_OTHER; | |
1765 | |
1766 DEBUG_EMAIL(("%s\n", item->ascii_type)); | |
1767 break; | |
1768 case 0x0023: // PR_ORIGINATOR_DELIVERY_REPORT_REQUESTED | |
1769 // set if the sender wants a delivery report from all recipients | |
1770 DEBUG_EMAIL(("Global Delivery Report - ")); | |
1771 MALLOC_EMAIL(item); | |
1772 if (*(int16_t*)list->items[x]->data != 0) { | |
1773 DEBUG_EMAIL(("True\n")); | |
1774 item->email->delivery_report = 1; | |
1775 } else { | |
1776 DEBUG_EMAIL(("False\n")); | |
1777 item->email->delivery_report = 0; | |
1778 } | |
1779 break; | |
1780 case 0x0026: // PR_PRIORITY | |
1781 // Priority of a message | |
1782 // -1 NonUrgent | |
1783 // 0 Normal | |
1784 // 1 Urgent | |
1785 DEBUG_EMAIL(("Priority - ")); | |
1786 MALLOC_EMAIL(item); | |
1787 memcpy(&(item->email->priority), list->items[x]->data, sizeof(item->email->priority)); | |
1788 LE32_CPU(item->email->priority); | |
1789 t = item->email->priority; | |
1790 DEBUG_EMAIL(("%s [%i]\n", (t<0?"NonUrgent":(t==0?"Normal":"Urgent")), t)); | |
1791 break; | |
1792 case 0x0029:// PR_READ_RECEIPT_REQUESTED | |
1793 DEBUG_EMAIL(("Read Receipt - ")); | |
1794 MALLOC_EMAIL(item); | |
1795 if (*(short int*)list->items[x]->data != 0) { | |
1796 DEBUG_EMAIL(("True\n")); | |
1797 item->email->read_receipt = 1; | |
1798 } else { | |
1799 DEBUG_EMAIL(("False\n")); | |
1800 item->email->read_receipt = 0; | |
1801 } | |
1802 break; | |
1803 case 0x002B: // PR_RECIPIENT_REASSIGNMENT_PROHIBITED | |
1804 DEBUG_EMAIL(("Reassignment Prohibited (Private) - ")); | |
1805 if (*(short int*)list->items[x]->data != 0) { | |
1806 DEBUG_EMAIL(("True\n")); | |
1807 item->private_member = 1; | |
1808 } else { | |
1809 DEBUG_EMAIL(("False\n")); | |
1810 item->private_member = 0; | |
1811 } | |
1812 break; | |
1813 case 0x002E: // PR_ORIGINAL_SENSITIVITY | |
1814 // the sensitivity of the message before being replied to or forwarded | |
1815 // 0 - None | |
1816 // 1 - Personal | |
1817 // 2 - Private | |
1818 // 3 - Company Confidential | |
1819 DEBUG_EMAIL(("Original Sensitivity - ")); | |
1820 MALLOC_EMAIL(item); | |
1821 memcpy(&(item->email->orig_sensitivity), list->items[x]->data, sizeof(item->email->orig_sensitivity)); | |
1822 LE32_CPU(item->email->orig_sensitivity); | |
1823 t = item->email->orig_sensitivity; | |
1824 DEBUG_EMAIL(("%s [%i]\n", (t==0?"None":(t==1?"Personal": | |
1825 (t==2?"Private":"Company Confidential"))), t)); | |
1826 break; | |
1827 case 0x0036: // PR_SENSITIVITY | |
1828 // sender's opinion of the sensitivity of an email | |
1829 // 0 - None | |
1830 // 1 - Personal | |
1831 // 2 - Private | |
1832 // 3 - Company Confidiential | |
1833 DEBUG_EMAIL(("Sensitivity - ")); | |
1834 MALLOC_EMAIL(item); | |
1835 memcpy(&(item->email->sensitivity), list->items[x]->data, sizeof(item->email->sensitivity)); | |
1836 LE32_CPU(item->email->sensitivity); | |
1837 t = item->email->sensitivity; | |
1838 DEBUG_EMAIL(("%s [%i]\n", (t==0?"None":(t==1?"Personal": | |
1839 (t==2?"Private":"Company Confidential"))), t)); | |
1840 break; | |
1841 case 0x0037: // PR_SUBJECT raw subject | |
1842 // if (list->items[x]->id == 0x0037) { | |
1843 DEBUG_EMAIL(("Raw Subject - ")); | |
1844 MALLOC_EMAIL(item); | |
1845 item->email->subject = (pst_item_email_subject*) realloc(item->email->subject, sizeof(pst_item_email_subject)); | |
1846 memset(item->email->subject, 0, sizeof(pst_item_email_subject)); | |
1847 DEBUG_EMAIL((" [size = %i] ", list->items[x]->size)); | |
1848 if (list->items[x]->size > 0) { | |
1849 if (isprint(list->items[x]->data[0])) { | |
1850 // then there are no control bytes at the front | |
1851 item->email->subject->off1 = 0; | |
1852 item->email->subject->off2 = 0; | |
1853 item->email->subject->subj = realloc(item->email->subject->subj, list->items[x]->size+1); | |
1854 memset(item->email->subject->subj, 0, list->items[x]->size+1); | |
1855 memcpy(item->email->subject->subj, list->items[x]->data, list->items[x]->size); | |
1856 } else { | |
1857 DEBUG_EMAIL(("Raw Subject has control codes\n")); | |
1858 // there might be some control bytes in the first and second bytes | |
1859 item->email->subject->off1 = list->items[x]->data[0]; | |
1860 item->email->subject->off2 = list->items[x]->data[1]; | |
1861 item->email->subject->subj = realloc(item->email->subject->subj, (list->items[x]->size-2)+1); | |
1862 memset(item->email->subject->subj, 0, list->items[x]->size-1); | |
1863 memcpy(item->email->subject->subj, &(list->items[x]->data[2]), list->items[x]->size-2); | |
1864 } | |
1865 DEBUG_EMAIL(("%s\n", item->email->subject->subj)); | |
1866 } else { | |
1867 // obviously outlook has decided not to be straight with this one. | |
1868 item->email->subject->off1 = 0; | |
1869 item->email->subject->off2 = 0; | |
1870 item->email->subject = NULL; | |
1871 DEBUG_EMAIL(("NULL subject detected\n")); | |
1872 } | |
1873 break; | |
1874 case 0x0039: // PR_CLIENT_SUBMIT_TIME Date Email Sent/Created | |
1875 DEBUG_EMAIL(("Date sent - ")); | |
1876 MALLOC_EMAIL(item); | |
1877 LIST_COPY(item->email->sent_date, (FILETIME*)); | |
1878 LE32_CPU(item->email->sent_date->dwLowDateTime); | |
1879 LE32_CPU(item->email->sent_date->dwHighDateTime); | |
1880 DEBUG_EMAIL(("%s", fileTimeToAscii(item->email->sent_date))); | |
1881 break; | |
1882 case 0x003B: // PR_SENT_REPRESENTING_SEARCH_KEY Sender address 1 | |
1883 DEBUG_EMAIL(("Sent on behalf of address 1 - ")); | |
1884 MALLOC_EMAIL(item); | |
1885 LIST_COPY(item->email->outlook_sender, (char*)); | |
1886 DEBUG_EMAIL(("%s\n", item->email->outlook_sender)); | |
1887 break; | |
1888 case 0x003F: // PR_RECEIVED_BY_ENTRYID Structure containing Recipient | |
1889 DEBUG_EMAIL(("Recipient Structure 1 -- NOT HANDLED\n")); | |
1890 break; | |
1891 case 0x0040: // PR_RECEIVED_BY_NAME Name of Recipient Structure | |
1892 DEBUG_EMAIL(("Received By Name 1 -- NOT HANDLED\n")); | |
1893 break; | |
1894 case 0x0041: // PR_SENT_REPRESENTING_ENTRYID Structure containing Sender | |
1895 DEBUG_EMAIL(("Sent on behalf of Structure 1 -- NOT HANDLED\n")); | |
1896 break; | |
1897 case 0x0042: // PR_SENT_REPRESENTING_NAME Name of Sender Structure | |
1898 DEBUG_EMAIL(("Sent on behalf of Structure Name - ")); | |
1899 MALLOC_EMAIL(item); | |
1900 LIST_COPY(item->email->outlook_sender_name, (char*)); | |
1901 DEBUG_EMAIL(("%s\n", item->email->outlook_sender_name)); | |
1902 break; | |
1903 case 0x0043: // PR_RCVD_REPRESENTING_ENTRYID Recipient Structure 2 | |
1904 DEBUG_EMAIL(("Received on behalf of Structure -- NOT HANDLED\n")); | |
1905 break; | |
1906 case 0x0044: // PR_RCVD_REPRESENTING_NAME Name of Recipient Structure 2 | |
1907 DEBUG_EMAIL(("Received on behalf of Structure Name -- NOT HANDLED\n")); | |
1908 break; | |
1909 case 0x004F: // PR_REPLY_RECIPIENT_ENTRIES Reply-To Structure | |
1910 DEBUG_EMAIL(("Reply-To Structure -- NOT HANDLED\n")); | |
1911 break; | |
1912 case 0x0050: // PR_REPLY_RECIPIENT_NAMES Name of Reply-To Structure | |
1913 DEBUG_EMAIL(("Name of Reply-To Structure -")); | |
1914 MALLOC_EMAIL(item); | |
1915 LIST_COPY(item->email->reply_to, (char*)); | |
1916 DEBUG_EMAIL(("%s\n", item->email->reply_to)); | |
1917 break; | |
1918 case 0x0051: // PR_RECEIVED_BY_SEARCH_KEY Recipient Address 1 | |
1919 DEBUG_EMAIL(("Recipient's Address 1 (Search Key) - ")); | |
1920 MALLOC_EMAIL(item); | |
1921 LIST_COPY (item->email->outlook_recipient, (char*)); | |
1922 DEBUG_EMAIL(("%s\n", item->email->outlook_recipient)); | |
1923 break; | |
1924 case 0x0052: // PR_RCVD_REPRESENTING_SEARCH_KEY Recipient Address 2 | |
1925 DEBUG_EMAIL(("Received on behalf of Address (Search Key) - ")); | |
1926 MALLOC_EMAIL(item); | |
1927 LIST_COPY(item->email->outlook_recipient2, (char*)); | |
1928 DEBUG_EMAIL(("%s\n", item->email->outlook_recipient2)); | |
1929 break; | |
1930 case 0x0057: // PR_MESSAGE_TO_ME | |
1931 // this user is listed explicitly in the TO address | |
1932 DEBUG_EMAIL(("My address in TO field - ")); | |
1933 MALLOC_EMAIL(item); | |
1934 if (*(int16_t*)list->items[x]->data != 0) { | |
1935 DEBUG_EMAIL(("True\n")); | |
1936 item->email->message_to_me = 1; | |
1937 } else { | |
1938 DEBUG_EMAIL(("False\n")); | |
1939 item->email->message_to_me = 0; | |
1940 } | |
1941 break; | |
1942 case 0x0058: // PR_MESSAGE_CC_ME | |
1943 // this user is listed explicitly in the CC address | |
1944 DEBUG_EMAIL(("My address in CC field - ")); | |
1945 MALLOC_EMAIL(item); | |
1946 if (*(int16_t*)list->items[x]->data != 0) { | |
1947 DEBUG_EMAIL(("True\n")); | |
1948 item->email->message_cc_me = 1; | |
1949 } else { | |
1950 DEBUG_EMAIL(("False\n")); | |
1951 item->email->message_cc_me = 0; | |
1952 } | |
1953 break; | |
1954 case 0x0059: //PR_MESSAGE_RECIP_ME | |
1955 // this user appears in TO, CC or BCC address list | |
1956 DEBUG_EMAIL(("Message addressed to me - ")); | |
1957 MALLOC_EMAIL(item); | |
1958 if (*(int16_t*)list->items[x]->data != 0) { | |
1959 DEBUG_EMAIL(("True\n")); | |
1960 item->email->message_recip_me = 1; | |
1961 } else { | |
1962 DEBUG_EMAIL(("False\n")); | |
1963 item->email->message_recip_me = 0; | |
1964 } | |
1965 break; | |
1966 case 0x0063: // PR_RESPONSE_REQUESTED | |
1967 DEBUG_EMAIL(("Response requested - ")); | |
1968 if (*(int16_t*)list->items[x]->data != 0) { | |
1969 DEBUG_EMAIL(("True\n")); | |
1970 item->response_requested = 1; | |
1971 } else { | |
1972 DEBUG_EMAIL(("False\n")); | |
1973 item->response_requested = 0; | |
1974 } | |
1975 break; | |
1976 case 0x0064: // PR_SENT_REPRESENTING_ADDRTYPE Access method for Sender Address | |
1977 DEBUG_EMAIL(("Sent on behalf of address type - ")); | |
1978 MALLOC_EMAIL(item); | |
1979 LIST_COPY(item->email->sender_access, (char*)); | |
1980 DEBUG_EMAIL(("%s\n", item->email->sender_access)); | |
1981 break; | |
1982 case 0x0065: // PR_SENT_REPRESENTING_EMAIL_ADDRESS Sender Address | |
1983 DEBUG_EMAIL(("Sent on behalf of Address - ")); | |
1984 MALLOC_EMAIL(item); | |
1985 LIST_COPY(item->email->sender_address, (char*)); | |
1986 DEBUG_EMAIL(("%s\n", item->email->sender_address)); | |
1987 break; | |
1988 case 0x0070: // PR_CONVERSATION_TOPIC Processed Subject | |
1989 DEBUG_EMAIL(("Processed Subject (Conversation Topic) - ")); | |
1990 MALLOC_EMAIL(item); | |
1991 LIST_COPY(item->email->proc_subject, (char*)); | |
1992 DEBUG_EMAIL(("%s\n", item->email->proc_subject)); | |
1993 break; | |
1994 case 0x0071: // PR_CONVERSATION_INDEX Date 2 | |
1995 DEBUG_EMAIL(("Conversation Index - ")); | |
1996 MALLOC_EMAIL(item); | |
1997 memcpy(&(item->email->conv_index), list->items[x]->data, sizeof(item->email->conv_index)); | |
1998 DEBUG_EMAIL(("%i\n", item->email->conv_index)); | |
1999 break; | |
2000 case 0x0075: // PR_RECEIVED_BY_ADDRTYPE Recipient Access Method | |
2001 DEBUG_EMAIL(("Received by Address type - ")); | |
2002 MALLOC_EMAIL(item); | |
2003 LIST_COPY(item->email->recip_access, (char*)); | |
2004 DEBUG_EMAIL(("%s\n", item->email->recip_access)); | |
2005 break; | |
2006 case 0x0076: // PR_RECEIVED_BY_EMAIL_ADDRESS Recipient Address | |
2007 DEBUG_EMAIL(("Received by Address - ")); | |
2008 MALLOC_EMAIL(item); | |
2009 LIST_COPY(item->email->recip_address, (char*)); | |
2010 DEBUG_EMAIL(("%s\n", item->email->recip_address)); | |
2011 break; | |
2012 case 0x0077: // PR_RCVD_REPRESENTING_ADDRTYPE Recipient Access Method 2 | |
2013 DEBUG_EMAIL(("Received on behalf of Address type - ")); | |
2014 MALLOC_EMAIL(item); | |
2015 LIST_COPY(item->email->recip2_access, (char*)); | |
2016 DEBUG_EMAIL(("%s\n", item->email->recip2_access)); | |
2017 break; | |
2018 case 0x0078: // PR_RCVD_REPRESENTING_EMAIL_ADDRESS Recipient Address 2 | |
2019 DEBUG_EMAIL(("Received on behalf of Address -")); | |
2020 MALLOC_EMAIL(item); | |
2021 LIST_COPY(item->email->recip2_address, (char*)); | |
2022 DEBUG_EMAIL(("%s\n", item->email->recip2_address)); | |
2023 break; | |
2024 case 0x007D: // PR_TRANSPORT_MESSAGE_HEADERS Internet Header | |
2025 DEBUG_EMAIL(("Internet Header - ")); | |
2026 MALLOC_EMAIL(item); | |
2027 LIST_COPY(item->email->header, (char*)); | |
2028 //DEBUG_EMAIL(("%s\n", item->email->header)); | |
2029 DEBUG_EMAIL(("NOT PRINTED\n")); | |
2030 break; | |
2031 case 0x0C17: // PR_REPLY_REQUESTED | |
2032 DEBUG_EMAIL(("Reply Requested - ")); | |
2033 MALLOC_EMAIL(item); | |
2034 if (*(int16_t*)list->items[x]->data != 0) { | |
2035 DEBUG_EMAIL(("True\n")); | |
2036 item->email->reply_requested = 1; | |
2037 } else { | |
2038 DEBUG_EMAIL(("False\n")); | |
2039 item->email->reply_requested = 0; | |
2040 } | |
2041 break; | |
2042 case 0x0C19: // PR_SENDER_ENTRYID Sender Structure 2 | |
2043 DEBUG_EMAIL(("Sender Structure 2 -- NOT HANDLED\n")); | |
2044 break; | |
2045 case 0x0C1A: // PR_SENDER_NAME Name of Sender Structure 2 | |
2046 DEBUG_EMAIL(("Name of Sender Structure 2 -- NOT HANDLED\n")); | |
2047 break; | |
2048 case 0x0C1D: // PR_SENDER_SEARCH_KEY Name of Sender Address 2 | |
2049 DEBUG_EMAIL(("Name of Sender Address 2 (Sender search key) - ")); | |
2050 MALLOC_EMAIL(item); | |
2051 LIST_COPY(item->email->outlook_sender2, (char*)); | |
2052 DEBUG_EMAIL(("%s\n", item->email->outlook_sender2)); | |
2053 break; | |
2054 case 0x0C1E: // PR_SENDER_ADDRTYPE Sender Address 2 access method | |
2055 DEBUG_EMAIL(("Sender Address type - ")); | |
2056 MALLOC_EMAIL(item); | |
2057 LIST_COPY(item->email->sender2_access, (char*)); | |
2058 DEBUG_EMAIL(("%s\n", item->email->sender2_access)); | |
2059 break; | |
2060 case 0x0C1F: // PR_SENDER_EMAIL_ADDRESS Sender Address 2 | |
2061 DEBUG_EMAIL(("Sender Address - ")); | |
2062 MALLOC_EMAIL(item); | |
2063 LIST_COPY(item->email->sender2_address, (char*)); | |
2064 DEBUG_EMAIL(("%s\n", item->email->sender2_address)); | |
2065 break; | |
2066 case 0x0E01: // PR_DELETE_AFTER_SUBMIT | |
2067 // I am not too sure how this works | |
2068 DEBUG_EMAIL(("Delete after submit - ")); | |
2069 MALLOC_EMAIL(item); | |
2070 if (*(int16_t*) list->items[x]->data != 0) { | |
2071 DEBUG_EMAIL(("True\n")); | |
2072 item->email->delete_after_submit = 1; | |
2073 } else { | |
2074 DEBUG_EMAIL(("False\n")); | |
2075 item->email->delete_after_submit = 0; | |
2076 } | |
2077 break; | |
2078 case 0x0E03: // PR_DISPLAY_CC CC Addresses | |
2079 DEBUG_EMAIL(("Display CC Addresses - ")); | |
2080 MALLOC_EMAIL(item); | |
2081 LIST_COPY(item->email->cc_address, (char*)); | |
2082 DEBUG_EMAIL(("%s\n", item->email->cc_address)); | |
2083 break; | |
2084 case 0x0E04: // PR_DISPLAY_TO Address Sent-To | |
2085 DEBUG_EMAIL(("Display Sent-To Address - ")); | |
2086 MALLOC_EMAIL(item); | |
2087 LIST_COPY(item->email->sentto_address, (char*)); | |
2088 DEBUG_EMAIL(("%s\n", item->email->sentto_address)); | |
2089 break; | |
2090 case 0x0E06: // PR_MESSAGE_DELIVERY_TIME Date 3 - Email Arrival Date | |
2091 DEBUG_EMAIL(("Date 3 (Delivery Time) - ")); | |
2092 MALLOC_EMAIL(item); | |
2093 LIST_COPY(item->email->arrival_date, (FILETIME*)); | |
2094 DEBUG_EMAIL(("%s", fileTimeToAscii(item->email->arrival_date))); | |
2095 break; | |
2096 case 0x0E07: // PR_MESSAGE_FLAGS Email Flag | |
2097 // 0x01 - Read | |
2098 // 0x02 - Unmodified | |
2099 // 0x04 - Submit | |
2100 // 0x08 - Unsent | |
2101 // 0x10 - Has Attachments | |
2102 // 0x20 - From Me | |
2103 // 0x40 - Associated | |
2104 // 0x80 - Resend | |
2105 // 0x100 - RN Pending | |
2106 // 0x200 - NRN Pending | |
2107 DEBUG_EMAIL(("Message Flags - ")); | |
2108 MALLOC_EMAIL(item); | |
2109 memcpy(&(item->email->flag), list->items[x]->data, sizeof(item->email->flag)); | |
2110 LE32_CPU(item->email->flag); | |
2111 DEBUG_EMAIL(("%i\n", item->email->flag)); | |
2112 break; | |
2113 case 0x0E08: // PR_MESSAGE_SIZE Total size of a message object | |
2114 DEBUG_EMAIL(("Message Size - ")); | |
2115 memcpy(&(item->message_size), list->items[x]->data, sizeof(item->message_size)); | |
2116 LE32_CPU(item->message_size); | |
2117 DEBUG_EMAIL(("%i [%#x]\n", item->message_size, item->message_size)); | |
2118 break; | |
2119 case 0x0E0A: // PR_SENTMAIL_ENTRYID | |
2120 // folder that this message is sent to after submission | |
2121 DEBUG_EMAIL(("Sentmail EntryID - ")); | |
2122 MALLOC_EMAIL(item); | |
2123 LIST_COPY(item->email->sentmail_folder, (pst_entryid*)); | |
2124 LE32_CPU(item->email->sentmail_folder->id); | |
2125 DEBUG_EMAIL(("[id = %#x]\n", item->email->sentmail_folder->id)); | |
2126 break; | |
2127 case 0x0E1F: // PR_RTF_IN_SYNC | |
2128 // True means that the rtf version is same as text body | |
2129 // False means rtf version is more up-to-date than text body | |
2130 // if this value doesn't exist, text body is more up-to-date than rtf and | |
2131 // cannot update to the rtf | |
2132 DEBUG_EMAIL(("Compressed RTF in Sync - ")); | |
2133 MALLOC_EMAIL(item); | |
2134 if (*(int16_t*)list->items[x]->data != 0) { | |
2135 DEBUG_EMAIL(("True\n")); | |
2136 item->email->rtf_in_sync = 1; | |
2137 } else { | |
2138 DEBUG_EMAIL(("False\n")); | |
2139 item->email->rtf_in_sync = 0; | |
2140 } | |
2141 break; | |
2142 case 0x0E20: // PR_ATTACH_SIZE binary Attachment data in record | |
2143 DEBUG_EMAIL(("Attachment Size - ")); | |
2144 NULL_CHECK(attach); | |
2145 MOVE_NEXT(attach); | |
2146 memcpy(&(attach->size), list->items[x]->data, sizeof(attach->size)); | |
2147 DEBUG_EMAIL(("%i\n", attach->size)); | |
2148 break; | |
2149 case 0x0FF9: // PR_RECORD_KEY Record Header 1 | |
2150 DEBUG_EMAIL(("Record Key 1 - ")); | |
2151 LIST_COPY(item->record_key, (char*)); | |
2152 item->record_key_size = list->items[x]->size; | |
2153 DEBUG_EMAIL_HEXPRINT(item->record_key, item->record_key_size); | |
2154 DEBUG_EMAIL(("\n")); | |
2155 break; | |
2156 case 0x1000: // PR_BODY Plain Text body | |
2157 DEBUG_EMAIL(("Plain Text body - ")); | |
2158 MALLOC_EMAIL(item); | |
2159 LIST_COPY(item->email->body, (char*)); | |
2160 //DEBUG_EMAIL("%s\n", item->email->body); | |
2161 DEBUG_EMAIL(("NOT PRINTED\n")); | |
2162 break; | |
2163 case 0x1006: // PR_RTF_SYNC_BODY_CRC | |
2164 DEBUG_EMAIL(("RTF Sync Body CRC - ")); | |
2165 MALLOC_EMAIL(item); | |
2166 memcpy(&(item->email->rtf_body_crc), list->items[x]->data, sizeof(item->email->rtf_body_crc)); | |
2167 LE32_CPU(item->email->rtf_body_crc); | |
2168 DEBUG_EMAIL(("%#x\n", item->email->rtf_body_crc)); | |
2169 break; | |
2170 case 0x1007: // PR_RTF_SYNC_BODY_COUNT | |
2171 // a count of the *significant* charcters in the rtf body. Doesn't count | |
2172 // whitespace and other ignorable characters | |
2173 DEBUG_EMAIL(("RTF Sync Body character count - ")); | |
2174 MALLOC_EMAIL(item); | |
2175 memcpy(&(item->email->rtf_body_char_count), list->items[x]->data, sizeof(item->email->rtf_body_char_count)); | |
2176 LE32_CPU(item->email->rtf_body_char_count); | |
2177 DEBUG_EMAIL(("%i [%#x]\n", item->email->rtf_body_char_count, item->email->rtf_body_char_count)); | |
2178 break; | |
2179 case 0x1008: // PR_RTF_SYNC_BODY_TAG | |
2180 // the first couple of lines of RTF body so that after modification, then beginning can | |
2181 // once again be found | |
2182 DEBUG_EMAIL(("RTF Sync body tag - ")); | |
2183 MALLOC_EMAIL(item); | |
2184 LIST_COPY(item->email->rtf_body_tag, (char*)); | |
2185 DEBUG_EMAIL(("%s\n", item->email->rtf_body_tag)); | |
2186 break; | |
2187 case 0x1009: // PR_RTF_COMPRESSED | |
2188 // some compression algorithm has been applied to this. At present | |
2189 // it is unknown | |
2190 DEBUG_EMAIL(("RTF Compressed body - ")); | |
2191 MALLOC_EMAIL(item); | |
2192 LIST_COPY_SIZE(item->email->rtf_compressed, (char*), item->email->rtf_compressed_size); | |
2193 DEBUG_EMAIL(("NOT PRINTED\n")); | |
2194 break; | |
2195 case 0x1010: // PR_RTF_SYNC_PREFIX_COUNT | |
2196 // a count of the ignored characters before the first significant character | |
2197 DEBUG_EMAIL(("RTF whitespace prefix count - ")); | |
2198 MALLOC_EMAIL(item); | |
2199 memcpy(&(item->email->rtf_ws_prefix_count), list->items[x]->data, sizeof(item->email->rtf_ws_prefix_count)); | |
2200 DEBUG_EMAIL(("%i\n", item->email->rtf_ws_prefix_count)); | |
2201 break; | |
2202 case 0x1011: // PR_RTF_SYNC_TRAILING_COUNT | |
2203 // a count of the ignored characters after the last significant character | |
2204 DEBUG_EMAIL(("RTF whitespace tailing count - ")); | |
2205 MALLOC_EMAIL(item); | |
2206 memcpy(&(item->email->rtf_ws_trailing_count), list->items[x]->data, sizeof(item->email->rtf_ws_trailing_count)); | |
2207 DEBUG_EMAIL(("%i\n", item->email->rtf_ws_trailing_count)); | |
2208 break; | |
2209 case 0x1013: // HTML body | |
2210 DEBUG_EMAIL(("HTML body - ")); | |
2211 MALLOC_EMAIL(item); | |
2212 LIST_COPY(item->email->htmlbody, (char*)); | |
2213 // DEBUG_EMAIL(("%s\n", item->email->htmlbody)); | |
2214 DEBUG_EMAIL(("NOT PRINTED\n")); | |
2215 break; | |
2216 case 0x1035: // Message ID | |
2217 DEBUG_EMAIL(("Message ID - ")); | |
2218 MALLOC_EMAIL(item); | |
2219 LIST_COPY(item->email->messageid, (char*)); | |
2220 DEBUG_EMAIL(("%s\n", item->email->messageid)); | |
2221 break; | |
2222 case 0x1042: // in-reply-to | |
2223 DEBUG_EMAIL(("In-Reply-To - ")); | |
2224 MALLOC_EMAIL(item); | |
2225 LIST_COPY(item->email->in_reply_to, (char*)); | |
2226 DEBUG_EMAIL(("%s\n", item->email->in_reply_to)); | |
2227 break; | |
2228 case 0x1046: // Return Path | |
2229 DEBUG_EMAIL(("Return Path - ")); | |
2230 MALLOC_EMAIL(item); | |
2231 LIST_COPY(item->email->return_path_address, (char*)); | |
2232 DEBUG_EMAIL(("%s\n", item->email->return_path_address)); | |
2233 break; | |
2234 case 0x3001: // PR_DISPLAY_NAME File As | |
2235 DEBUG_EMAIL(("Display Name - ")); | |
2236 LIST_COPY(item->file_as, (char*)); | |
2237 DEBUG_EMAIL(("%s\n", item->file_as)); | |
2238 break; | |
2239 case 0x3002: // PR_ADDRTYPE | |
2240 DEBUG_EMAIL(("Address Type - ")); | |
2241 MALLOC_CONTACT(item); | |
2242 LIST_COPY(item->contact->address1_transport, (char*)); | |
2243 DEBUG_EMAIL(("|%s|\n", item->contact->address1_transport)); | |
2244 break; | |
2245 case 0x3003: // PR_EMAIL_ADDRESS | |
2246 // Contact's email address | |
2247 DEBUG_EMAIL(("Contact Address - ")); | |
2248 MALLOC_CONTACT(item); | |
2249 LIST_COPY(item->contact->address1, (char*)); | |
2250 DEBUG_EMAIL(("|%s|\n", item->contact->address1)); | |
2251 break; | |
2252 case 0x3004: // PR_COMMENT Comment for item - usually folders | |
2253 DEBUG_EMAIL(("Comment - ")); | |
2254 LIST_COPY(item->comment, (char*)); | |
2255 DEBUG_EMAIL(("%s\n", item->comment)); | |
2256 break; | |
2257 case 0x3007: // PR_CREATION_TIME Date 4 - Creation Date? | |
2258 DEBUG_EMAIL(("Date 4 (Item Creation Date) - ")); | |
2259 LIST_COPY(item->create_date, (FILETIME*)); | |
2260 DEBUG_EMAIL(("%s", fileTimeToAscii(item->create_date))); | |
2261 break; | |
2262 case 0x3008: // PR_LAST_MODIFICATION_TIME Date 5 - Modify Date | |
2263 DEBUG_EMAIL(("Date 5 (Modify Date) - ")); | |
2264 LIST_COPY(item->modify_date, (FILETIME*)); | |
2265 DEBUG_EMAIL(("%s", fileTimeToAscii(item->modify_date))); | |
2266 break; | |
2267 case 0x300B: // PR_SEARCH_KEY Record Header 2 | |
2268 DEBUG_EMAIL(("Record Search 2 -- NOT HANDLED\n")); | |
2269 break; | |
2270 case 0x35DF: // PR_VALID_FOLDER_MASK | |
2271 // States which folders are valid for this message store | |
2272 // FOLDER_IPM_SUBTREE_VALID 0x1 | |
2273 // FOLDER_IPM_INBOX_VALID 0x2 | |
2274 // FOLDER_IPM_OUTBOX_VALID 0x4 | |
2275 // FOLDER_IPM_WASTEBOX_VALID 0x8 | |
2276 // FOLDER_IPM_SENTMAIL_VALID 0x10 | |
2277 // FOLDER_VIEWS_VALID 0x20 | |
2278 // FOLDER_COMMON_VIEWS_VALID 0x40 | |
2279 // FOLDER_FINDER_VALID 0x80 | |
2280 DEBUG_EMAIL(("Valid Folder Mask - ")); | |
2281 MALLOC_MESSAGESTORE(item); | |
2282 memcpy(&(item->message_store->valid_mask), list->items[x]->data, sizeof(int)); | |
2283 LE32_CPU(item->message_store->valid_mask); | |
2284 DEBUG_EMAIL(("%i\n", item->message_store->valid_mask)); | |
2285 break; | |
2286 case 0x35E0: // PR_IPM_SUBTREE_ENTRYID Top of Personal Folder Record | |
2287 DEBUG_EMAIL(("Top of Personal Folder Record - ")); | |
2288 MALLOC_MESSAGESTORE(item); | |
2289 LIST_COPY(item->message_store->top_of_personal_folder, (pst_entryid*)); | |
2290 LE32_CPU(item->message_store->top_of_personal_folder->id); | |
2291 DEBUG_EMAIL(("[id = %#x]\n", item->message_store->top_of_personal_folder->id)); | |
2292 break; | |
2293 case 0x35E3: // PR_IPM_WASTEBASKET_ENTRYID Deleted Items Folder Record | |
2294 DEBUG_EMAIL(("Deleted Items Folder record - ")); | |
2295 MALLOC_MESSAGESTORE(item); | |
2296 LIST_COPY(item->message_store->deleted_items_folder, (pst_entryid*)); | |
2297 LE32_CPU(item->message_store->deleted_items_folder->id); | |
2298 DEBUG_EMAIL(("[id = %#x]\n", item->message_store->deleted_items_folder->id)); | |
2299 break; | |
2300 case 0x35E7: // PR_FINDER_ENTRYID Search Root Record | |
2301 DEBUG_EMAIL(("Search Root record - ")); | |
2302 MALLOC_MESSAGESTORE(item); | |
2303 LIST_COPY(item->message_store->search_root_folder, (pst_entryid*)); | |
2304 LE32_CPU(item->message_store->search_root_folder->id); | |
2305 DEBUG_EMAIL(("[id = %#x]\n", item->message_store->search_root_folder->id)); | |
2306 break; | |
2307 case 0x3602: // PR_CONTENT_COUNT Number of emails stored in a folder | |
2308 DEBUG_EMAIL(("Folder Email Count - ")); | |
2309 MALLOC_FOLDER(item); | |
2310 memcpy(&(item->folder->email_count), list->items[x]->data, sizeof(item->folder->email_count)); | |
2311 LE32_CPU(item->folder->email_count); | |
2312 DEBUG_EMAIL(("%i\n", item->folder->email_count)); | |
2313 break; | |
2314 case 0x3603: // PR_CONTENT_UNREAD Number of unread emails | |
2315 DEBUG_EMAIL(("Unread Email Count - ")); | |
2316 MALLOC_FOLDER(item); | |
2317 memcpy(&(item->folder->unseen_email_count), list->items[x]->data, sizeof(item->folder->unseen_email_count)); | |
2318 LE32_CPU(item->folder->unseen_email_count); | |
2319 DEBUG_EMAIL(("%i\n", item->folder->unseen_email_count)); | |
2320 break; | |
2321 case 0x360A: // PR_SUBFOLDERS Has children | |
2322 DEBUG_EMAIL(("Has Subfolders - ")); | |
2323 MALLOC_FOLDER(item); | |
2324 if (*((int32_t*)list->items[x]->data) != 0) { | |
2325 DEBUG_EMAIL(("True\n")); | |
2326 item->folder->subfolder = 1; | |
2327 } else { | |
2328 DEBUG_EMAIL(("False\n")); | |
2329 item->folder->subfolder = 0; | |
2330 } | |
2331 break; | |
2332 case 0x3613: // PR_CONTAINER_CLASS IPF.x | |
2333 DEBUG_EMAIL(("IPF.x - ")); | |
2334 LIST_COPY(item->ascii_type, (char*)); | |
2335 if (strncmp("IPF.Note", item->ascii_type, 8) == 0) | |
2336 item->type = PST_TYPE_NOTE; | |
2337 else if (strncmp("IPF.Contact", item->ascii_type, 11) == 0) | |
2338 item->type = PST_TYPE_CONTACT; | |
2339 else if (strncmp("IPF.Journal", item->ascii_type, 11) == 0) | |
2340 item->type = PST_TYPE_JOURNAL; | |
2341 else if (strncmp("IPF.Appointment", item->ascii_type, 15) == 0) | |
2342 item->type = PST_TYPE_APPOINTMENT; | |
2343 else if (strncmp("IPF.StickyNote", item->ascii_type, 14) == 0) | |
2344 item->type = PST_TYPE_STICKYNOTE; | |
2345 else if (strncmp("IPF.Task", item->ascii_type, 8) == 0) | |
2346 item->type = PST_TYPE_TASK; | |
2347 else | |
2348 item->type = PST_TYPE_OTHER; | |
2349 | |
2350 DEBUG_EMAIL(("%s [%i]\n", item->ascii_type, item->type)); | |
2351 break; | |
2352 case 0x3617: // PR_ASSOC_CONTENT_COUNT | |
2353 // associated content are items that are attached to this folder | |
2354 // but are hidden from users | |
2355 DEBUG_EMAIL(("Associate Content count - ")); | |
2356 MALLOC_FOLDER(item); | |
2357 memcpy(&(item->folder->assoc_count), list->items[x]->data, sizeof(item->folder->assoc_count)); | |
2358 LE32_CPU(item->folder->assoc_count); | |
2359 DEBUG_EMAIL(("%i [%#x]\n", item->folder->assoc_count, item->folder->assoc_count)); | |
2360 break; | |
2361 case 0x3701: // PR_ATTACH_DATA_OBJ binary data of attachment | |
2362 DEBUG_EMAIL(("Binary Data [Size %i] - ", list->items[x]->size)); | |
2363 NULL_CHECK(attach); | |
2364 MOVE_NEXT(attach); | |
2365 if (!list->items[x]->data) { //special case | |
2366 attach->id2_val = list->items[x]->type; | |
2367 DEBUG_EMAIL(("Seen a Reference. The data hasn't been loaded yet. [%#x][%#x]\n", | |
2368 attach->id2_val, list->items[x]->type)); | |
2369 } else { | |
2370 LIST_COPY(attach->data, (char*)); | |
2371 attach->size = list->items[x]->size; | |
2372 DEBUG_EMAIL(("NOT PRINTED\n")); | |
2373 } | |
2374 break; | |
2375 case 0x3704: // PR_ATTACH_FILENAME Attachment filename (8.3) | |
2376 DEBUG_EMAIL(("Attachment Filename - ")); | |
2377 NULL_CHECK(attach); | |
2378 MOVE_NEXT(attach); | |
2379 LIST_COPY(attach->filename1, (char*)); | |
2380 DEBUG_EMAIL(("%s\n", attach->filename1)); | |
2381 break; | |
2382 case 0x3705: // PR_ATTACH_METHOD | |
2383 // 0 - No Attachment | |
2384 // 1 - Attach by Value | |
2385 // 2 - Attach by reference | |
2386 // 3 - Attach by ref resolve | |
2387 // 4 - Attach by ref only | |
2388 // 5 - Embedded Message | |
2389 // 6 - OLE | |
2390 DEBUG_EMAIL(("Attachment method - ")); | |
2391 NULL_CHECK(attach); | |
2392 MOVE_NEXT(attach); | |
2393 memcpy(&(attach->method), list->items[x]->data, sizeof(attach->method)); | |
2394 LE32_CPU(attach->method); | |
2395 t = attach->method; | |
2396 DEBUG_EMAIL(("%s [%i]\n", (t==0?"No Attachment": | |
2397 (t==1?"Attach By Value": | |
2398 (t==2?"Attach By Reference": | |
2399 (t==3?"Attach by Ref. Resolve": | |
2400 (t==4?"Attach by Ref. Only": | |
2401 (t==5?"Embedded Message":"OLE")))))),t)); | |
2402 break; | |
2403 case 0x3707: // PR_ATTACH_LONG_FILENAME Attachment filename (long?) | |
2404 DEBUG_EMAIL(("Attachment Filename long - ")); | |
2405 NULL_CHECK(attach); | |
2406 MOVE_NEXT(attach); | |
2407 LIST_COPY(attach->filename2, (char*)); | |
2408 DEBUG_EMAIL(("%s\n", attach->filename2)); | |
2409 break; | |
2410 case 0x370B: // PR_RENDERING_POSITION | |
2411 // position in characters that the attachment appears in the plain text body | |
2412 DEBUG_EMAIL(("Attachment Position - ")); | |
2413 NULL_CHECK(attach); | |
2414 MOVE_NEXT(attach); | |
2415 memcpy(&(attach->position), list->items[x]->data, sizeof(attach->position)); | |
2416 LE32_CPU(attach->position); | |
2417 DEBUG_EMAIL(("%i [%#x]\n", attach->position)); | |
2418 break; | |
2419 case 0x370E: // PR_ATTACH_MIME_TAG Mime type of encoding | |
2420 DEBUG_EMAIL(("Attachment mime encoding - ")); | |
2421 NULL_CHECK(attach); | |
2422 MOVE_NEXT(attach); | |
2423 LIST_COPY(attach->mimetype, (char*)); | |
2424 DEBUG_EMAIL(("%s\n", attach->mimetype)); | |
2425 break; | |
2426 case 0x3710: // PR_ATTACH_MIME_SEQUENCE | |
2427 // sequence number for mime parts. Includes body | |
2428 DEBUG_EMAIL(("Attachment Mime Sequence - ")); | |
2429 NULL_CHECK(attach); | |
2430 MOVE_NEXT(attach); | |
2431 memcpy(&(attach->sequence), list->items[x]->data, sizeof(attach->sequence)); | |
2432 LE32_CPU(attach->sequence); | |
2433 DEBUG_EMAIL(("%i\n", attach->sequence)); | |
2434 break; | |
2435 case 0x3A00: // PR_ACCOUNT | |
2436 DEBUG_EMAIL(("Contact's Account name - ")); | |
2437 MALLOC_CONTACT(item); | |
2438 LIST_COPY(item->contact->account_name, (char*)); | |
2439 DEBUG_EMAIL(("%s\n", item->contact->account_name)); | |
2440 break; | |
2441 case 0x3A01: // PR_ALTERNATE_RECIPIENT | |
2442 DEBUG_EMAIL(("Contact Alternate Recipient - NOT PROCESSED\n")); | |
2443 break; | |
2444 case 0x3A02: // PR_CALLBACK_TELEPHONE_NUMBER | |
2445 DEBUG_EMAIL(("Callback telephone number - ")); | |
2446 MALLOC_CONTACT(item); | |
2447 LIST_COPY(item->contact->callback_phone, (char*)); | |
2448 DEBUG_EMAIL(("%s\n", item->contact->callback_phone)); | |
2449 break; | |
2450 case 0x3A03: // PR_CONVERSION_PROHIBITED | |
2451 DEBUG_EMAIL(("Message Conversion Prohibited - ")); | |
2452 MALLOC_EMAIL(item); | |
2453 if (*(int16_t*)list->items[x]->data != 0) { | |
2454 DEBUG_EMAIL(("True\n")); | |
2455 item->email->conversion_prohib = 1; | |
2456 } else { | |
2457 DEBUG_EMAIL(("False\n")); | |
2458 item->email->conversion_prohib = 0; | |
2459 } | |
2460 break; | |
2461 case 0x3A05: // PR_GENERATION suffix | |
2462 DEBUG_EMAIL(("Contacts Suffix - ")); | |
2463 MALLOC_CONTACT(item); | |
2464 LIST_COPY(item->contact->suffix, (char*)); | |
2465 DEBUG_EMAIL(("%s\n", item->contact->suffix)); | |
2466 break; | |
2467 case 0x3A06: // PR_GIVEN_NAME Contact's first name | |
2468 DEBUG_EMAIL(("Contacts First Name - ")); | |
2469 MALLOC_CONTACT(item); | |
2470 LIST_COPY(item->contact->first_name, (char*)); | |
2471 DEBUG_EMAIL(("%s\n", item->contact->first_name)); | |
2472 break; | |
2473 case 0x3A07: // PR_GOVERNMENT_ID_NUMBER | |
2474 DEBUG_EMAIL(("Contacts Government ID Number - ")); | |
2475 MALLOC_CONTACT(item); | |
2476 LIST_COPY(item->contact->gov_id, (char*)); | |
2477 DEBUG_EMAIL(("%s\n", item->contact->gov_id)); | |
2478 break; | |
2479 case 0x3A08: // PR_BUSINESS_TELEPHONE_NUMBER | |
2480 DEBUG_EMAIL(("Business Telephone Number - ")); | |
2481 MALLOC_CONTACT(item); | |
2482 LIST_COPY(item->contact->business_phone, (char*)); | |
2483 DEBUG_EMAIL(("%s\n", item->contact->business_phone)); | |
2484 break; | |
2485 case 0x3A09: // PR_HOME_TELEPHONE_NUMBER | |
2486 DEBUG_EMAIL(("Home Telephone Number - ")); | |
2487 MALLOC_CONTACT(item); | |
2488 LIST_COPY(item->contact->home_phone, (char*)); | |
2489 DEBUG_EMAIL(("%s\n", item->contact->home_phone)); | |
2490 break; | |
2491 case 0x3A0A: // PR_INITIALS Contact's Initials | |
2492 DEBUG_EMAIL(("Contacts Initials - ")); | |
2493 MALLOC_CONTACT(item); | |
2494 LIST_COPY(item->contact->initials, (char*)); | |
2495 DEBUG_EMAIL(("%s\n", item->contact->initials)); | |
2496 break; | |
2497 case 0x3A0B: // PR_KEYWORD | |
2498 DEBUG_EMAIL(("Keyword - ")); | |
2499 MALLOC_CONTACT(item); | |
2500 LIST_COPY(item->contact->keyword, (char*)); | |
2501 DEBUG_EMAIL(("%s\n", item->contact->keyword)); | |
2502 break; | |
2503 case 0x3A0C: // PR_LANGUAGE | |
2504 DEBUG_EMAIL(("Contact's Language - ")); | |
2505 MALLOC_CONTACT(item); | |
2506 LIST_COPY(item->contact->language, (char*)); | |
2507 DEBUG_EMAIL(("%s\n", item->contact->language)); | |
2508 break; | |
2509 case 0x3A0D: // PR_LOCATION | |
2510 DEBUG_EMAIL(("Contact's Location - ")); | |
2511 MALLOC_CONTACT(item); | |
2512 LIST_COPY(item->contact->location, (char*)); | |
2513 DEBUG_EMAIL(("%s\n", item->contact->location)); | |
2514 break; | |
2515 case 0x3A0E: // PR_MAIL_PERMISSION - Can the recipient receive and send email | |
2516 DEBUG_EMAIL(("Mail Permission - ")); | |
2517 MALLOC_CONTACT(item); | |
2518 if (*(int16_t*)list->items[x]->data != 0) { | |
2519 DEBUG_EMAIL(("True\n")); | |
2520 item->contact->mail_permission = 1; | |
2521 } else { | |
2522 DEBUG_EMAIL(("False\n")); | |
2523 item->contact->mail_permission = 0; | |
2524 } | |
2525 break; | |
2526 case 0x3A0F: // PR_MHS_COMMON_NAME | |
2527 DEBUG_EMAIL(("MHS Common Name - ")); | |
2528 MALLOC_EMAIL(item); | |
2529 LIST_COPY(item->email->common_name, (char*)); | |
2530 DEBUG_EMAIL(("%s\n", item->email->common_name)); | |
2531 break; | |
2532 case 0x3A10: // PR_ORGANIZATIONAL_ID_NUMBER | |
2533 DEBUG_EMAIL(("Organizational ID # - ")); | |
2534 MALLOC_CONTACT(item); | |
2535 LIST_COPY(item->contact->org_id, (char*)); | |
2536 DEBUG_EMAIL(("%s\n", item->contact->org_id)); | |
2537 break; | |
2538 case 0x3A11: // PR_SURNAME Contact's Surname | |
2539 DEBUG_EMAIL(("Contacts Surname - ")); | |
2540 MALLOC_CONTACT(item); | |
2541 LIST_COPY(item->contact->surname, (char*)); | |
2542 DEBUG_EMAIL(("%s\n", item->contact->surname)); | |
2543 break; | |
2544 case 0x3A12: // PR_ORIGINAL_ENTRY_ID | |
2545 DEBUG_EMAIL(("Original Entry ID - NOT PROCESSED\n")); | |
2546 break; | |
2547 case 0x3A13: // PR_ORIGINAL_DISPLAY_NAME | |
2548 DEBUG_EMAIL(("Original Display Name - NOT PROCESSED\n")); | |
2549 break; | |
2550 case 0x3A14: // PR_ORIGINAL_SEARCH_KEY | |
2551 DEBUG_EMAIL(("Original Search Key - NOT PROCESSED\n")); | |
2552 break; | |
2553 case 0x3A15: // PR_POSTAL_ADDRESS | |
2554 DEBUG_EMAIL(("Default Postal Address - ")); | |
2555 MALLOC_CONTACT(item); | |
2556 LIST_COPY(item->contact->def_postal_address, (char*)); | |
2557 DEBUG_EMAIL(("%s\n", item->contact->def_postal_address)); | |
2558 break; | |
2559 case 0x3A16: // PR_COMPANY_NAME | |
2560 DEBUG_EMAIL(("Company Name - ")); | |
2561 MALLOC_CONTACT(item); | |
2562 LIST_COPY(item->contact->company_name, (char*)); | |
2563 DEBUG_EMAIL(("%s\n", item->contact->company_name)); | |
2564 break; | |
2565 case 0x3A17: // PR_TITLE - Job Title | |
2566 DEBUG_EMAIL(("Job Title - ")); | |
2567 MALLOC_CONTACT(item); | |
2568 LIST_COPY(item->contact->job_title, (char*)); | |
2569 DEBUG_EMAIL(("%s\n", item->contact->job_title)); | |
2570 break; | |
2571 case 0x3A18: // PR_DEPARTMENT_NAME | |
2572 DEBUG_EMAIL(("Department Name - ")); | |
2573 MALLOC_CONTACT(item); | |
2574 LIST_COPY(item->contact->department, (char*)); | |
2575 DEBUG_EMAIL(("%s\n", item->contact->department)); | |
2576 break; | |
2577 case 0x3A19: // PR_OFFICE_LOCATION | |
2578 DEBUG_EMAIL(("Office Location - ")); | |
2579 MALLOC_CONTACT(item); | |
2580 LIST_COPY(item->contact->office_loc, (char*)); | |
2581 DEBUG_EMAIL(("%s\n", item->contact->office_loc)); | |
2582 break; | |
2583 case 0x3A1A: // PR_PRIMARY_TELEPHONE_NUMBER | |
2584 DEBUG_EMAIL(("Primary Telephone - ")); | |
2585 MALLOC_CONTACT(item); | |
2586 LIST_COPY(item->contact->primary_phone, (char*)); | |
2587 DEBUG_EMAIL(("%s\n", item->contact->primary_phone)); | |
2588 break; | |
2589 case 0x3A1B: // PR_BUSINESS2_TELEPHONE_NUMBER | |
2590 DEBUG_EMAIL(("Business Phone Number 2 - ")); | |
2591 MALLOC_CONTACT(item); | |
2592 LIST_COPY(item->contact->business_phone2, (char*)); | |
2593 DEBUG_EMAIL(("%s\n", item->contact->business_phone2)); | |
2594 break; | |
2595 case 0x3A1C: // PR_MOBILE_TELEPHONE_NUMBER | |
2596 DEBUG_EMAIL(("Mobile Phone Number - ")); | |
2597 MALLOC_CONTACT(item); | |
2598 LIST_COPY(item->contact->mobile_phone, (char*)); | |
2599 DEBUG_EMAIL(("%s\n", item->contact->mobile_phone)); | |
2600 break; | |
2601 case 0x3A1D: // PR_RADIO_TELEPHONE_NUMBER | |
2602 DEBUG_EMAIL(("Radio Phone Number - ")); | |
2603 MALLOC_CONTACT(item); | |
2604 LIST_COPY(item->contact->radio_phone, (char*)); | |
2605 DEBUG_EMAIL(("%s\n", item->contact->radio_phone)); | |
2606 break; | |
2607 case 0x3A1E: // PR_CAR_TELEPHONE_NUMBER | |
2608 DEBUG_EMAIL(("Car Phone Number - ")); | |
2609 MALLOC_CONTACT(item); | |
2610 LIST_COPY(item->contact->car_phone, (char*)); | |
2611 DEBUG_EMAIL(("%s\n", item->contact->car_phone)); | |
2612 break; | |
2613 case 0x3A1F: // PR_OTHER_TELEPHONE_NUMBER | |
2614 DEBUG_EMAIL(("Other Phone Number - ")); | |
2615 MALLOC_CONTACT(item); | |
2616 LIST_COPY(item->contact->other_phone, (char*)); | |
2617 DEBUG_EMAIL(("%s\n", item->contact->other_phone)); | |
2618 break; | |
2619 case 0x3A20: // PR_TRANSMITTABLE_DISPLAY_NAME | |
2620 DEBUG_EMAIL(("Transmittable Display Name - ")); | |
2621 MALLOC_CONTACT(item); | |
2622 LIST_COPY(item->contact->transmittable_display_name, (char*)); | |
2623 DEBUG_EMAIL(("%s\n", item->contact->transmittable_display_name)); | |
2624 break; | |
2625 case 0x3A21: // PR_PAGER_TELEPHONE_NUMBER | |
2626 DEBUG_EMAIL(("Pager Phone Number - ")); | |
2627 MALLOC_CONTACT(item); | |
2628 LIST_COPY(item->contact->pager_phone, (char*)); | |
2629 DEBUG_EMAIL(("%s\n", item->contact->pager_phone)); | |
2630 break; | |
2631 case 0x3A22: // PR_USER_CERTIFICATE | |
2632 DEBUG_EMAIL(("User Certificate - NOT PROCESSED")); | |
2633 break; | |
2634 case 0x3A23: // PR_PRIMARY_FAX_NUMBER | |
2635 DEBUG_EMAIL(("Primary Fax Number - ")); | |
2636 MALLOC_CONTACT(item); | |
2637 LIST_COPY(item->contact->primary_fax, (char*)); | |
2638 DEBUG_EMAIL(("%s\n", item->contact->primary_fax)); | |
2639 break; | |
2640 case 0x3A24: // PR_BUSINESS_FAX_NUMBER | |
2641 DEBUG_EMAIL(("Business Fax Number - ")); | |
2642 MALLOC_CONTACT(item); | |
2643 LIST_COPY(item->contact->business_fax, (char*)); | |
2644 DEBUG_EMAIL(("%s\n", item->contact->business_fax)); | |
2645 break; | |
2646 case 0x3A25: // PR_HOME_FAX_NUMBER | |
2647 DEBUG_EMAIL(("Home Fax Number - ")); | |
2648 MALLOC_CONTACT(item); | |
2649 LIST_COPY(item->contact->home_fax, (char*)); | |
2650 DEBUG_EMAIL(("%s\n", item->contact->home_fax)); | |
2651 break; | |
2652 case 0x3A26: // PR_BUSINESS_ADDRESS_COUNTRY | |
2653 DEBUG_EMAIL(("Business Address Country - ")); | |
2654 MALLOC_CONTACT(item); | |
2655 LIST_COPY(item->contact->business_country, (char*)); | |
2656 DEBUG_EMAIL(("%s\n", item->contact->business_country)); | |
2657 break; | |
2658 case 0x3A27: // PR_BUSINESS_ADDRESS_CITY | |
2659 DEBUG_EMAIL(("Business Address City - ")); | |
2660 MALLOC_CONTACT(item); | |
2661 LIST_COPY(item->contact->business_city, (char*)); | |
2662 DEBUG_EMAIL(("%s\n", item->contact->business_city)); | |
2663 break; | |
2664 case 0x3A28: // PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE | |
2665 DEBUG_EMAIL(("Business Address State - ")); | |
2666 MALLOC_CONTACT(item); | |
2667 LIST_COPY(item->contact->business_state, (char*)); | |
2668 DEBUG_EMAIL(("%s\n", item->contact->business_state)); | |
2669 break; | |
2670 case 0x3A29: // PR_BUSINESS_ADDRESS_STREET | |
2671 DEBUG_EMAIL(("Business Address Street - ")); | |
2672 MALLOC_CONTACT(item); | |
2673 LIST_COPY(item->contact->business_street, (char*)); | |
2674 DEBUG_EMAIL(("%s\n", item->contact->business_street)); | |
2675 break; | |
2676 case 0x3A2A: // PR_BUSINESS_POSTAL_CODE | |
2677 DEBUG_EMAIL(("Business Postal Code - ")); | |
2678 MALLOC_CONTACT(item); | |
2679 LIST_COPY(item->contact->business_postal_code, (char*)); | |
2680 DEBUG_EMAIL(("%s\n", item->contact->business_postal_code)); | |
2681 break; | |
2682 case 0x3A2B: // PR_BUSINESS_PO_BOX | |
2683 DEBUG_EMAIL(("Business PO Box - ")); | |
2684 MALLOC_CONTACT(item); | |
2685 LIST_COPY(item->contact->business_po_box, (char*)); | |
2686 DEBUG_EMAIL(("%s\n", item->contact->business_po_box)); | |
2687 break; | |
2688 case 0x3A2C: // PR_TELEX_NUMBER | |
2689 DEBUG_EMAIL(("Telex Number - ")); | |
2690 MALLOC_CONTACT(item); | |
2691 LIST_COPY(item->contact->telex, (char*)); | |
2692 DEBUG_EMAIL(("%s\n", item->contact->telex)); | |
2693 break; | |
2694 case 0x3A2D: // PR_ISDN_NUMBER | |
2695 DEBUG_EMAIL(("ISDN Number - ")); | |
2696 MALLOC_CONTACT(item); | |
2697 LIST_COPY(item->contact->isdn_phone, (char*)); | |
2698 DEBUG_EMAIL(("%s\n", item->contact->isdn_phone)); | |
2699 break; | |
2700 case 0x3A2E: // PR_ASSISTANT_TELEPHONE_NUMBER | |
2701 DEBUG_EMAIL(("Assistant Phone Number - ")); | |
2702 MALLOC_CONTACT(item); | |
2703 LIST_COPY(item->contact->assistant_phone, (char*)); | |
2704 DEBUG_EMAIL(("%s\n", item->contact->assistant_phone)); | |
2705 break; | |
2706 case 0x3A2F: // PR_HOME2_TELEPHONE_NUMBER | |
2707 DEBUG_EMAIL(("Home Phone 2 - ")); | |
2708 MALLOC_CONTACT(item); | |
2709 LIST_COPY(item->contact->home_phone2, (char*)); | |
2710 DEBUG_EMAIL(("%s\n", item->contact->home_phone2)); | |
2711 break; | |
2712 case 0x3A30: // PR_ASSISTANT | |
2713 DEBUG_EMAIL(("Assistant's Name - ")); | |
2714 MALLOC_CONTACT(item); | |
2715 LIST_COPY(item->contact->assistant_name, (char*)); | |
2716 DEBUG_EMAIL(("%s\n", item->contact->assistant_name)); | |
2717 break; | |
2718 case 0x3A40: // PR_SEND_RICH_INFO | |
2719 DEBUG_EMAIL(("Can receive Rich Text - ")); | |
2720 MALLOC_CONTACT(item); | |
2721 if(*(int16_t*)list->items[x]->data != 0) { | |
2722 DEBUG_EMAIL(("True\n")); | |
2723 item->contact->rich_text = 1; | |
2724 } else { | |
2725 DEBUG_EMAIL(("False\n")); | |
2726 item->contact->rich_text = 0; | |
2727 } | |
2728 break; | |
2729 case 0x3A41: // PR_WEDDING_ANNIVERSARY | |
2730 DEBUG_EMAIL(("Wedding Anniversary - ")); | |
2731 MALLOC_CONTACT(item); | |
2732 LIST_COPY(item->contact->wedding_anniversary, (FILETIME*)); | |
2733 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->contact->wedding_anniversary))); | |
2734 break; | |
2735 case 0x3A42: // PR_BIRTHDAY | |
2736 DEBUG_EMAIL(("Birthday - ")); | |
2737 MALLOC_CONTACT(item); | |
2738 LIST_COPY(item->contact->birthday, (FILETIME*)); | |
2739 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->contact->birthday))); | |
2740 break; | |
2741 case 0x3A43: // PR_HOBBIES | |
2742 DEBUG_EMAIL(("Hobbies - ")); | |
2743 MALLOC_CONTACT(item); | |
2744 LIST_COPY(item->contact->hobbies, (char*)); | |
2745 DEBUG_EMAIL(("%s\n", item->contact->hobbies)); | |
2746 break; | |
2747 case 0x3A44: // PR_MIDDLE_NAME | |
2748 DEBUG_EMAIL(("Middle Name - ")); | |
2749 MALLOC_CONTACT(item); | |
2750 LIST_COPY(item->contact->middle_name, (char*)); | |
2751 DEBUG_EMAIL(("%s\n", item->contact->middle_name)); | |
2752 break; | |
2753 case 0x3A45: // PR_DISPLAY_NAME_PREFIX | |
2754 DEBUG_EMAIL(("Display Name Prefix (Title) - ")); | |
2755 MALLOC_CONTACT(item); | |
2756 LIST_COPY(item->contact->display_name_prefix, (char*)); | |
2757 DEBUG_EMAIL(("%s\n", item->contact->display_name_prefix)); | |
2758 break; | |
2759 case 0x3A46: // PR_PROFESSION | |
2760 DEBUG_EMAIL(("Profession - ")); | |
2761 MALLOC_CONTACT(item); | |
2762 LIST_COPY(item->contact->profession, (char*)); | |
2763 DEBUG_EMAIL(("%s\n", item->contact->profession)); | |
2764 break; | |
2765 case 0x3A47: // PR_PREFERRED_BY_NAME | |
2766 DEBUG_EMAIL(("Preferred By Name - ")); | |
2767 MALLOC_CONTACT(item); | |
2768 LIST_COPY(item->contact->pref_name, (char*)); | |
2769 DEBUG_EMAIL(("%s\n", item->contact->pref_name)); | |
2770 break; | |
2771 case 0x3A48: // PR_SPOUSE_NAME | |
2772 DEBUG_EMAIL(("Spouse's Name - ")); | |
2773 MALLOC_CONTACT(item); | |
2774 LIST_COPY(item->contact->spouse_name, (char*)); | |
2775 DEBUG_EMAIL(("%s\n", item->contact->spouse_name)); | |
2776 break; | |
2777 case 0x3A49: // PR_COMPUTER_NETWORK_NAME | |
2778 DEBUG_EMAIL(("Computer Network Name - ")); | |
2779 MALLOC_CONTACT(item); | |
2780 LIST_COPY(item->contact->computer_name, (char*)); | |
2781 DEBUG_EMAIL(("%s\n", item->contact->computer_name)); | |
2782 break; | |
2783 case 0x3A4A: // PR_CUSTOMER_ID | |
2784 DEBUG_EMAIL(("Customer ID - ")); | |
2785 MALLOC_CONTACT(item); | |
2786 LIST_COPY(item->contact->customer_id, (char*)); | |
2787 DEBUG_EMAIL(("%s\n", item->contact->customer_id)); | |
2788 break; | |
2789 case 0x3A4B: // PR_TTYTDD_PHONE_NUMBER | |
2790 DEBUG_EMAIL(("TTY/TDD Phone - ")); | |
2791 MALLOC_CONTACT(item); | |
2792 LIST_COPY(item->contact->ttytdd_phone, (char*)); | |
2793 DEBUG_EMAIL(("%s\n", item->contact->ttytdd_phone)); | |
2794 break; | |
2795 case 0x3A4C: // PR_FTP_SITE | |
2796 DEBUG_EMAIL(("Ftp Site - ")); | |
2797 MALLOC_CONTACT(item); | |
2798 LIST_COPY(item->contact->ftp_site, (char*)); | |
2799 DEBUG_EMAIL(("%s\n", item->contact->ftp_site)); | |
2800 break; | |
2801 case 0x3A4D: // PR_GENDER | |
2802 DEBUG_EMAIL(("Gender - ")); | |
2803 MALLOC_CONTACT(item); | |
2804 memcpy(&item->contact->gender, list->items[x]->data, sizeof(int16_t)); | |
2805 LE16_CPU(item->contact->gender); | |
2806 switch(item->contact->gender) { | |
2807 case 0: | |
2808 DEBUG_EMAIL(("Unspecified\n")); | |
2809 break; | |
2810 case 1: | |
2811 DEBUG_EMAIL(("Female\n")); | |
2812 break; | |
2813 case 2: | |
2814 DEBUG_EMAIL(("Male\n")); | |
2815 break; | |
2816 default: | |
2817 DEBUG_EMAIL(("Error processing\n")); | |
2818 } | |
2819 break; | |
2820 case 0x3A4E: // PR_MANAGER_NAME | |
2821 DEBUG_EMAIL(("Manager's Name - ")); | |
2822 MALLOC_CONTACT(item); | |
2823 LIST_COPY(item->contact->manager_name, (char*)); | |
2824 DEBUG_EMAIL(("%s\n", item->contact->manager_name)); | |
2825 break; | |
2826 case 0x3A4F: // PR_NICKNAME | |
2827 DEBUG_EMAIL(("Nickname - ")); | |
2828 MALLOC_CONTACT(item); | |
2829 LIST_COPY(item->contact->nickname, (char*)); | |
2830 DEBUG_EMAIL(("%s\n", item->contact->nickname)); | |
2831 break; | |
2832 case 0x3A50: // PR_PERSONAL_HOME_PAGE | |
2833 DEBUG_EMAIL(("Personal Home Page - ")); | |
2834 MALLOC_CONTACT(item); | |
2835 LIST_COPY(item->contact->personal_homepage, (char*)); | |
2836 DEBUG_EMAIL(("%s\n", item->contact->personal_homepage)); | |
2837 break; | |
2838 case 0x3A51: // PR_BUSINESS_HOME_PAGE | |
2839 DEBUG_EMAIL(("Business Home Page - ")); | |
2840 MALLOC_CONTACT(item); | |
2841 LIST_COPY(item->contact->business_homepage, (char*)); | |
2842 DEBUG_EMAIL(("%s\n", item->contact->business_homepage)); | |
2843 break; | |
2844 case 0x3A57: // PR_COMPANY_MAIN_PHONE_NUMBER | |
2845 DEBUG_EMAIL(("Company Main Phone - ")); | |
2846 MALLOC_CONTACT(item); | |
2847 LIST_COPY(item->contact->company_main_phone, (char*)); | |
2848 DEBUG_EMAIL(("%s\n", item->contact->company_main_phone)); | |
2849 break; | |
2850 case 0x3A58: // PR_CHILDRENS_NAMES | |
2851 DEBUG_EMAIL(("Children's Names - NOT PROCESSED\n")); | |
2852 break; | |
2853 case 0x3A59: // PR_HOME_ADDRESS_CITY | |
2854 DEBUG_EMAIL(("Home Address City - ")); | |
2855 MALLOC_CONTACT(item); | |
2856 LIST_COPY(item->contact->home_city, (char*)); | |
2857 DEBUG_EMAIL(("%s\n", item->contact->home_city)); | |
2858 break; | |
2859 case 0x3A5A: // PR_HOME_ADDRESS_COUNTRY | |
2860 DEBUG_EMAIL(("Home Address Country - ")); | |
2861 MALLOC_CONTACT(item); | |
2862 LIST_COPY(item->contact->home_country, (char*)); | |
2863 DEBUG_EMAIL(("%s\n", item->contact->home_country)); | |
2864 break; | |
2865 case 0x3A5B: // PR_HOME_ADDRESS_POSTAL_CODE | |
2866 DEBUG_EMAIL(("Home Address Postal Code - ")); | |
2867 MALLOC_CONTACT(item); | |
2868 LIST_COPY(item->contact->home_postal_code, (char*)); | |
2869 DEBUG_EMAIL(("%s\n", item->contact->home_postal_code)); | |
2870 break; | |
2871 case 0x3A5C: // PR_HOME_ADDRESS_STATE_OR_PROVINCE | |
2872 DEBUG_EMAIL(("Home Address State or Province - ")); | |
2873 MALLOC_CONTACT(item); | |
2874 LIST_COPY(item->contact->home_state, (char*)); | |
2875 DEBUG_EMAIL(("%s\n", item->contact->home_state)); | |
2876 break; | |
2877 case 0x3A5D: // PR_HOME_ADDRESS_STREET | |
2878 DEBUG_EMAIL(("Home Address Street - ")); | |
2879 MALLOC_CONTACT(item); | |
2880 LIST_COPY(item->contact->home_street, (char*)); | |
2881 DEBUG_EMAIL(("%s\n", item->contact->home_street)); | |
2882 break; | |
2883 case 0x3A5E: // PR_HOME_ADDRESS_POST_OFFICE_BOX | |
2884 DEBUG_EMAIL(("Home Address Post Office Box - ")); | |
2885 MALLOC_CONTACT(item); | |
2886 LIST_COPY(item->contact->home_po_box, (char*)); | |
2887 DEBUG_EMAIL(("%s\n", item->contact->home_po_box)); | |
2888 break; | |
2889 case 0x3A5F: // PR_OTHER_ADDRESS_CITY | |
2890 DEBUG_EMAIL(("Other Address City - ")); | |
2891 MALLOC_CONTACT(item); | |
2892 LIST_COPY(item->contact->other_city, (char*)); | |
2893 DEBUG_EMAIL(("%s\n", item->contact->other_city)); | |
2894 break; | |
2895 case 0x3A60: // PR_OTHER_ADDRESS_COUNTRY | |
2896 DEBUG_EMAIL(("Other Address Country - ")); | |
2897 MALLOC_CONTACT(item); | |
2898 LIST_COPY(item->contact->other_country, (char*)); | |
2899 DEBUG_EMAIL(("%s\n", item->contact->other_country)); | |
2900 break; | |
2901 case 0x3A61: // PR_OTHER_ADDRESS_POSTAL_CODE | |
2902 DEBUG_EMAIL(("Other Address Postal Code - ")); | |
2903 MALLOC_CONTACT(item); | |
2904 LIST_COPY(item->contact->other_postal_code, (char*)); | |
2905 DEBUG_EMAIL(("%s\n", item->contact->other_postal_code)); | |
2906 break; | |
2907 case 0x3A62: // PR_OTHER_ADDRESS_STATE_OR_PROVINCE | |
2908 DEBUG_EMAIL(("Other Address State - ")); | |
2909 MALLOC_CONTACT(item); | |
2910 LIST_COPY(item->contact->other_state, (char*)); | |
2911 DEBUG_EMAIL(("%s\n", item->contact->other_state)); | |
2912 break; | |
2913 case 0x3A63: // PR_OTHER_ADDRESS_STREET | |
2914 DEBUG_EMAIL(("Other Address Street - ")); | |
2915 MALLOC_CONTACT(item); | |
2916 LIST_COPY(item->contact->other_street, (char*)); | |
2917 DEBUG_EMAIL(("%s\n", item->contact->other_street)); | |
2918 break; | |
2919 case 0x3A64: // PR_OTHER_ADDRESS_POST_OFFICE_BOX | |
2920 DEBUG_EMAIL(("Other Address Post Office box - ")); | |
2921 MALLOC_CONTACT(item); | |
2922 LIST_COPY(item->contact->other_po_box, (char*)); | |
2923 DEBUG_EMAIL(("%s\n", item->contact->other_po_box)); | |
2924 break; | |
2925 case 0x65E3: // Entry ID? | |
2926 DEBUG_EMAIL(("Entry ID - ")); | |
2927 item->record_key = (char*) xmalloc(16+1); | |
2928 memcpy(item->record_key, &(list->items[x]->data[1]), 16); //skip first byte | |
2929 item->record_key[16]='\0'; | |
2930 item->record_key_size=16; | |
2931 DEBUG_EMAIL_HEXPRINT((char*)item->record_key, 16); | |
2932 break; | |
2933 case 0x67F2: // ID2 value of the attachments proper record | |
2934 DEBUG_EMAIL(("Attachment ID2 value - ")); | |
2935 if (attach){ | |
2936 MOVE_NEXT(attach); | |
2937 memcpy(&(attach->id2_val), list->items[x]->data, sizeof(attach->id2_val)); | |
2938 LE32_CPU(attach->id2_val); | |
2939 DEBUG_EMAIL(("%#x\n", attach->id2_val)); | |
2940 } else { | |
2941 DEBUG_EMAIL(("NOT AN ATTACHMENT: %#x\n", list->items[x]->id)); | |
2942 } | |
2943 break; | |
2944 case 0x67FF: // Extra Property Identifier (Password CheckSum) | |
2945 DEBUG_EMAIL(("Password checksum [0x67FF] - ")); | |
2946 MALLOC_MESSAGESTORE(item); | |
2947 memcpy(&(item->message_store->pwd_chksum), list->items[x]->data, | |
2948 sizeof(item->message_store->pwd_chksum)); | |
2949 DEBUG_EMAIL(("%#x\n", item->message_store->pwd_chksum)); | |
2950 break; | |
2951 case 0x6F02: // Secure HTML Body | |
2952 DEBUG_EMAIL(("Secure HTML Body - ")); | |
2953 MALLOC_EMAIL(item); | |
2954 LIST_COPY(item->email->encrypted_htmlbody, (char*)); | |
2955 item->email->encrypted_htmlbody_size = list->items[x]->size; | |
2956 DEBUG_EMAIL(("Not Printed\n")); | |
2957 break; | |
2958 case 0x6F04: // Secure Text Body | |
2959 DEBUG_EMAIL(("Secure Text Body - ")); | |
2960 MALLOC_EMAIL(item); | |
2961 LIST_COPY(item->email->encrypted_body, (char*)); | |
2962 item->email->encrypted_body_size = list->items[x]->size; | |
2963 DEBUG_EMAIL(("Not Printed\n")); | |
2964 break; | |
2965 case 0x7C07: // top of folders ENTRYID | |
2966 DEBUG_EMAIL(("Top of folders RecID [0x7c07] - ")); | |
2967 MALLOC_MESSAGESTORE(item); | |
2968 item->message_store->top_of_folder = (pst_entryid*) xmalloc(sizeof(pst_entryid)); | |
2969 memcpy(item->message_store->top_of_folder, list->items[x]->data, sizeof(pst_entryid)); | |
2970 LE32_CPU(item->message_store->top_of_folder->u1); | |
2971 LE32_CPU(item->message_store->top_of_folder->id); | |
2972 DEBUG_EMAIL_HEXPRINT((char*)item->message_store->top_of_folder->entryid, 16); | |
2973 break; | |
2974 case 0x8005: // Contact's Fullname | |
2975 DEBUG_EMAIL(("Contact Fullname - ")); | |
2976 MALLOC_CONTACT(item); | |
2977 LIST_COPY(item->contact->fullname, (char*)); | |
2978 DEBUG_EMAIL(("%s\n", item->contact->fullname)); | |
2979 break; | |
2980 case 0x801A: // Full Home Address | |
2981 DEBUG_EMAIL(("Home Address - ")); | |
2982 MALLOC_CONTACT(item); | |
2983 LIST_COPY(item->contact->home_address, (char*)); | |
2984 DEBUG_EMAIL(("%s\n", item->contact->home_address)); | |
2985 break; | |
2986 case 0x801B: // Full Business Address | |
2987 DEBUG_EMAIL(("Business Address - ")); | |
2988 MALLOC_CONTACT(item); | |
2989 LIST_COPY(item->contact->business_address, (char*)); | |
2990 DEBUG_EMAIL(("%s\n", item->contact->business_address)); | |
2991 break; | |
2992 case 0x801C: // Full Other Address | |
2993 DEBUG_EMAIL(("Other Address - ")); | |
2994 MALLOC_CONTACT(item); | |
2995 LIST_COPY(item->contact->other_address, (char*)); | |
2996 DEBUG_EMAIL(("%s\n", item->contact->other_address)); | |
2997 break; | |
2998 case 0x8082: // Email Address 1 Transport | |
2999 DEBUG_EMAIL(("Email Address 1 Transport - ")); | |
3000 MALLOC_CONTACT(item); | |
3001 LIST_COPY(item->contact->address1_transport, (char*)); | |
3002 DEBUG_EMAIL(("|%s|\n", item->contact->address1_transport)); | |
3003 break; | |
3004 case 0x8083: // Email Address 1 Address | |
3005 DEBUG_EMAIL(("Email Address 1 Address - ")); | |
3006 MALLOC_CONTACT(item); | |
3007 LIST_COPY(item->contact->address1, (char*)); | |
3008 DEBUG_EMAIL(("|%s|\n", item->contact->address1)); | |
3009 break; | |
3010 case 0x8084: // Email Address 1 Description | |
3011 DEBUG_EMAIL(("Email Address 1 Description - ")); | |
3012 MALLOC_CONTACT(item); | |
3013 LIST_COPY(item->contact->address1_desc, (char*)); | |
3014 DEBUG_EMAIL(("|%s|\n", item->contact->address1_desc)); | |
3015 break; | |
3016 case 0x8085: // Email Address 1 Record | |
3017 DEBUG_EMAIL(("Email Address 1 Record - ")); | |
3018 MALLOC_CONTACT(item); | |
3019 LIST_COPY(item->contact->address1a, (char*)); | |
3020 DEBUG_EMAIL(("|%s|\n", item->contact->address1a)); | |
3021 break; | |
3022 case 0x8092: // Email Address 2 Transport | |
3023 DEBUG_EMAIL(("Email Address 2 Transport - ")); | |
3024 MALLOC_CONTACT(item); | |
3025 LIST_COPY(item->contact->address2_transport, (char*)); | |
3026 DEBUG_EMAIL(("|%s|\n", item->contact->address2_transport)); | |
3027 break; | |
3028 case 0x8093: // Email Address 2 Address | |
3029 DEBUG_EMAIL(("Email Address 2 Address - ")); | |
3030 MALLOC_CONTACT(item); | |
3031 LIST_COPY(item->contact->address2, (char*)); | |
3032 DEBUG_EMAIL(("|%s|\n", item->contact->address2)); | |
3033 break; | |
3034 case 0x8094: // Email Address 2 Description | |
3035 DEBUG_EMAIL (("Email Address 2 Description - ")); | |
3036 MALLOC_CONTACT(item); | |
3037 LIST_COPY(item->contact->address2_desc, (char*)); | |
3038 DEBUG_EMAIL(("|%s|\n", item->contact->address2_desc)); | |
3039 break; | |
3040 case 0x8095: // Email Address 2 Record | |
3041 DEBUG_EMAIL(("Email Address 2 Record - ")); | |
3042 MALLOC_CONTACT(item); | |
3043 LIST_COPY(item->contact->address2a, (char*)); | |
3044 DEBUG_EMAIL(("|%s|\n", item->contact->address2a)); | |
3045 break; | |
3046 case 0x80A2: // Email Address 3 Transport | |
3047 DEBUG_EMAIL (("Email Address 3 Transport - ")); | |
3048 MALLOC_CONTACT(item); | |
3049 LIST_COPY(item->contact->address3_transport, (char*)); | |
3050 DEBUG_EMAIL(("|%s|\n", item->contact->address3_transport)); | |
3051 break; | |
3052 case 0x80A3: // Email Address 3 Address | |
3053 DEBUG_EMAIL(("Email Address 3 Address - ")); | |
3054 MALLOC_CONTACT(item); | |
3055 LIST_COPY(item->contact->address3, (char*)); | |
3056 DEBUG_EMAIL(("|%s|\n", item->contact->address3)); | |
3057 break; | |
3058 case 0x80A4: // Email Address 3 Description | |
3059 DEBUG_EMAIL(("Email Address 3 Description - ")); | |
3060 MALLOC_CONTACT(item); | |
3061 LIST_COPY(item->contact->address3_desc, (char*)); | |
3062 DEBUG_EMAIL(("|%s|\n", item->contact->address3_desc)); | |
3063 break; | |
3064 case 0x80A5: // Email Address 3 Record | |
3065 DEBUG_EMAIL(("Email Address 3 Record - ")); | |
3066 MALLOC_CONTACT(item); | |
3067 LIST_COPY(item->contact->address3a, (char*)); | |
3068 DEBUG_EMAIL(("|%s|\n", item->contact->address3a)); | |
3069 break; | |
3070 case 0x80D8: // Internet Free/Busy | |
3071 DEBUG_EMAIL(("Internet Free/Busy - ")); | |
3072 MALLOC_CONTACT(item); | |
3073 LIST_COPY(item->contact->free_busy_address, (char*)); | |
3074 DEBUG_EMAIL(("%s\n", item->contact->free_busy_address)); | |
3075 break; | |
3076 case 0x8205: // Show on Free/Busy as | |
3077 // 0: Free | |
3078 // 1: Tentative | |
3079 // 2: Busy | |
3080 // 3: Out Of Office | |
3081 DEBUG_EMAIL(("Appointment shows as - ")); | |
3082 MALLOC_APPOINTMENT(item); | |
3083 memcpy(&(item->appointment->showas), list->items[x]->data, sizeof(item->appointment->showas)); | |
3084 LE32_CPU(item->appointment->showas); | |
3085 switch (item->appointment->showas) { | |
3086 case PST_FREEBUSY_FREE: | |
3087 DEBUG_EMAIL(("Free\n")); break; | |
3088 case PST_FREEBUSY_TENTATIVE: | |
3089 DEBUG_EMAIL(("Tentative\n")); break; | |
3090 case PST_FREEBUSY_BUSY: | |
3091 DEBUG_EMAIL(("Busy\n")); break; | |
3092 case PST_FREEBUSY_OUT_OF_OFFICE: | |
3093 DEBUG_EMAIL(("Out Of Office\n")); break; | |
3094 default: | |
3095 DEBUG_EMAIL(("Unknown Value: %d\n", item->appointment->showas)); break; | |
3096 } | |
3097 break; | |
3098 case 0x8208: // Location of an appointment | |
3099 DEBUG_EMAIL(("Appointment Location - ")); | |
3100 MALLOC_APPOINTMENT(item); | |
3101 LIST_COPY(item->appointment->location, (char*)); | |
3102 DEBUG_EMAIL(("%s\n", item->appointment->location)); | |
3103 break; | |
3104 case 0x8214: // Label for an appointment | |
3105 DEBUG_EMAIL(("Label for appointment - ")); | |
3106 MALLOC_APPOINTMENT(item); | |
3107 memcpy(&(item->appointment->label), list->items[x]->data, sizeof(item->appointment->label)); | |
3108 LE32_CPU(item->appointment->label); | |
3109 switch (item->appointment->label) { | |
3110 case PST_APP_LABEL_NONE: | |
3111 DEBUG_EMAIL(("None\n")); break; | |
3112 case PST_APP_LABEL_IMPORTANT: | |
3113 DEBUG_EMAIL(("Important\n")); break; | |
3114 case PST_APP_LABEL_BUSINESS: | |
3115 DEBUG_EMAIL(("Business\n")); break; | |
3116 case PST_APP_LABEL_PERSONAL: | |
3117 DEBUG_EMAIL(("Personal\n")); break; | |
3118 case PST_APP_LABEL_VACATION: | |
3119 DEBUG_EMAIL(("Vacation\n")); break; | |
3120 case PST_APP_LABEL_MUST_ATTEND: | |
3121 DEBUG_EMAIL(("Must Attend\n")); break; | |
3122 case PST_APP_LABEL_TRAVEL_REQ: | |
3123 DEBUG_EMAIL(("Travel Required\n")); break; | |
3124 case PST_APP_LABEL_NEEDS_PREP: | |
3125 DEBUG_EMAIL(("Needs Preparation\n")); break; | |
3126 case PST_APP_LABEL_BIRTHDAY: | |
3127 DEBUG_EMAIL(("Birthday\n")); break; | |
3128 case PST_APP_LABEL_ANNIVERSARY: | |
3129 DEBUG_EMAIL(("Anniversary\n")); break; | |
3130 case PST_APP_LABEL_PHONE_CALL: | |
3131 DEBUG_EMAIL(("Phone Call\n")); break; | |
3132 } | |
3133 break; | |
3134 case 0x8215: // All day appointment flag | |
3135 DEBUG_EMAIL(("All day flag - ")); | |
3136 MALLOC_APPOINTMENT(item); | |
3137 if (*(int16_t*)list->items[x]->data != 0) { | |
3138 DEBUG_EMAIL(("True\n")); | |
3139 item->appointment->all_day = 1; | |
3140 } else { | |
3141 DEBUG_EMAIL(("False\n")); | |
3142 item->appointment->all_day = 0; | |
3143 } | |
3144 break; | |
3145 case 0x8234: // TimeZone as String | |
3146 DEBUG_EMAIL(("TimeZone of times - ")); | |
3147 MALLOC_APPOINTMENT(item); | |
3148 LIST_COPY(item->appointment->timezonestring, (char*)); | |
3149 DEBUG_EMAIL(("%s\n", item->appointment->timezonestring)); | |
3150 break; | |
3151 case 0x8235: // Appointment start time | |
3152 DEBUG_EMAIL(("Appointment Start Time - ")); | |
3153 MALLOC_APPOINTMENT(item); | |
3154 LIST_COPY(item->appointment->start, (FILETIME*)); | |
3155 DEBUG_EMAIL(("%s\n", fileTimeToAscii((FILETIME*)item->appointment->start))); | |
3156 break; | |
3157 case 0x8236: // Appointment end time | |
3158 DEBUG_EMAIL(("Appointment End Time - ")); | |
3159 MALLOC_APPOINTMENT(item); | |
3160 LIST_COPY(item->appointment->end, (FILETIME*)); | |
3161 DEBUG_EMAIL(("%s\n", fileTimeToAscii((FILETIME*)item->appointment->start))); | |
3162 break; | |
3163 case 0x8516: // Journal time start | |
3164 DEBUG_EMAIL(("Duplicate Time Start - ")); | |
3165 DEBUG_EMAIL(("%s\n", fileTimeToAscii((FILETIME*)list->items[x]->data))); | |
3166 break; | |
3167 case 0x8517: // Journal time end | |
3168 DEBUG_EMAIL(("Duplicate Time End - ")); | |
3169 DEBUG_EMAIL(("%s\n", fileTimeToAscii((FILETIME*)list->items[x]->data))); | |
3170 break; | |
3171 case 0x8530: // Followup | |
3172 DEBUG_EMAIL(("Followup String - ")); | |
3173 MALLOC_CONTACT(item); | |
3174 LIST_COPY(item->contact->followup, (char*)); | |
3175 DEBUG_EMAIL(("%s\n", item->contact->followup)); | |
3176 break; | |
3177 case 0x8534: // Mileage | |
3178 DEBUG_EMAIL(("Mileage - ")); | |
3179 MALLOC_CONTACT(item); | |
3180 LIST_COPY(item->contact->mileage, (char*)); | |
3181 DEBUG_EMAIL(("%s\n", item->contact->mileage)); | |
3182 break; | |
3183 case 0x8535: // Billing Information | |
3184 DEBUG_EMAIL(("Billing Information - ")); | |
3185 MALLOC_CONTACT(item); | |
3186 LIST_COPY(item->contact->billing_information, (char*)); | |
3187 DEBUG_EMAIL(("%s\n", item->contact->billing_information)); | |
3188 break; | |
3189 case 0x8554: // Outlook Version | |
3190 DEBUG_EMAIL(("Outlook Version - ")); | |
3191 LIST_COPY(item->outlook_version, (char*)); | |
3192 DEBUG_EMAIL(("%s\n", item->outlook_version)); | |
3193 break; | |
3194 case 0x8560: // Appointment Reminder Time | |
3195 DEBUG_EMAIL(("Appointment Reminder Time - ")); | |
3196 MALLOC_APPOINTMENT(item); | |
3197 LIST_COPY(item->appointment->reminder, (FILETIME*)); | |
3198 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->appointment->reminder))); | |
3199 break; | |
3200 case 0x8700: // Journal Type | |
3201 DEBUG_EMAIL(("Journal Entry Type - ")); | |
3202 MALLOC_JOURNAL(item); | |
3203 LIST_COPY(item->journal->type, (char*)); | |
3204 DEBUG_EMAIL(("%s\n", item->journal->type)); | |
3205 break; | |
3206 case 0x8706: // Journal Start date/time | |
3207 DEBUG_EMAIL(("Start Timestamp - ")); | |
3208 MALLOC_JOURNAL(item); | |
3209 LIST_COPY(item->journal->start, (FILETIME*)); | |
3210 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->journal->start))); | |
3211 break; | |
3212 case 0x8708: // Journal End date/time | |
3213 DEBUG_EMAIL(("End Timestamp - ")); | |
3214 MALLOC_JOURNAL(item); | |
3215 LIST_COPY(item->journal->end, (FILETIME*)); | |
3216 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->journal->end))); | |
3217 break; | |
3218 case 0x8712: // Title? | |
3219 DEBUG_EMAIL(("Journal Entry Type - ")); | |
3220 MALLOC_JOURNAL(item); | |
3221 LIST_COPY(item->journal->type, (char*)); | |
3222 DEBUG_EMAIL(("%s\n", item->journal->type)); | |
3223 break; | |
3224 default: | |
3225 DEBUG_EMAIL(("unknown type %#x\n", list->items[x]->id)); | |
3226 /* Reference Types | |
3227 | |
3228 2 - 0x0002 - Signed 16bit value | |
3229 3 - 0x0003 - Signed 32bit value | |
3230 11 - 0x000B - Boolean (non-zero = true) | |
3231 13 - 0x000D - Embedded Object | |
3232 30 - 0x001E - Null terminated String | |
3233 31 - 0x001F - Unicode string | |
3234 64 - 0x0040 - Systime - Filetime structure | |
3235 72 - 0x0048 - OLE Guid | |
3236 258 - 0x0102 - Binary data | |
3237 | |
3238 - 0x1003 - Array of 32bit values | |
3239 - 0x101E - Array of Strings | |
3240 - 0x1102 - Array of Binary data | |
3241 */ | |
3242 // DEBUG_EMAIL(("Unknown id [%#x, size=%#x]\n", list->items[x]->id, list->items[x]->size)); | |
3243 if (list->items[x]->type == 0x02) { | |
3244 DEBUG_EMAIL(("Unknown 16bit int = %hi\n", *(int16_t*)list->items[x]->data)); | |
3245 } else if (list->items[x]->type == 0x03) { | |
3246 DEBUG_EMAIL(("Unknown 32bit int = %i\n", *(int32_t*)list->items[x]->data)); | |
3247 } else if (list->items[x]->type == 0x0b) { | |
3248 DEBUG_EMAIL(("Unknown 16bit boolean = %s [%hi]\n", | |
3249 (*((int16_t*)list->items[x]->data)!=0?"True":"False"), | |
3250 *((int16_t*)list->items[x]->data))); | |
3251 } else if (list->items[x]->type == 0x1e) { | |
3252 DEBUG_EMAIL(("Unknown String Data = \"%s\" [%#x]\n", | |
3253 list->items[x]->data, list->items[x]->type)); | |
3254 } else if (list->items[x]->type == 0x40) { | |
3255 DEBUG_EMAIL(("Unknown Date = \"%s\" [%#x]\n", | |
3256 fileTimeToAscii((FILETIME*)list->items[x]->data), | |
3257 list->items[x]->type)); | |
3258 } else if (list->items[x]->type == 0x102) { | |
3259 DEBUG_EMAIL(("Unknown Binary Data [size = %#x]\n", | |
3260 list->items[x]->size)); | |
3261 DEBUG_HEXDUMP(list->items[x]->data, list->items[x]->size); | |
3262 } else if (list->items[x]->type == 0x101E) { | |
3263 DEBUG_EMAIL(("Unknown Array of Strings [%#x]\n", | |
3264 list->items[x]->type)); | |
3265 } else { | |
3266 DEBUG_EMAIL(("Unknown Not Printable [%#x]\n", | |
3267 list->items[x]->type)); | |
3268 } | |
3269 if (list->items[x]->data) { | |
3270 free(list->items[x]->data); | |
3271 list->items[x]->data = NULL; | |
3272 } | |
3273 } | |
3274 x++; | |
3275 } | |
3276 x = 0; | |
3277 list = list->next; | |
3278 next = 1; | |
3279 } | |
3280 DEBUG_RET(); | |
3281 return 0; | |
16 | 3282 } |
3283 | |
3284 | |
3285 int32_t _pst_free_list(pst_num_array *list) { | |
43 | 3286 pst_num_array *l; |
3287 DEBUG_ENT("_pst_free_list"); | |
3288 while (list) { | |
3289 if (list->items) { | |
3290 int32_t x; | |
3291 for (x=0; x < list->orig_count; x++) { | |
3292 if (list->items[x]) { | |
3293 if (list->items[x]->data) free(list->items[x]->data); | |
3294 free(list->items[x]); | |
3295 } | |
3296 } | |
3297 free(list->items); | |
3298 } | |
3299 l = list; | |
3300 list = list->next; | |
3301 free (l); | |
3302 } | |
3303 DEBUG_RET(); | |
3304 return 1; | |
16 | 3305 } |
3306 | |
3307 | |
3308 int32_t _pst_free_id2(pst_index2_ll * head) { | |
43 | 3309 pst_index2_ll *t; |
3310 DEBUG_ENT("_pst_free_id2"); | |
3311 while (head) { | |
3312 t = head->next; | |
3313 free (head); | |
3314 head = t; | |
3315 } | |
3316 DEBUG_RET(); | |
3317 return 1; | |
16 | 3318 } |
3319 | |
3320 | |
3321 int32_t _pst_free_id (pst_index_ll *head) { | |
43 | 3322 pst_index_ll *t; |
3323 DEBUG_ENT("_pst_free_id"); | |
3324 while (head) { | |
3325 t = head->next; | |
3326 free(head); | |
3327 head = t; | |
3328 } | |
3329 DEBUG_RET(); | |
3330 return 1; | |
16 | 3331 } |
3332 | |
3333 | |
3334 int32_t _pst_free_desc (pst_desc_ll *head) { | |
43 | 3335 pst_desc_ll *t; |
3336 DEBUG_ENT("_pst_free_desc"); | |
3337 while (head) { | |
3338 while (head->child) { | |
3339 head = head->child; | |
3340 } | |
3341 | |
3342 // point t to the next item | |
3343 t = head->next; | |
3344 if (!t && head->parent) { | |
3345 t = head->parent; | |
3346 t->child = NULL; // set the child to NULL so we don't come back here again! | |
3347 } | |
3348 | |
3349 if (head) free(head); | |
3350 else DIE(("head is NULL")); | |
3351 | |
3352 head = t; | |
3353 } | |
3354 DEBUG_RET(); | |
3355 return 1; | |
16 | 3356 } |
3357 | |
3358 | |
3359 int32_t _pst_free_xattrib(pst_x_attrib_ll *x) { | |
43 | 3360 pst_x_attrib_ll *t; |
3361 DEBUG_ENT("_pst_free_xattrib"); | |
3362 while (x) { | |
3363 if (x->data) free(x->data); | |
3364 t = x->next; | |
3365 free(x); | |
3366 x = t; | |
3367 } | |
3368 DEBUG_RET(); | |
3369 return 1; | |
16 | 3370 } |
3371 | |
3372 | |
3373 pst_index2_ll * _pst_build_id2(pst_file *pf, pst_index_ll* list, pst_index2_ll* head_ptr) { | |
43 | 3374 pst_block_header block_head; |
3375 pst_index2_ll *head = NULL, *tail = NULL; | |
3376 int32_t x = 0, b_ptr = 0; | |
3377 char *buf = NULL; | |
3378 pst_id2_assoc id2_rec; | |
3379 pst_index_ll *i_ptr = NULL; | |
3380 pst_index2_ll *i2_ptr = NULL; | |
3381 DEBUG_ENT("_pst_build_id2"); | |
3382 | |
3383 if (head_ptr) { | |
3384 head = head_ptr; | |
3385 while (head_ptr) head_ptr = (tail = head_ptr)->next; | |
3386 } | |
3387 if (_pst_read_block_size(pf, list->offset, list->size, &buf, PST_NO_ENC, 0) < list->size) { | |
3388 //an error occured in block read | |
3389 WARN(("block read error occured. offset = %#llx, size = %#llx\n", list->offset, list->size)); | |
3390 if (buf) free(buf); | |
3391 DEBUG_RET(); | |
3392 return NULL; | |
3393 } | |
3394 DEBUG_HEXDUMPC(buf, list->size, 16); | |
3395 | |
3396 memcpy(&block_head, buf, sizeof(block_head)); | |
3397 LE16_CPU(block_head.type); | |
3398 LE16_CPU(block_head.count); | |
3399 | |
3400 if (block_head.type != 0x0002) { // some sort of constant? | |
3401 WARN(("Unknown constant [%#x] at start of id2 values [offset %#llx].\n", block_head.type, list->offset)); | |
3402 if (buf) free(buf); | |
3403 DEBUG_RET(); | |
3404 return NULL; | |
3405 } | |
3406 | |
3407 DEBUG_INDEX(("ID %#x is likely to be a description record. Count is %i (offset %#x)\n", | |
3408 list->id, block_head.count, list->offset)); | |
3409 x = 0; | |
3410 b_ptr = 0x04; | |
3411 while (x < block_head.count) { | |
3412 memcpy(&id2_rec, &(buf[b_ptr]), sizeof(id2_rec)); | |
3413 LE32_CPU(id2_rec.id2); | |
3414 LE32_CPU(id2_rec.id); | |
3415 LE32_CPU(id2_rec.table2); | |
3416 | |
3417 b_ptr += sizeof(id2_rec); | |
3418 DEBUG_INDEX(("\tid2 = %#x, id = %#x, table2 = %#x\n", id2_rec.id2, id2_rec.id, id2_rec.table2)); | |
3419 if ((i_ptr = _pst_getID(pf, id2_rec.id)) == NULL) { | |
3420 DEBUG_WARN(("\t\t%#x - Not Found\n", id2_rec.id)); | |
3421 } else { | |
3422 DEBUG_INDEX(("\t\t%#x - Offset %#x, u1 %#x, Size %i(%#x)\n", i_ptr->id, i_ptr->offset, i_ptr->u1, i_ptr->size, i_ptr->size)); | |
3423 // add it to the linked list | |
3424 i2_ptr = (pst_index2_ll*) xmalloc(sizeof(pst_index2_ll)); | |
3425 i2_ptr->id2 = id2_rec.id2; | |
3426 i2_ptr->id = i_ptr; | |
3427 i2_ptr->next = NULL; | |
3428 if (!head) head = i2_ptr; | |
3429 if (tail) tail->next = i2_ptr; | |
3430 tail = i2_ptr; | |
3431 if (id2_rec.table2 != 0) { | |
3432 if ((i_ptr = _pst_getID(pf, id2_rec.table2)) == NULL) { | |
3433 DEBUG_WARN(("\tTable2 [%#x] not found\n", id2_rec.table2)); | |
3434 } | |
3435 else { | |
3436 DEBUG_INDEX(("\tGoing deeper for table2 [%#x]\n", id2_rec.table2)); | |
3437 if ((i2_ptr = _pst_build_id2(pf, i_ptr, head))) { | |
3438 // DEBUG_INDEX(("_pst_build_id2(): \t\tAdding new list onto end of current\n")); | |
3439 // if (!head) | |
3440 // head = i2_ptr; | |
3441 // if (tail) | |
3442 // tail->next = i2_ptr; | |
3443 // while (i2_ptr->next) | |
3444 // i2_ptr = i2_ptr->next; | |
3445 // tail = i2_ptr; | |
3446 } | |
3447 // need to re-establish tail | |
3448 DEBUG_INDEX(("Returned from depth\n")); | |
3449 if (tail) { | |
3450 while (tail->next) tail = tail->next; | |
3451 } | |
3452 } | |
3453 } | |
3454 } | |
3455 x++; | |
3456 } | |
3457 if (buf) free (buf); | |
3458 DEBUG_RET(); | |
3459 return head; | |
16 | 3460 } |
3461 | |
3462 | |
3463 // This version of free does NULL check first | |
3464 #define SAFE_FREE(x) {if (x) free(x);} | |
3465 | |
3466 void _pst_freeItem(pst_item *item) { | |
43 | 3467 pst_item_attach *t; |
3468 pst_item_extra_field *et; | |
3469 | |
3470 DEBUG_ENT("_pst_freeItem"); | |
3471 if (item) { | |
3472 if (item->email) { | |
3473 SAFE_FREE(item->email->arrival_date); | |
3474 SAFE_FREE(item->email->body); | |
3475 SAFE_FREE(item->email->cc_address); | |
3476 SAFE_FREE(item->email->common_name); | |
3477 SAFE_FREE(item->email->encrypted_body); | |
3478 SAFE_FREE(item->email->encrypted_htmlbody); | |
3479 SAFE_FREE(item->email->header); | |
3480 SAFE_FREE(item->email->htmlbody); | |
3481 SAFE_FREE(item->email->in_reply_to); | |
3482 SAFE_FREE(item->email->messageid); | |
3483 SAFE_FREE(item->email->outlook_recipient); | |
3484 SAFE_FREE(item->email->outlook_recipient2); | |
3485 SAFE_FREE(item->email->outlook_sender); | |
3486 SAFE_FREE(item->email->outlook_sender_name); | |
3487 SAFE_FREE(item->email->outlook_sender2); | |
3488 SAFE_FREE(item->email->proc_subject); | |
3489 SAFE_FREE(item->email->recip_access); | |
3490 SAFE_FREE(item->email->recip_address); | |
3491 SAFE_FREE(item->email->recip2_access); | |
3492 SAFE_FREE(item->email->recip2_address); | |
3493 SAFE_FREE(item->email->reply_to); | |
3494 SAFE_FREE(item->email->rtf_body_tag); | |
3495 SAFE_FREE(item->email->rtf_compressed); | |
3496 SAFE_FREE(item->email->return_path_address); | |
3497 SAFE_FREE(item->email->sender_access); | |
3498 SAFE_FREE(item->email->sender_address); | |
3499 SAFE_FREE(item->email->sender2_access); | |
3500 SAFE_FREE(item->email->sender2_address); | |
3501 SAFE_FREE(item->email->sent_date); | |
3502 SAFE_FREE(item->email->sentmail_folder); | |
3503 SAFE_FREE(item->email->sentto_address); | |
3504 if (item->email->subject) | |
3505 SAFE_FREE(item->email->subject->subj); | |
3506 SAFE_FREE(item->email->subject); | |
3507 free(item->email); | |
3508 } | |
3509 if (item->folder) { | |
3510 free(item->folder); | |
3511 } | |
3512 if (item->message_store) { | |
3513 SAFE_FREE(item->message_store->deleted_items_folder); | |
3514 SAFE_FREE(item->message_store->search_root_folder); | |
3515 SAFE_FREE(item->message_store->top_of_personal_folder); | |
3516 SAFE_FREE(item->message_store->top_of_folder); | |
3517 free(item->message_store); | |
3518 } | |
3519 if (item->contact) { | |
3520 SAFE_FREE(item->contact->access_method); | |
3521 SAFE_FREE(item->contact->account_name); | |
3522 SAFE_FREE(item->contact->address1); | |
3523 SAFE_FREE(item->contact->address1a); | |
3524 SAFE_FREE(item->contact->address1_desc); | |
3525 SAFE_FREE(item->contact->address1_transport); | |
3526 SAFE_FREE(item->contact->address2); | |
3527 SAFE_FREE(item->contact->address2a); | |
3528 SAFE_FREE(item->contact->address2_desc); | |
3529 SAFE_FREE(item->contact->address2_transport); | |
3530 SAFE_FREE(item->contact->address3); | |
3531 SAFE_FREE(item->contact->address3a); | |
3532 SAFE_FREE(item->contact->address3_desc); | |
3533 SAFE_FREE(item->contact->address3_transport); | |
3534 SAFE_FREE(item->contact->assistant_name); | |
3535 SAFE_FREE(item->contact->assistant_phone); | |
3536 SAFE_FREE(item->contact->billing_information); | |
3537 SAFE_FREE(item->contact->birthday); | |
3538 SAFE_FREE(item->contact->business_address); | |
3539 SAFE_FREE(item->contact->business_city); | |
3540 SAFE_FREE(item->contact->business_country); | |
3541 SAFE_FREE(item->contact->business_fax); | |
3542 SAFE_FREE(item->contact->business_homepage); | |
3543 SAFE_FREE(item->contact->business_phone); | |
3544 SAFE_FREE(item->contact->business_phone2); | |
3545 SAFE_FREE(item->contact->business_po_box); | |
3546 SAFE_FREE(item->contact->business_postal_code); | |
3547 SAFE_FREE(item->contact->business_state); | |
3548 SAFE_FREE(item->contact->business_street); | |
3549 SAFE_FREE(item->contact->callback_phone); | |
3550 SAFE_FREE(item->contact->car_phone); | |
3551 SAFE_FREE(item->contact->company_main_phone); | |
3552 SAFE_FREE(item->contact->company_name); | |
3553 SAFE_FREE(item->contact->computer_name); | |
3554 SAFE_FREE(item->contact->customer_id); | |
3555 SAFE_FREE(item->contact->def_postal_address); | |
3556 SAFE_FREE(item->contact->department); | |
3557 SAFE_FREE(item->contact->display_name_prefix); | |
3558 SAFE_FREE(item->contact->first_name); | |
3559 SAFE_FREE(item->contact->followup); | |
3560 SAFE_FREE(item->contact->free_busy_address); | |
3561 SAFE_FREE(item->contact->ftp_site); | |
3562 SAFE_FREE(item->contact->fullname); | |
3563 SAFE_FREE(item->contact->gov_id); | |
3564 SAFE_FREE(item->contact->hobbies); | |
3565 SAFE_FREE(item->contact->home_address); | |
3566 SAFE_FREE(item->contact->home_city); | |
3567 SAFE_FREE(item->contact->home_country); | |
3568 SAFE_FREE(item->contact->home_fax); | |
3569 SAFE_FREE(item->contact->home_po_box); | |
3570 SAFE_FREE(item->contact->home_phone); | |
3571 SAFE_FREE(item->contact->home_phone2); | |
3572 SAFE_FREE(item->contact->home_postal_code); | |
3573 SAFE_FREE(item->contact->home_state); | |
3574 SAFE_FREE(item->contact->home_street); | |
3575 SAFE_FREE(item->contact->initials); | |
3576 SAFE_FREE(item->contact->isdn_phone); | |
3577 SAFE_FREE(item->contact->job_title); | |
3578 SAFE_FREE(item->contact->keyword); | |
3579 SAFE_FREE(item->contact->language); | |
3580 SAFE_FREE(item->contact->location); | |
3581 SAFE_FREE(item->contact->manager_name); | |
3582 SAFE_FREE(item->contact->middle_name); | |
3583 SAFE_FREE(item->contact->mileage); | |
3584 SAFE_FREE(item->contact->mobile_phone); | |
3585 SAFE_FREE(item->contact->nickname); | |
3586 SAFE_FREE(item->contact->office_loc); | |
3587 SAFE_FREE(item->contact->org_id); | |
3588 SAFE_FREE(item->contact->other_address); | |
3589 SAFE_FREE(item->contact->other_city); | |
3590 SAFE_FREE(item->contact->other_country); | |
3591 SAFE_FREE(item->contact->other_phone); | |
3592 SAFE_FREE(item->contact->other_po_box); | |
3593 SAFE_FREE(item->contact->other_postal_code); | |
3594 SAFE_FREE(item->contact->other_state); | |
3595 SAFE_FREE(item->contact->other_street); | |
3596 SAFE_FREE(item->contact->pager_phone); | |
3597 SAFE_FREE(item->contact->personal_homepage); | |
3598 SAFE_FREE(item->contact->pref_name); | |
3599 SAFE_FREE(item->contact->primary_fax); | |
3600 SAFE_FREE(item->contact->primary_phone); | |
3601 SAFE_FREE(item->contact->profession); | |
3602 SAFE_FREE(item->contact->radio_phone); | |
3603 SAFE_FREE(item->contact->spouse_name); | |
3604 SAFE_FREE(item->contact->suffix); | |
3605 SAFE_FREE(item->contact->surname); | |
3606 SAFE_FREE(item->contact->telex); | |
3607 SAFE_FREE(item->contact->transmittable_display_name); | |
3608 SAFE_FREE(item->contact->ttytdd_phone); | |
3609 SAFE_FREE(item->contact->wedding_anniversary); | |
3610 free(item->contact); | |
3611 } | |
3612 while (item->attach) { | |
3613 SAFE_FREE(item->attach->filename1); | |
3614 SAFE_FREE(item->attach->filename2); | |
3615 SAFE_FREE(item->attach->mimetype); | |
3616 SAFE_FREE(item->attach->data); | |
3617 t = item->attach->next; | |
3618 free(item->attach); | |
3619 item->attach = t; | |
3620 } | |
3621 while (item->extra_fields) { | |
3622 SAFE_FREE(item->extra_fields->field_name); | |
3623 SAFE_FREE(item->extra_fields->value); | |
3624 et = item->extra_fields->next; | |
3625 free(item->extra_fields); | |
3626 item->extra_fields = et; | |
3627 } | |
3628 if (item->journal) { | |
3629 SAFE_FREE(item->journal->end); | |
3630 SAFE_FREE(item->journal->start); | |
3631 SAFE_FREE(item->journal->type); | |
3632 free(item->journal); | |
3633 } | |
3634 if (item->appointment) { | |
3635 SAFE_FREE(item->appointment->location); | |
3636 SAFE_FREE(item->appointment->reminder); | |
3637 SAFE_FREE(item->appointment->start); | |
3638 SAFE_FREE(item->appointment->end); | |
3639 SAFE_FREE(item->appointment->timezonestring); | |
3640 free(item->appointment); | |
3641 } | |
3642 SAFE_FREE(item->ascii_type); | |
3643 SAFE_FREE(item->comment); | |
3644 SAFE_FREE(item->create_date); | |
3645 SAFE_FREE(item->file_as); | |
3646 SAFE_FREE(item->modify_date); | |
3647 SAFE_FREE(item->outlook_version); | |
3648 SAFE_FREE(item->record_key); | |
3649 free(item); | |
3650 } | |
3651 DEBUG_RET(); | |
16 | 3652 } |
3653 | |
3654 | |
35 | 3655 /** |
3656 * The offset might be zero, in which case we have no data, so return a pair of null pointers. | |
3657 * Or, the offset might end in 0xf, so it is an id2 pointer, in which case we read the id2 block. | |
3658 * Otherwise, the offset>>4 is an index into the table of offsets in the buffer. | |
3659 */ | |
3660 int32_t _pst_getBlockOffsetPointer(pst_file *pf, pst_index2_ll *i2_head, unsigned char *buf, int32_t read_size, int32_t i_offset, int32_t offset, pst_block_offset_pointer *p) { | |
43 | 3661 int32_t size; |
3662 pst_block_offset block_offset; | |
3663 DEBUG_ENT("_pst_getBlockOffsetPointer"); | |
3664 if (p->needfree) free(p->from); | |
3665 p->from = NULL; | |
3666 p->needfree = 0; | |
3667 if (!offset) { | |
3668 p->from = p->to = NULL; | |
3669 } | |
3670 else if ((offset & 0xf) == 0xf) { | |
3671 DEBUG_WARN(("Found id2 %#x value. Will follow it\n", offset)); | |
3672 size = _pst_ff_getID2block(pf, offset, i2_head, &(p->from)); | |
3673 if (size) { | |
3674 p->to = p->from + size; | |
3675 p->needfree = 1; | |
3676 } | |
3677 else { | |
3678 p->from = p->to = NULL; | |
3679 } | |
3680 } | |
3681 else if (_pst_getBlockOffset(buf, read_size, i_offset, offset, &block_offset)) { | |
3682 p->from = p->to = NULL; | |
3683 } | |
3684 else { | |
3685 p->from = buf + block_offset.from; | |
3686 p->to = buf + block_offset.to; | |
3687 } | |
3688 DEBUG_RET(); | |
3689 return (p->from) ? 0 : 1; | |
35 | 3690 } |
3691 | |
3692 | |
31 | 3693 int32_t _pst_getBlockOffset(unsigned char *buf, int32_t read_size, int32_t i_offset, int32_t offset, pst_block_offset *p) { |
43 | 3694 int32_t low = offset & 0xf; |
3695 int32_t of1 = offset >> 4; | |
3696 DEBUG_ENT("_pst_getBlockOffset"); | |
3697 if (!p || !buf || !i_offset || low || (i_offset+2+of1+sizeof(*p) > read_size)) { | |
3698 DEBUG_WARN(("p is NULL or buf is NULL or offset is 0 or offset has low bits or beyond read size (%p, %p, %#x, %i, %i)\n", p, buf, offset, read_size, i_offset)); | |
3699 DEBUG_RET(); | |
3700 return -1; | |
3701 } | |
3702 memcpy(&(p->from), &(buf[(i_offset+2)+of1]), sizeof(p->from)); | |
3703 memcpy(&(p->to), &(buf[(i_offset+2)+of1+sizeof(p->from)]), sizeof(p->to)); | |
3704 LE16_CPU(p->from); | |
3705 LE16_CPU(p->to); | |
3706 DEBUG_WARN(("get block offset finds from=%i(%#x), to=%i(%#x)\n", p->from, p->from, p->to, p->to)); | |
3707 if (p->from > p->to) { | |
3708 DEBUG_WARN(("get block offset from > to")); | |
3709 return -1; | |
3710 } | |
3711 DEBUG_RET(); | |
3712 return 0; | |
16 | 3713 } |
3714 | |
3715 | |
43 | 3716 pst_index_ll* _pst_getID(pst_file* pf, uint64_t id) { |
3717 pst_index_ll *ptr = NULL; | |
3718 DEBUG_ENT("_pst_getID"); | |
3719 if (id == 0) { | |
3720 DEBUG_RET(); | |
3721 return NULL; | |
3722 } | |
3723 | |
3724 //if (id & 1) DEBUG_INDEX(("have odd id bit %#x\n", id)); | |
3725 //if (id & 2) DEBUG_INDEX(("have two id bit %#x\n", id)); | |
3726 id -= (id & 1); | |
3727 | |
3728 DEBUG_INDEX(("Trying to find %#llx\n", id)); | |
3729 if (!ptr) ptr = pf->i_head; | |
3730 while (ptr && (ptr->id != id)) { | |
3731 ptr = ptr->next; | |
3732 } | |
3733 if (ptr) {DEBUG_INDEX(("Found Value %#x\n", id)); } | |
3734 else {DEBUG_INDEX(("ERROR: Value %#x not found\n", id)); } | |
3735 DEBUG_RET(); | |
3736 return ptr; | |
16 | 3737 } |
3738 | |
3739 | |
43 | 3740 pst_index_ll * _pst_getID2(pst_index2_ll *ptr, uint32_t id) { |
3741 DEBUG_ENT("_pst_getID2"); | |
3742 DEBUG_INDEX(("Head = %p\n", ptr)); | |
3743 DEBUG_INDEX(("Trying to find %#x\n", id)); | |
3744 while (ptr && (ptr->id2 != id)) { | |
3745 ptr = ptr->next; | |
3746 } | |
3747 if (ptr) { | |
3748 if (ptr->id) {DEBUG_INDEX(("Found value %#x\n", ptr->id->id)); } | |
3749 else {DEBUG_INDEX(("Found value, though it is NULL!\n"));} | |
3750 DEBUG_RET(); | |
3751 return ptr->id; | |
3752 } | |
3753 DEBUG_INDEX(("ERROR Not Found\n")); | |
3754 DEBUG_RET(); | |
3755 return NULL; | |
16 | 3756 } |
3757 | |
3758 | |
35 | 3759 /** |
3760 * find the id in the descriptor tree rooted at pf->d_head | |
3761 * | |
43 | 3762 * @param pf global pst file pointer |
3763 * @param id the id we are looking for | |
35 | 3764 * |
3765 * @return pointer to the pst_desc_ll node in the descriptor tree | |
3766 */ | |
43 | 3767 pst_desc_ll* _pst_getDptr(pst_file *pf, uint32_t id) { |
3768 pst_desc_ll *ptr = pf->d_head; | |
3769 DEBUG_ENT("_pst_getDptr"); | |
3770 while (ptr && (ptr->id != id)) { | |
3771 if (ptr->child) { | |
3772 ptr = ptr->child; | |
3773 continue; | |
3774 } | |
3775 while (!ptr->next && ptr->parent) { | |
3776 ptr = ptr->parent; | |
3777 } | |
3778 ptr = ptr->next; | |
3779 } | |
3780 DEBUG_RET(); | |
3781 return ptr; // will be NULL or record we are looking for | |
16 | 3782 } |
3783 | |
3784 | |
3785 int32_t _pst_printDptr(pst_file *pf) { | |
43 | 3786 pst_desc_ll *ptr = pf->d_head; |
3787 int32_t depth = 0; | |
3788 char spaces[100]; | |
3789 DEBUG_ENT("_pst_printDptr"); | |
3790 memset(spaces, ' ', 99); | |
3791 spaces[99] = '\0'; | |
3792 while (ptr) { | |
3793 DEBUG_INDEX(("%s%#x [%i] desc=%#x, list=%#x\n", &(spaces[(99-depth<0?0:99-depth)]), ptr->id, ptr->no_child, | |
3794 (ptr->desc==NULL?0:ptr->desc->id), | |
3795 (ptr->list_index==NULL?0:ptr->list_index->id))); | |
3796 if (ptr->child) { | |
3797 depth++; | |
3798 ptr = ptr->child; | |
3799 continue; | |
3800 } | |
3801 while (!ptr->next && ptr->parent) { | |
3802 depth--; | |
3803 ptr = ptr->parent; | |
3804 } | |
3805 ptr = ptr->next; | |
3806 } | |
3807 DEBUG_RET(); | |
3808 return 0; | |
16 | 3809 } |
3810 | |
3811 | |
3812 int32_t _pst_printIDptr(pst_file* pf) { | |
43 | 3813 pst_index_ll *ptr = pf->i_head; |
3814 DEBUG_ENT("_pst_printIDptr"); | |
3815 while (ptr) { | |
3816 DEBUG_INDEX(("%#x offset=%#x size=%#x\n", ptr->id, ptr->offset, ptr->size)); | |
3817 ptr = ptr->next; | |
3818 } | |
3819 DEBUG_RET(); | |
3820 return 0; | |
16 | 3821 } |
3822 | |
3823 | |
3824 int32_t _pst_printID2ptr(pst_index2_ll *ptr) { | |
43 | 3825 DEBUG_ENT("_pst_printID2ptr"); |
3826 while (ptr) { | |
3827 DEBUG_INDEX(("%#x id=%#x\n", ptr->id2, (ptr->id!=NULL?ptr->id->id:0))); | |
3828 ptr = ptr->next; | |
3829 } | |
3830 DEBUG_RET(); | |
3831 return 0; | |
16 | 3832 } |
3833 | |
3834 | |
43 | 3835 size_t _pst_read_block(FILE *fp, off_t offset, void **buf) { |
3836 int16_t size16; | |
3837 size_t size; | |
3838 off_t fpos; | |
3839 DEBUG_ENT("_pst_read_block"); | |
3840 DEBUG_READ(("Reading block from %#x\n", offset)); | |
3841 fpos = ftell(fp); | |
3842 fseek(fp, offset, SEEK_SET); | |
3843 fread(&size16, sizeof(int16_t), 1, fp); | |
3844 LE16_CPU(size16); | |
3845 size = size16; | |
3846 fseek(fp, offset, SEEK_SET); | |
3847 DEBUG_READ(("Allocating %i bytes\n", size)); | |
3848 if (*buf) { | |
3849 DEBUG_READ(("Freeing old memory\n")); | |
3850 free(*buf); | |
3851 } | |
3852 *buf = (void*)xmalloc(size); | |
3853 size = fread(*buf, 1, size, fp); | |
3854 fseek(fp, fpos, SEEK_SET); | |
3855 DEBUG_RET(); | |
3856 return size; | |
16 | 3857 } |
3858 | |
3859 | |
3860 // when the first byte of the block being read is 01, then we can assume | |
3861 // that it is a list of further ids to read and we will follow those ids | |
3862 // recursively calling this function until we have all the data | |
3863 // we could do decryption of the encrypted PST files here | |
43 | 3864 size_t _pst_read_block_size(pst_file *pf, off_t offset, size_t size, char **buf, int32_t do_enc, unsigned char is_index) { |
3865 off_t fpos; | |
3866 int32_t x; | |
3867 int16_t count, y; | |
3868 char *buf2 = NULL, *buf3 = NULL; | |
3869 unsigned char fdepth; | |
3870 pst_index_ll *ptr = NULL; | |
3871 size_t rsize, z; | |
3872 | |
3873 DEBUG_ENT("_pst_read_block_size"); | |
3874 DEBUG_READ(("Reading block from %#x, %i bytes\n", offset, size)); | |
3875 | |
3876 fpos = ftell(pf->fp); | |
3877 fseek(pf->fp, offset, SEEK_SET); | |
3878 if (*buf) { | |
3879 DEBUG_READ(("Freeing old memory\n")); | |
3880 free(*buf); | |
3881 } | |
3882 | |
3883 *buf = (void*) xmalloc(size+1); //plus one so that we can NUL terminate it later | |
3884 rsize = fread(*buf, 1, size, pf->fp); | |
3885 if (rsize != size) { | |
3886 DEBUG_WARN(("Didn't read all that I could. fread returned less [%i instead of %i]\n", rsize, size)); | |
3887 if (feof(pf->fp)) { | |
3888 DEBUG_WARN(("We tried to read past the end of the file at [offset %#x, size %#x]\n", offset, size)); | |
3889 } else if (ferror(pf->fp)) { | |
3890 DEBUG_WARN(("Error is set on file stream.\n")); | |
3891 } else { | |
3892 DEBUG_WARN(("I can't tell why it failed\n")); | |
3893 } | |
3894 size = rsize; | |
3895 } | |
3896 | |
3897 // DEBUG_HEXDUMP(*buf, size); | |
3898 | |
3899 /* if (is_index) { | |
3900 DEBUG_READ(("_pst_read_block_size: ODD_BLOCK should be here\n")); | |
3901 DEBUG_READ(("\t: byte 0-1: %#x %#x\n", (*buf)[0], (*buf)[1])); | |
3902 }*/ | |
3903 | |
3904 if ((*buf)[0] == 0x01 && (*buf)[1] != 0x00 && is_index) { | |
3905 //don't do this recursion if we should be at a leaf node | |
3906 memcpy(&count, &((*buf)[2]), sizeof(int16_t)); | |
3907 LE16_CPU(count); | |
3908 memcpy(&fdepth, &((*buf)[1]), sizeof(fdepth)); | |
3909 DEBUG_READ(("Seen indexes to blocks. Depth is %i\n", fdepth)); | |
3910 // do fancy stuff! :) | |
3911 DEBUG_READ(("There are %i ids\n", count)); | |
3912 // if first 2 blocks are 01 01 then index to blocks | |
3913 size = 0; | |
3914 y = 0; | |
3915 while (y < count) { | |
3916 memcpy(&x, &(*buf)[0x08+(y*4)], sizeof(int32_t)); | |
3917 LE32_CPU(x); | |
3918 if ((ptr = _pst_getID(pf, x)) == NULL) { | |
3919 WARN(("Error. Cannot find ID [%#x] during multi-block read\n", x)); | |
3920 buf3 = (char*) realloc(buf3, size+1); | |
3921 buf3[size] = '\0'; | |
3922 *buf = buf3; | |
3923 fseek(pf->fp, fpos, SEEK_SET); | |
3924 DEBUG_RET(); | |
3925 return size; | |
3926 } | |
3927 if ((z = _pst_read_block_size(pf, ptr->offset, ptr->size, &buf2, do_enc, fdepth-1)) < ptr->size) { | |
3928 buf3 = (char*) realloc(buf3, size+1); | |
3929 buf3[size] = '\0'; | |
3930 *buf = buf3; | |
3931 fseek(pf->fp, fpos, SEEK_SET); | |
3932 DEBUG_RET(); | |
3933 return size; | |
3934 } | |
3935 DEBUG_READ(("Melding newley retrieved block with bigger one. New size is %i\n", size+z)); | |
3936 buf3 = (char*) realloc(buf3, size+z+1); //plus one so that we can null terminate it later | |
3937 DEBUG_READ(("Doing copy. Start pos is %i, length is %i\n", size, z)); | |
3938 memcpy(&(buf3[size]), buf2, z); | |
3939 size += z; | |
3940 y++; | |
3941 } | |
3942 free(*buf); | |
3943 if (buf2) free(buf2); | |
3944 if (!buf3) { | |
3945 // this can happen if count == 0. We should create an empty buffer so we don't | |
3946 // confuse any clients | |
3947 buf3 = (char*) xmalloc(1); | |
3948 } | |
3949 *buf = buf3; | |
3950 } else if (do_enc && pf->encryption) | |
3951 _pst_decrypt(*buf, size, pf->encryption); | |
3952 | |
3953 (*buf)[size] = '\0'; //should be byte after last one read | |
3954 fseek(pf->fp, fpos, SEEK_SET); | |
3955 DEBUG_RET(); | |
3956 return size; | |
16 | 3957 } |
3958 | |
3959 | |
3960 int32_t _pst_decrypt(unsigned char *buf, size_t size, int32_t type) { | |
43 | 3961 size_t x = 0; |
3962 unsigned char y; | |
3963 DEBUG_ENT("_pst_decrypt"); | |
3964 if (!buf) { | |
3965 DEBUG_RET(); | |
3966 return -1; | |
3967 } | |
3968 | |
3969 if (type == PST_COMP_ENCRYPT) { | |
3970 x = 0; | |
3971 while (x < size) { | |
3972 y = buf[x]; | |
3973 DEBUG_DECRYPT(("Transposing %#hhx to %#hhx [%#x]\n", buf[x], comp_enc[y], y)); | |
3974 buf[x] = comp_enc[y]; // transpose from encrypt array | |
3975 x++; | |
3976 } | |
3977 } else { | |
3978 WARN(("Unknown encryption: %i. Cannot decrypt\n", type)); | |
3979 DEBUG_RET(); | |
3980 return -1; | |
3981 } | |
3982 DEBUG_RET(); | |
3983 return 0; | |
16 | 3984 } |
3985 | |
3986 | |
43 | 3987 int64_t _getIntAt(char *buf) { |
3988 int64_t buf64; | |
3989 int32_t buf32; | |
3990 if (do_read64) { | |
3991 memcpy(&buf64, buf, sizeof(buf64)); | |
3992 LE64_CPU(buf64); | |
3993 return buf64; | |
3994 } | |
3995 else { | |
3996 memcpy(&buf32, buf, sizeof(buf32)); | |
3997 LE32_CPU(buf32); | |
3998 return buf32; | |
3999 } | |
4000 } | |
4001 | |
4002 | |
4003 int64_t _pst_getIntAtPos(FILE *fp, off_t pos ) { | |
4004 int64_t buf64; | |
4005 int32_t buf32; | |
4006 if (do_read64) { | |
4007 _pst_getAtPos(fp, pos, &buf64, sizeof(buf64)); | |
4008 LE64_CPU(buf64); | |
4009 return buf64; | |
4010 } | |
4011 else { | |
4012 _pst_getAtPos(fp, pos, &buf32, sizeof(buf32)); | |
4013 LE32_CPU(buf32); | |
4014 return buf32; | |
4015 } | |
16 | 4016 } |
4017 | |
4018 | |
43 | 4019 int32_t _pst_getAtPos(FILE *fp, off_t pos, void* buf, uint32_t size) { |
4020 DEBUG_ENT("_pst_getAtPos"); | |
4021 if (fseek(fp, pos, SEEK_SET) == -1) { | |
4022 DEBUG_RET(); | |
4023 return 1; | |
4024 } | |
4025 if (fread(buf, 1, size, fp) < size) { | |
4026 DEBUG_RET(); | |
4027 return 2; | |
4028 } | |
4029 DEBUG_RET(); | |
4030 return 0; | |
16 | 4031 } |
4032 | |
4033 | |
43 | 4034 int32_t _pst_get (FILE *fp, void *buf, uint32_t size) { |
4035 DEBUG_ENT("_pst_get"); | |
4036 if (fread(buf, 1, size, fp) < size) { | |
4037 DEBUG_RET(); | |
4038 return 1; | |
4039 } | |
4040 DEBUG_RET(); | |
4041 return 0; | |
16 | 4042 } |
4043 | |
4044 | |
43 | 4045 size_t _pst_ff_getIDblock_dec(pst_file *pf, uint32_t id, unsigned char **b) { |
4046 size_t r; | |
4047 DEBUG_ENT("_pst_ff_getIDblock_dec"); | |
4048 DEBUG_INDEX(("for id %#x\n", id)); | |
4049 r = _pst_ff_getIDblock(pf, id, b); | |
4050 int noenc = (id & 2); // disable encryption | |
4051 if ((pf->encryption) & !(noenc)) { | |
4052 _pst_decrypt(*b, r, pf->encryption); | |
4053 } | |
4054 DEBUG_HEXDUMPC(*b, r, 16); | |
4055 DEBUG_RET(); | |
4056 return r; | |
4057 } | |
4058 | |
4059 | |
4060 size_t _pst_ff_getIDblock(pst_file *pf, uint32_t id, unsigned char** b) { | |
4061 pst_index_ll *rec; | |
4062 size_t rsize = 0;//, re_size=0; | |
4063 DEBUG_ENT("_pst_ff_getIDblock"); | |
4064 if ((rec = _pst_getID(pf, id)) == NULL) { | |
4065 DEBUG_INDEX(("Cannot find ID %#x\n", id)); | |
4066 DEBUG_RET(); | |
4067 return 0; | |
4068 } | |
4069 fseek(pf->fp, rec->offset, SEEK_SET); | |
4070 if (*b) { | |
4071 DEBUG_INDEX(("freeing old memory in b\n")); | |
4072 free(*b); | |
4073 } | |
4074 | |
4075 DEBUG_INDEX(("id = %#x, record size = %#x, offset = %#x\n", id, rec->size, rec->offset)); | |
4076 *b = (char*) xmalloc(rec->size+1); | |
4077 rsize = fread(*b, 1, rec->size, pf->fp); | |
4078 if (rsize != rec->size) { | |
4079 DEBUG_WARN(("Didn't read all the size. fread returned less [%i instead of %i]\n", rsize, rec->size)); | |
4080 if (feof(pf->fp)) { | |
4081 DEBUG_WARN(("We tried to read past the end of the file [offset %#x, size %#x]\n", rec->offset, rec->size)); | |
4082 } else if (ferror(pf->fp)) { | |
4083 DEBUG_WARN(("Some error occured on the file stream\n")); | |
4084 } else { | |
4085 DEBUG_WARN(("No error has been set on the file stream\n")); | |
4086 } | |
4087 } | |
4088 DEBUG_RET(); | |
4089 return rsize; | |
16 | 4090 } |
4091 | |
4092 | |
4093 #define PST_PTR_BLOCK_SIZE 0x120 | |
43 | 4094 size_t _pst_ff_getID2block(pst_file *pf, uint32_t id2, pst_index2_ll *id2_head, unsigned char** buf) { |
4095 pst_index_ll* ptr; | |
4096 // size_t ret; | |
4097 struct holder h = {buf, NULL, 0, "", 0}; | |
4098 DEBUG_ENT("_pst_ff_getID2block"); | |
4099 ptr = _pst_getID2(id2_head, id2); | |
4100 | |
4101 if (!ptr) { | |
4102 DEBUG_INDEX(("Cannot find id2 value %#x\n", id2)); | |
4103 DEBUG_RET(); | |
4104 return 0; | |
4105 } | |
4106 DEBUG_RET(); | |
4107 return _pst_ff_getID2data(pf, ptr, &h); | |
16 | 4108 } |
4109 | |
4110 | |
4111 size_t _pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, struct holder *h) { | |
43 | 4112 int32_t ret; |
4113 unsigned char *b = NULL, *t; | |
4114 DEBUG_ENT("_pst_ff_getID2data"); | |
4115 if (!(ptr->id & 0x02)) { | |
4116 ret = _pst_ff_getIDblock_dec(pf, ptr->id, &b); | |
4117 if (h->buf) { | |
4118 *(h->buf) = b; | |
4119 } else if ((h->base64 == 1) && h->fp) { | |
4120 t = base64_encode(b, ret); | |
4121 if (t) { | |
4122 pst_fwrite(t, 1, strlen(t), h->fp); | |
4123 free(t); // caught by valgrind | |
4124 } | |
4125 free(b); | |
4126 } else if (h->fp) { | |
4127 pst_fwrite(b, 1, ret, h->fp); | |
4128 free(b); | |
4129 } | |
4130 } else { | |
4131 // here we will assume it is a block that points to others | |
4132 DEBUG_READ(("Assuming it is a multi-block record because of it's id\n")); | |
4133 ret = _pst_ff_compile_ID(pf, ptr->id, h, 0); | |
4134 } | |
4135 if (h->buf && *h->buf) | |
4136 (*(h->buf))[ret]='\0'; | |
4137 DEBUG_RET(); | |
4138 return ret; | |
16 | 4139 } |
4140 | |
4141 | |
43 | 4142 size_t _pst_ff_compile_ID(pst_file *pf, uint32_t id, struct holder *h, int32_t size) { |
4143 size_t z, a; | |
4144 uint16_t count, y; | |
4145 uint32_t x, b; | |
4146 unsigned char * buf3 = NULL, *buf2 = NULL, *t; | |
4147 unsigned char fdepth; | |
4148 | |
4149 DEBUG_ENT("_pst_ff_compile_ID"); | |
4150 a = _pst_ff_getIDblock(pf, id, &buf3); | |
4151 if (!a) { | |
4152 if (buf3) free(buf3); | |
4153 return 0; | |
4154 } | |
4155 if ((buf3[0] != 0x1)) { // if bit 8 is set) { | |
4156 // if ((buf3)[0] != 0x1 && (buf3)[1] > 4) { | |
4157 DEBUG_WARN(("WARNING: buffer doesn't start with 0x1, but I expected it to or doesn't have it's two-bit set!\n")); | |
4158 DEBUG_WARN(("Treating as normal buffer\n")); | |
4159 if (pf->encryption) _pst_decrypt(buf3, a, pf->encryption); | |
4160 if (h->buf) | |
4161 *(h->buf) = buf3; | |
4162 else if (h->base64 == 1 && h->fp) { | |
4163 t = base64_encode(buf3, a); | |
4164 if (t) { | |
4165 pst_fwrite(t, 1, strlen(t), h->fp); | |
4166 free(t); // caught by valgrind | |
4167 } | |
4168 free(buf3); | |
4169 } else if (h->fp) { | |
4170 pst_fwrite(buf3, 1, a, h->fp); | |
4171 free(buf3); | |
4172 } | |
4173 DEBUG_RET(); | |
4174 return a; | |
4175 } | |
4176 memcpy (&count, &(buf3[2]), sizeof(int16_t)); | |
4177 LE16_CPU(count); | |
4178 memcpy (&fdepth, &(buf3[1]), sizeof(char)); | |
4179 DEBUG_READ(("Seen index to blocks. Depth is %i\n", fdepth)); | |
4180 DEBUG_READ(("There are %i ids here\n", count)); | |
4181 | |
4182 y = 0; | |
4183 while (y < count) { | |
4184 memcpy(&x, &buf3[0x08+(y*4)], sizeof(int32_t)); | |
4185 LE32_CPU(x); | |
4186 if (fdepth == 0x1) { | |
4187 if ((z = _pst_ff_getIDblock(pf, x, &buf2)) == 0) { | |
4188 DEBUG_WARN(("call to getIDblock returned zero %i\n", z)); | |
4189 if (buf2) free(buf2); | |
4190 free(buf3); | |
4191 return z; | |
4192 } | |
4193 if (pf->encryption) _pst_decrypt(buf2, z, pf->encryption); | |
4194 if (h->buf) { | |
4195 *(h->buf) = realloc(*(h->buf), size+z+1); | |
4196 DEBUG_READ(("appending read data of size %i onto main buffer from pos %i\n", z, size)); | |
4197 memcpy(&((*(h->buf))[size]), buf2, z); | |
4198 } | |
4199 else if ((h->base64 == 1) && h->fp) { | |
4200 // include any byte left over from the last one encoding | |
4201 buf2 = (char*)realloc(buf2, z+h->base64_extra); | |
4202 memmove(buf2+h->base64_extra, buf2, z); | |
4203 memcpy(buf2, h->base64_extra_chars, h->base64_extra); | |
4204 z+= h->base64_extra; | |
4205 | |
4206 b = z % 3; // find out how many bytes will be left over after the encoding. | |
4207 // and save them | |
4208 memcpy(h->base64_extra_chars, &(buf2[z-b]), b); | |
4209 h->base64_extra = b; | |
4210 t = base64_encode(buf2, z-b); | |
4211 if (t) { | |
4212 DEBUG_READ(("writing %i bytes to file as base64 [%i]. Currently %i\n", z, strlen(t), size)); | |
4213 pst_fwrite(t, 1, strlen(t), h->fp); | |
4214 free(t); // caught by valgrind | |
4215 } | |
4216 } | |
4217 else if (h->fp) { | |
4218 DEBUG_READ(("writing %i bytes to file. Currently %i\n", z, size)); | |
4219 pst_fwrite(buf2, 1, z, h->fp); | |
4220 } | |
4221 size += z; | |
4222 y++; | |
4223 } | |
4224 else { | |
4225 if ((z = _pst_ff_compile_ID(pf, x, h, size)) == 0) { | |
4226 DEBUG_WARN(("recursive called returned zero %i\n", z)); | |
4227 free(buf3); | |
4228 DEBUG_RET(); | |
4229 return z; | |
4230 } | |
4231 size = z; | |
4232 y++; | |
4233 } | |
4234 } | |
4235 free(buf3); | |
4236 if (buf2) free(buf2); | |
4237 DEBUG_RET(); | |
4238 return size; | |
16 | 4239 } |
4240 | |
4241 | |
4242 #ifdef _MSC_VER | |
4243 char * fileTimeToAscii(const FILETIME* filetime) { | |
43 | 4244 time_t t; |
4245 DEBUG_ENT("fileTimeToAscii"); | |
4246 t = fileTimeToUnixTime(filetime, 0); | |
4247 if (t == -1) | |
4248 DEBUG_WARN(("ERROR time_t varible that was produced, is -1\n")); | |
4249 DEBUG_RET(); | |
4250 return ctime(&t); | |
16 | 4251 } |
4252 | |
4253 | |
4254 time_t fileTimeToUnixTime(const FILETIME* filetime, DWORD *x) { | |
43 | 4255 SYSTEMTIME s; |
4256 struct tm t; | |
4257 DEBUG_ENT("fileTimeToUnixTime"); | |
4258 memset (&t, 0, sizeof(struct tm)); | |
4259 FileTimeToSystemTime(filetime, &s); | |
4260 t.tm_year = s.wYear-1900; // this is what is required | |
4261 t.tm_mon = s.wMonth-1; // also required! It made me a bit confused | |
4262 t.tm_mday = s.wDay; | |
4263 t.tm_hour = s.wHour; | |
4264 t.tm_min = s.wMinute; | |
4265 t.tm_sec = s.wSecond; | |
4266 DEBUG_RET(); | |
4267 return mktime(&t); | |
16 | 4268 } |
4269 | |
4270 | |
4271 struct tm * fileTimeToStructTM (const FILETIME *filetime) { | |
43 | 4272 time_t t1; |
4273 t1 = fileTimeToUnixTime(filetime, 0); | |
4274 return gmtime(&t1); | |
16 | 4275 } |
4276 | |
4277 | |
4278 #endif //_MSC_VER | |
4279 | |
4280 int32_t pst_stricmp(char *a, char *b) { | |
43 | 4281 // compare strings case-insensitive. |
4282 // returns -1 if a < b, 0 if a==b, 1 if a > b | |
4283 while(*a != '\0' && *b != '\0' && toupper(*a)==toupper(*b)) { | |
4284 a++; b++; | |
4285 } | |
4286 if (toupper(*a) == toupper(*b)) | |
4287 return 0; | |
4288 else if (toupper(*a) < toupper(*b)) | |
4289 return -1; | |
4290 else | |
4291 return 1; | |
16 | 4292 } |
4293 | |
4294 | |
4295 int32_t pst_strincmp(char *a, char *b, int32_t x) { | |
43 | 4296 // compare upto x chars in string a and b case-insensitively |
4297 // returns -1 if a < b, 0 if a==b, 1 if a > b | |
4298 int32_t y = 0; | |
4299 while (*a != '\0' && *b != '\0' && y < x && toupper(*a)==toupper(*b)) { | |
4300 a++; b++; y++; | |
4301 } | |
4302 // if we have reached the end of either string, or a and b still match | |
4303 if (*a == '\0' || *b == '\0' || toupper(*a)==toupper(*b)) | |
4304 return 0; | |
4305 else if (toupper(*a) < toupper(*b)) | |
4306 return -1; | |
4307 else | |
4308 return 1; | |
16 | 4309 } |
4310 | |
4311 | |
4312 size_t pst_fwrite(const void*ptr, size_t size, size_t nmemb, FILE*stream) { | |
43 | 4313 size_t r; |
4314 DEBUG_ENT("pst_fwrite"); | |
4315 if (ptr) | |
4316 r = fwrite(ptr, size, nmemb, stream); | |
4317 else { | |
4318 r = 0; | |
4319 DEBUG_WARN(("An attempt to write a NULL Pointer was made\n")); | |
4320 } | |
4321 DEBUG_RET(); | |
4322 return r; | |
16 | 4323 } |
4324 | |
4325 | |
4326 char * _pst_wide_to_single(char *wt, int32_t size) { | |
43 | 4327 // returns the first byte of each wide char. the size is the number of bytes in source |
4328 char *x, *y; | |
4329 DEBUG_ENT("_pst_wide_to_single"); | |
4330 x = xmalloc((size/2)+1); | |
4331 y = x; | |
4332 while (size != 0 && *wt != '\0') { | |
4333 *y = *wt; | |
4334 wt+=2; | |
4335 size -= 2; | |
4336 y++; | |
4337 } | |
4338 *y = '\0'; | |
4339 DEBUG_RET(); | |
4340 return x; | |
16 | 4341 } |
4342 | |
43 | 4343 |
4344 char *pst_rfc2426_escape(char *str) { | |
4345 static char* buf = NULL; | |
4346 char *ret, *a, *b; | |
4347 int x = 0, y, z; | |
4348 DEBUG_ENT("rfc2426_escape"); | |
4349 if (!str) | |
4350 ret = str; | |
4351 else { | |
4352 | |
4353 // calculate space required to escape all the following characters | |
4354 y = pst_chr_count(str, ',') | |
4355 + pst_chr_count(str, '\\') | |
4356 + pst_chr_count(str, ';') | |
4357 + pst_chr_count(str, '\n'); | |
4358 z = pst_chr_count(str, '\r'); | |
4359 if (y == 0 && z == 0) | |
4360 // there isn't any extra space required | |
4361 ret = str; | |
4362 else { | |
4363 x = strlen(str) + y - z + 1; // don't forget room for the NUL | |
4364 buf = (char*) realloc(buf, x); | |
4365 a = str; | |
4366 b = buf; | |
4367 while (*a != '\0') { | |
4368 switch (*a) { | |
4369 case ',' : | |
4370 case '\\': | |
4371 case ';' : | |
4372 *(b++) = '\\'; | |
4373 *b = *a; | |
4374 break; | |
4375 case '\n': // newlines are encoded as "\n" | |
4376 *(b++) = '\\'; | |
4377 *b = 'n'; | |
4378 break; | |
4379 case '\r': // skip cr | |
4380 b--; | |
4381 break; | |
4382 default: | |
4383 *b=*a; | |
4384 } | |
4385 b++; | |
4386 a++; | |
4387 } | |
4388 *b = '\0'; // NUL-terminate the string (buf) | |
4389 ret = buf; | |
4390 } | |
4391 } | |
4392 DEBUG_RET(); | |
4393 return ret; | |
4394 } | |
4395 | |
4396 | |
4397 int pst_chr_count(char *str, char x) { | |
4398 int r = 0; | |
4399 while (*str != '\0') { | |
4400 if (*str == x) | |
4401 r++; | |
4402 str++; | |
4403 } | |
4404 return r; | |
4405 } | |
4406 | |
4407 | |
4408 char *pst_rfc2425_datetime_format(FILETIME *ft) { | |
4409 static char* buffer = NULL; | |
4410 struct tm *stm = NULL; | |
4411 DEBUG_ENT("rfc2425_datetime_format"); | |
4412 if (!buffer) buffer = malloc(30); // should be enough for the date as defined below | |
4413 stm = fileTimeToStructTM(ft); | |
4414 if (strftime(buffer, 30, "%Y-%m-%dT%H:%M:%SZ", stm)==0) { | |
4415 DEBUG_INFO(("Problem occured formatting date\n")); | |
4416 } | |
4417 DEBUG_RET(); | |
4418 return buffer; | |
4419 } | |
4420 | |
4421 | |
4422 char *pst_rfc2445_datetime_format(FILETIME *ft) { | |
4423 static char* buffer = NULL; | |
4424 struct tm *stm = NULL; | |
4425 DEBUG_ENT("rfc2445_datetime_format"); | |
4426 if (!buffer) buffer = malloc(30); // should be enough for the date as defined below | |
4427 stm = fileTimeToStructTM(ft); | |
4428 if (strftime(buffer, 30, "%Y%m%dT%H%M%SZ", stm)==0) { | |
4429 DEBUG_INFO(("Problem occured formatting date\n")); | |
4430 } | |
4431 DEBUG_RET(); | |
4432 return buffer; | |
4433 } | |
4434 | |
4435 |