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