Mercurial > libpst
annotate src/libpst.h @ 37:ddfb25318812 stable-0-5-8
more valgrind fixes
author | carl |
---|---|
date | Fri, 10 Aug 2007 08:06:13 -0700 |
parents | 6fe121a971c9 |
children | 2ad7ef0a3c4f |
rev | line source |
---|---|
16 | 1 /*** |
2 * libpst.h | |
3 * Part of LibPST project | |
4 * Written by David Smith | |
5 * dave.s@earthcorp.com | |
6 */ | |
7 // LibPST - Library for Accessing Outlook .pst files | |
8 // Dave Smith - davesmith@users.sourceforge.net | |
9 | |
10 #ifndef LIBPST_H | |
11 #define LIBPST_H | |
12 | |
13 #ifndef _MSC_VER | |
14 | |
15 #ifndef FILETIME_DEFINED | |
16 #define FILETIME_DEFINED | |
17 //Win32 Filetime struct - copied from WINE | |
18 typedef struct { | |
19 u_int32_t dwLowDateTime; | |
20 u_int32_t dwHighDateTime; | |
21 } FILETIME; | |
22 #endif //ifndef FILETIME_DEFINED | |
23 #endif //ifndef _MSC_VER | |
24 | |
25 // define the INT32_MAX here cause it isn't normally defined | |
26 #ifndef INT32_MAX | |
27 # define INT32_MAX INT_MAX | |
28 #endif | |
29 | |
30 // According to Jan Wolter, sys/param.h is the most portable source of endian | |
31 // information on UNIX systems. see http://www.unixpapa.com/incnote/byteorder.html | |
32 #ifdef _MSC_VER | |
33 #define BYTE_ORDER LITTLE_ENDIAN | |
34 #else | |
35 #include <sys/param.h> | |
36 #endif // defined _MSC_VER | |
37 | |
38 #if BYTE_ORDER == BIG_ENDIAN | |
39 # define LE64_CPU(x) \ | |
40 x = ((((x) & 0xff00000000000000) >> 56) | \ | |
41 (((x) & 0x00ff000000000000) >> 40) | \ | |
42 (((x) & 0x0000ff0000000000) >> 24) | \ | |
43 (((x) & 0x000000ff00000000) >> 8 ) | \ | |
44 (((x) & 0x00000000ff000000) << 8 ) | \ | |
45 (((x) & 0x0000000000ff0000) << 24) | \ | |
46 (((x) & 0x000000000000ff00) << 40) | \ | |
47 (((x) & 0x00000000000000ff) << 56)); | |
48 # define LE32_CPU(x) \ | |
49 x = ((((x) & 0xff000000) >> 24) | \ | |
50 (((x) & 0x00ff0000) >> 8 ) | \ | |
51 (((x) & 0x0000ff00) << 8 ) | \ | |
52 (((x) & 0x000000ff) << 24)); | |
53 # define LE16_CPU(x) \ | |
54 x = ((((x) & 0xff00) >> 8) | \ | |
55 (((x) & 0x00ff) << 8)); | |
56 #elif BYTE_ORDER == LITTLE_ENDIAN | |
57 # define LE64_CPU(x) {} | |
58 # define LE32_CPU(x) {} | |
59 # define LE16_CPU(x) {} | |
60 #else | |
61 # error "Byte order not supported by this library" | |
62 #endif // BYTE_ORDER | |
63 | |
64 | |
65 #ifdef _MSC_VER | |
66 #include "windows.h" | |
67 #define int32_t int | |
68 #define u_int32_t unsigned int | |
69 #define int16_t short int | |
70 #define u_int16_t unsigned short int | |
71 #endif // _MSC_VER | |
72 | |
73 #define PST_TYPE_NOTE 1 | |
74 #define PST_TYPE_APPOINTMENT 8 | |
75 #define PST_TYPE_CONTACT 9 | |
76 #define PST_TYPE_JOURNAL 10 | |
77 #define PST_TYPE_STICKYNOTE 11 | |
78 #define PST_TYPE_TASK 12 | |
79 #define PST_TYPE_OTHER 13 | |
80 #define PST_TYPE_REPORT 14 | |
81 | |
82 // defines whether decryption is done on this bit of data | |
83 #define PST_NO_ENC 0 | |
84 #define PST_ENC 1 | |
85 | |
86 // defines types of possible encryption | |
87 #define PST_NO_ENCRYPT 0 | |
88 #define PST_COMP_ENCRYPT 1 | |
89 #define PST_ENCRYPT 2 | |
90 | |
91 // defines different types of mappings | |
92 #define PST_MAP_ATTRIB 1 | |
93 #define PST_MAP_HEADER 2 | |
94 | |
95 // define my custom email attributes. | |
96 #define PST_ATTRIB_HEADER -1 | |
97 | |
98 // defines types of free/busy values for appointment->showas | |
99 #define PST_FREEBUSY_FREE 0 | |
100 #define PST_FREEBUSY_TENTATIVE 1 | |
101 #define PST_FREEBUSY_BUSY 2 | |
102 #define PST_FREEBUSY_OUT_OF_OFFICE 3 | |
103 | |
104 // defines labels for appointment->label | |
105 #define PST_APP_LABEL_NONE 0 // None | |
106 #define PST_APP_LABEL_IMPORTANT 1 // Important | |
107 #define PST_APP_LABEL_BUSINESS 2 // Business | |
108 #define PST_APP_LABEL_PERSONAL 3 // Personal | |
109 #define PST_APP_LABEL_VACATION 4 // Vacation | |
110 #define PST_APP_LABEL_MUST_ATTEND 5 // Must Attend | |
111 #define PST_APP_LABEL_TRAVEL_REQ 6 // Travel Required | |
112 #define PST_APP_LABEL_NEEDS_PREP 7 // Needs Preparation | |
113 #define PST_APP_LABEL_BIRTHDAY 8 // Birthday | |
114 #define PST_APP_LABEL_ANNIVERSARY 9 // Anniversary | |
115 #define PST_APP_LABEL_PHONE_CALL 10// Phone Call | |
116 | |
117 typedef struct _pst_misc_6_struct { | |
118 int32_t i1; | |
119 int32_t i2; | |
120 int32_t i3; | |
121 int32_t i4; | |
122 int32_t i5; | |
123 int32_t i6; | |
124 } pst_misc_6; | |
125 | |
126 typedef struct _pst_entryid_struct { | |
127 int32_t u1; | |
128 char entryid[16]; | |
35 | 129 u_int32_t id; |
16 | 130 } pst_entryid; |
131 | |
132 typedef struct _pst_desc_struct { | |
133 u_int32_t d_id; | |
134 u_int32_t desc_id; | |
135 u_int32_t list_id; | |
136 u_int32_t parent_id; | |
137 } pst_desc; | |
138 | |
139 typedef struct _pst_index_struct{ | |
140 u_int32_t id; | |
141 int32_t offset; | |
142 u_int16_t size; | |
143 int16_t u1; | |
144 } pst_index; | |
145 | |
146 typedef struct _pst_index_tree { | |
147 u_int32_t id; | |
148 int32_t offset; | |
149 size_t size; | |
150 int32_t u1; | |
151 struct _pst_index_tree * next; | |
152 } pst_index_ll; | |
153 | |
154 typedef struct _pst_index2_tree { | |
35 | 155 u_int32_t id2; |
16 | 156 pst_index_ll *id; |
157 struct _pst_index2_tree * next; | |
158 } pst_index2_ll; | |
159 | |
160 typedef struct _pst_desc_tree { | |
161 u_int32_t id; | |
162 pst_index_ll * list_index; | |
163 pst_index_ll * desc; | |
164 int32_t no_child; | |
165 struct _pst_desc_tree * prev; | |
166 struct _pst_desc_tree * next; | |
167 struct _pst_desc_tree * parent; | |
168 struct _pst_desc_tree * child; | |
169 struct _pst_desc_tree * child_tail; | |
170 } pst_desc_ll; | |
171 | |
172 typedef struct _pst_item_email_subject { | |
173 int32_t off1; | |
174 int32_t off2; | |
175 char *subj; | |
176 } pst_item_email_subject; | |
177 | |
178 typedef struct _pst_item_email { | |
179 FILETIME *arrival_date; | |
180 int32_t autoforward; // 1 = true, 0 = not set, -1 = false | |
181 char *body; | |
182 char *cc_address; | |
183 char *common_name; | |
184 int32_t conv_index; | |
185 int32_t conversion_prohib; | |
186 int32_t delete_after_submit; // 1 = true, 0 = false | |
187 int32_t delivery_report; // 1 = true, 0 = false | |
188 char *encrypted_body; | |
189 int32_t encrypted_body_size; | |
190 char *encrypted_htmlbody; | |
191 int32_t encrypted_htmlbody_size; | |
192 int32_t flag; | |
193 char *header; | |
194 char *htmlbody; | |
195 int32_t importance; | |
196 char *in_reply_to; | |
197 int32_t message_cc_me; // 1 = true, 0 = false | |
198 int32_t message_recip_me; // 1 = true, 0 = false | |
199 int32_t message_to_me; // 1 = true, 0 = false | |
200 char *messageid; | |
201 int32_t orig_sensitivity; | |
202 char *outlook_recipient; | |
203 char *outlook_recipient2; | |
204 char *outlook_sender; | |
205 char *outlook_sender_name; | |
206 char *outlook_sender2; | |
207 int32_t priority; | |
208 char *proc_subject; | |
209 int32_t read_receipt; | |
210 char *recip_access; | |
211 char *recip_address; | |
212 char *recip2_access; | |
213 char *recip2_address; | |
214 int32_t reply_requested; | |
215 char *reply_to; | |
216 char *return_path_address; | |
217 int32_t rtf_body_char_count; | |
218 int32_t rtf_body_crc; | |
219 char *rtf_body_tag; | |
220 char *rtf_compressed; | |
221 int32_t rtf_in_sync; // 1 = true, 0 = doesn't exist, -1 = false | |
222 int32_t rtf_ws_prefix_count; | |
223 int32_t rtf_ws_trailing_count; | |
224 char *sender_access; | |
225 char *sender_address; | |
226 char *sender2_access; | |
227 char *sender2_address; | |
228 int32_t sensitivity; | |
229 FILETIME *sent_date; | |
230 pst_entryid *sentmail_folder; | |
231 char *sentto_address; | |
232 pst_item_email_subject *subject; | |
233 } pst_item_email; | |
234 | |
235 typedef struct _pst_item_folder { | |
236 int32_t email_count; | |
237 int32_t unseen_email_count; | |
238 int32_t assoc_count; | |
239 char subfolder; | |
240 } pst_item_folder; | |
241 | |
242 typedef struct _pst_item_message_store { | |
243 pst_entryid *deleted_items_folder; | |
244 pst_entryid *search_root_folder; | |
245 pst_entryid *top_of_personal_folder; | |
246 pst_entryid *top_of_folder; | |
247 int32_t valid_mask; // what folders the message store contains | |
248 int32_t pwd_chksum; | |
249 } pst_item_message_store; | |
250 | |
251 typedef struct _pst_item_contact { | |
252 char *access_method; | |
253 char *account_name; | |
254 char *address1; | |
255 char *address1a; | |
256 char *address1_desc; | |
257 char *address1_transport; | |
258 char *address2; | |
259 char *address2a; | |
260 char *address2_desc; | |
261 char *address2_transport; | |
262 char *address3; | |
263 char *address3a; | |
264 char *address3_desc; | |
265 char *address3_transport; | |
266 char *assistant_name; | |
267 char *assistant_phone; | |
268 char *billing_information; | |
269 FILETIME *birthday; | |
270 char *business_address; | |
271 char *business_city; | |
272 char *business_country; | |
273 char *business_fax; | |
274 char *business_homepage; | |
275 char *business_phone; | |
276 char *business_phone2; | |
277 char *business_po_box; | |
278 char *business_postal_code; | |
279 char *business_state; | |
280 char *business_street; | |
281 char *callback_phone; | |
282 char *car_phone; | |
283 char *company_main_phone; | |
284 char *company_name; | |
285 char *computer_name; | |
286 char *customer_id; | |
287 char *def_postal_address; | |
288 char *department; | |
289 char *display_name_prefix; | |
290 char *first_name; | |
291 char *followup; | |
292 char *free_busy_address; | |
293 char *ftp_site; | |
294 char *fullname; | |
295 int32_t gender; | |
296 char *gov_id; | |
297 char *hobbies; | |
298 char *home_address; | |
299 char *home_city; | |
300 char *home_country; | |
301 char *home_fax; | |
302 char *home_phone; | |
303 char *home_phone2; | |
304 char *home_po_box; | |
305 char *home_postal_code; | |
306 char *home_state; | |
307 char *home_street; | |
308 char *initials; | |
309 char *isdn_phone; | |
310 char *job_title; | |
311 char *keyword; | |
312 char *language; | |
313 char *location; | |
314 int32_t mail_permission; | |
315 char *manager_name; | |
316 char *middle_name; | |
317 char *mileage; | |
318 char *mobile_phone; | |
319 char *nickname; | |
320 char *office_loc; | |
321 char *org_id; | |
322 char *other_address; | |
323 char *other_city; | |
324 char *other_country; | |
325 char *other_phone; | |
326 char *other_po_box; | |
327 char *other_postal_code; | |
328 char *other_state; | |
329 char *other_street; | |
330 char *pager_phone; | |
331 char *personal_homepage; | |
332 char *pref_name; | |
333 char *primary_fax; | |
334 char *primary_phone; | |
335 char *profession; | |
336 char *radio_phone; | |
337 int32_t rich_text; | |
338 char *spouse_name; | |
339 char *suffix; | |
340 char *surname; | |
341 char *telex; | |
342 char *transmittable_display_name; | |
343 char *ttytdd_phone; | |
344 FILETIME *wedding_anniversary; | |
345 } pst_item_contact; | |
346 | |
347 typedef struct _pst_item_attach { | |
348 char *filename1; | |
349 char *filename2; | |
350 char *mimetype; | |
351 char *data; | |
36 | 352 size_t size; |
16 | 353 int32_t id2_val; |
354 int32_t id_val; // calculated from id2_val during creation of record | |
355 int32_t method; | |
356 int32_t position; | |
357 int32_t sequence; | |
358 struct _pst_item_attach *next; | |
359 } pst_item_attach; | |
360 | |
361 typedef struct _pst_item_extra_field { | |
362 char *field_name; | |
363 char *value; | |
364 struct _pst_item_extra_field *next; | |
365 } pst_item_extra_field; | |
366 | |
367 typedef struct _pst_item_journal { | |
368 FILETIME *end; | |
369 FILETIME *start; | |
370 char *type; | |
371 } pst_item_journal; | |
372 | |
373 typedef struct _pst_item_appointment { | |
374 FILETIME *end; | |
375 char *location; | |
376 FILETIME *reminder; | |
377 FILETIME *start; | |
378 char *timezonestring; | |
379 int32_t showas; | |
380 int32_t label; | |
31 | 381 int32_t all_day; |
16 | 382 } pst_item_appointment; |
383 | |
384 typedef struct _pst_item { | |
385 struct _pst_item_email *email; // data reffering to email | |
386 struct _pst_item_folder *folder; // data reffering to folder | |
387 struct _pst_item_contact *contact; // data reffering to contact | |
388 struct _pst_item_attach *attach; // linked list of attachments | |
389 struct _pst_item_message_store * message_store; // data referring to the message store | |
390 struct _pst_item_extra_field *extra_fields; // linked list of extra headers and such | |
391 struct _pst_item_journal *journal; // data reffering to a journal entry | |
392 struct _pst_item_appointment *appointment; // data reffering to a calendar entry | |
393 int32_t type; | |
394 char *ascii_type; | |
395 char *file_as; | |
396 char *comment; | |
397 int32_t message_size; | |
398 char *outlook_version; | |
399 char *record_key; // probably 16 bytes long. | |
400 size_t record_key_size; | |
401 int32_t response_requested; | |
402 FILETIME *create_date; | |
403 FILETIME *modify_date; | |
404 int32_t private_member; | |
405 } pst_item; | |
406 | |
407 typedef struct _pst_x_attrib_ll { | |
408 int32_t type; | |
409 int32_t mytype; | |
410 int32_t map; | |
411 void *data; | |
412 struct _pst_x_attrib_ll *next; | |
413 } pst_x_attrib_ll; | |
414 | |
415 typedef struct _pst_file { | |
416 pst_index_ll *i_head, *i_tail; | |
417 pst_index2_ll *i2_head; | |
418 pst_desc_ll *d_head, *d_tail; | |
419 pst_x_attrib_ll *x_head; | |
420 int32_t index1; | |
421 int32_t index1_count; | |
422 int32_t index2; | |
423 int32_t index2_count; | |
31 | 424 FILE * fp; // file pointer to opened PST file |
425 size_t size; // pst file size | |
426 unsigned char encryption; // pst encryption setting | |
427 unsigned char ind_type; // pst index type | |
16 | 428 } pst_file; |
429 | |
430 typedef struct _pst_block_offset { | |
431 int16_t from; | |
432 int16_t to; | |
433 } pst_block_offset; | |
434 | |
35 | 435 typedef struct _pst_block_offset_pointer { |
436 unsigned char *from; | |
437 unsigned char *to; | |
438 int needfree; | |
439 } pst_block_offset_pointer; | |
440 | |
16 | 441 struct _pst_num_item { |
35 | 442 u_int32_t id; |
16 | 443 unsigned char *data; |
444 int32_t type; | |
445 size_t size; | |
446 char *extra; | |
447 }; | |
448 | |
449 typedef struct _pst_num_array { | |
450 int32_t count_item; | |
451 int32_t count_array; | |
452 struct _pst_num_item ** items; | |
453 struct _pst_num_array *next; | |
454 } pst_num_array; | |
455 | |
456 struct holder { | |
457 unsigned char **buf; | |
458 FILE * fp; | |
459 int32_t base64; | |
460 char base64_extra_chars[3]; | |
461 int32_t base64_extra; | |
462 }; | |
463 | |
464 // prototypes | |
465 int32_t pst_open(pst_file *pf, char *name, char *mode); | |
466 int32_t pst_close(pst_file *pf); | |
467 pst_desc_ll * pst_getTopOfFolders(pst_file *pf, pst_item *root); | |
468 int32_t pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, unsigned char **b); | |
469 int32_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp); | |
470 int32_t pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp); | |
471 int32_t pst_load_index (pst_file *pf); | |
472 pst_desc_ll* pst_getNextDptr(pst_desc_ll* d); | |
473 int32_t pst_load_extended_attributes(pst_file *pf); | |
474 | |
34
07177825c91b
fix signed/unsigned to allow very small pst files with only leaf nodes
carl
parents:
31
diff
changeset
|
475 int32_t _pst_build_id_ptr(pst_file *pf, int32_t offset, int32_t depth, int32_t linku1, u_int32_t start_val, u_int32_t end_val); |
35 | 476 int32_t _pst_build_desc_ptr (pst_file *pf, int32_t offset, int32_t depth, int32_t linku1, u_int32_t *high_id, u_int32_t start_id, u_int32_t end_val); |
16 | 477 pst_item* _pst_getItem(pst_file *pf, pst_desc_ll *d_ptr); |
478 void * _pst_parse_item (pst_file *pf, pst_desc_ll *d_ptr); | |
479 pst_num_array * _pst_parse_block(pst_file *pf, u_int32_t block_id, pst_index2_ll *i2_head); | |
480 int32_t _pst_process(pst_num_array *list, pst_item *item); | |
481 int32_t _pst_free_list(pst_num_array *list); | |
482 void _pst_freeItem(pst_item *item); | |
483 int32_t _pst_free_id2(pst_index2_ll * head); | |
484 int32_t _pst_free_id (pst_index_ll *head); | |
485 int32_t _pst_free_desc (pst_desc_ll *head); | |
486 int32_t _pst_free_xattrib(pst_x_attrib_ll *x); | |
35 | 487 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); |
31 | 488 int32_t _pst_getBlockOffset(unsigned char *buf, int32_t read_size, int32_t i_offset, int32_t offset, pst_block_offset *p); |
16 | 489 pst_index2_ll * _pst_build_id2(pst_file *pf, pst_index_ll* list, pst_index2_ll* head_ptr); |
490 pst_index_ll * _pst_getID(pst_file* pf, u_int32_t id); | |
491 pst_index_ll * _pst_getID2(pst_index2_ll * ptr, u_int32_t id); | |
492 pst_desc_ll * _pst_getDptr(pst_file *pf, u_int32_t id); | |
493 size_t _pst_read_block_size(pst_file *pf, int32_t offset, size_t size, char ** buf, int32_t do_enc, | |
494 unsigned char is_index); | |
495 int32_t _pst_decrypt(unsigned char *buf, size_t size, int32_t type); | |
496 int32_t _pst_getAtPos(FILE *fp, int32_t pos, void* buf, u_int32_t size); | |
497 int32_t _pst_get (FILE *fp, void *buf, u_int32_t size); | |
498 size_t _pst_ff_getIDblock_dec(pst_file *pf, u_int32_t id, unsigned char **b); | |
499 size_t _pst_ff_getIDblock(pst_file *pf, u_int32_t id, unsigned char** b); | |
500 size_t _pst_ff_getID2block(pst_file *pf, u_int32_t id2, pst_index2_ll *id2_head, unsigned char** buf); | |
501 size_t _pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, struct holder *h); | |
502 size_t _pst_ff_compile_ID(pst_file *pf, u_int32_t id, struct holder *h, int32_t size); | |
503 | |
504 int32_t pst_strincmp(char *a, char *b, int32_t x); | |
505 int32_t pst_stricmp(char *a, char *b); | |
506 size_t pst_fwrite(const void*ptr, size_t size, size_t nmemb, FILE*stream); | |
507 char * _pst_wide_to_single(char *wt, int32_t size); | |
508 // DEBUG functions | |
509 int32_t _pst_printDptr(pst_file *pf); | |
510 int32_t _pst_printIDptr(pst_file* pf); | |
511 int32_t _pst_printID2ptr(pst_index2_ll *ptr); | |
512 void * xmalloc(size_t size); | |
513 | |
514 #endif // defined LIBPST_H |