Mercurial > libpst
comparison src/libpst.c @ 176:ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
remove many functions from the interface by making them static.
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 08 Apr 2009 14:13:06 -0700 |
parents | 6954d315aaa8 |
children | b65e8d0a088a |
comparison
equal
deleted
inserted
replaced
175:03dbd449290f | 176:ac6e22c8a9cf |
---|---|
166 0x27, 0x3b, 0xda, 0xba, 0xd7, 0xc2, 0x26, 0xd4, 0x91, 0x1d, 0xd2, 0x1c, 0x22, 0x33, 0xf8, 0xfa, | 166 0x27, 0x3b, 0xda, 0xba, 0xd7, 0xc2, 0x26, 0xd4, 0x91, 0x1d, 0xd2, 0x1c, 0x22, 0x33, 0xf8, 0xfa, |
167 0xf1, 0x5a, 0xef, 0xcf, 0x90, 0xb6, 0x8b, 0xb5, 0xbd, 0xc0, 0xbf, 0x08, 0x97, 0x1e, 0x6c, 0xe2, | 167 0xf1, 0x5a, 0xef, 0xcf, 0x90, 0xb6, 0x8b, 0xb5, 0xbd, 0xc0, 0xbf, 0x08, 0x97, 0x1e, 0x6c, 0xe2, |
168 0x61, 0xe0, 0xc6, 0xc1, 0x59, 0xab, 0xbb, 0x58, 0xde, 0x5f, 0xdf, 0x60, 0x79, 0x7e, 0xb2, 0x8a | 168 0x61, 0xe0, 0xc6, 0xc1, 0x59, 0xab, 0xbb, 0x58, 0xde, 0x5f, 0xdf, 0x60, 0x79, 0x7e, 0xb2, 0x8a |
169 }; | 169 }; |
170 | 170 |
171 static int pst_build_desc_ptr(pst_file *pf, int64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val); | |
172 static pst_id2_ll* pst_build_id2(pst_file *pf, pst_index_ll* list); | |
173 static int pst_build_id_ptr(pst_file *pf, int64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val); | |
174 static int pst_chr_count(char *str, char x); | |
175 static size_t pst_ff_compile_ID(pst_file *pf, uint64_t id, pst_holder *h, size_t size); | |
176 static size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_id2_ll *id2_head, char** buf); | |
177 static size_t pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, pst_holder *h); | |
178 static void pst_free_attach(pst_item_attach *attach); | |
179 static void pst_free_desc (pst_desc_ll *head); | |
180 static void pst_free_id2(pst_id2_ll * head); | |
181 static void pst_free_id (pst_index_ll *head); | |
182 static void pst_free_list(pst_mapi_object *list); | |
183 static void pst_free_xattrib(pst_x_attrib_ll *x); | |
184 static size_t pst_getAtPos(pst_file *pf, int64_t pos, void* buf, size_t size); | |
185 static int pst_getBlockOffsetPointer(pst_file *pf, pst_id2_ll *i2_head, pst_subblocks *subblocks, uint32_t offset, pst_block_offset_pointer *p); | |
186 static int pst_getBlockOffset(char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p); | |
187 static pst_id2_ll* pst_getID2(pst_id2_ll * ptr, uint64_t id); | |
188 static pst_desc_ll* pst_getDptr(pst_file *pf, uint64_t d_id); | |
189 static uint64_t pst_getIntAt(pst_file *pf, char *buf); | |
190 static uint64_t pst_getIntAtPos(pst_file *pf, int64_t pos); | |
191 static pst_mapi_object* pst_parse_block(pst_file *pf, uint64_t block_id, pst_id2_ll *i2_head); | |
192 static void pst_printDptr(pst_file *pf, pst_desc_ll *ptr); | |
193 static void pst_printIDptr(pst_file* pf); | |
194 static void pst_printID2ptr(pst_id2_ll *ptr); | |
195 static int pst_process(pst_mapi_object *list, pst_item *item, pst_item_attach *attach); | |
196 static size_t pst_read_block_size(pst_file *pf, int64_t offset, size_t size, char **buf); | |
197 static int pst_stricmp(char *a, char *b); | |
198 static int pst_strincmp(char *a, char *b, size_t x); | |
199 static char* pst_wide_to_single(char *wt, size_t size); | |
200 | |
201 | |
171 | 202 |
172 int pst_open(pst_file *pf, char *name) { | 203 int pst_open(pst_file *pf, char *name) { |
173 int32_t sig; | 204 int32_t sig; |
174 | 205 |
175 pst_unicode_init(); | 206 pst_unicode_init(); |
399 topnode->desc = NULL; | 430 topnode->desc = NULL; |
400 record_descriptor(pf, topnode); // add to the global tree | 431 record_descriptor(pf, topnode); // add to the global tree |
401 } | 432 } |
402 DEBUG_RET(); | 433 DEBUG_RET(); |
403 return topnode; | 434 return topnode; |
404 } | |
405 | |
406 | |
407 size_t pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, char **b){ | |
408 size_t size=0; | |
409 pst_index_ll *ptr; | |
410 pst_holder h = {b, NULL, 0}; | |
411 DEBUG_ENT("pst_attach_to_mem"); | |
412 if (attach->i_id != (uint64_t)-1) { | |
413 ptr = pst_getID(pf, attach->i_id); | |
414 if (ptr) { | |
415 size = pst_ff_getID2data(pf, ptr, &h); | |
416 } else { | |
417 DEBUG_WARN(("Couldn't find ID pointer. Cannot handle attachment\n")); | |
418 size = 0; | |
419 } | |
420 attach->data.size = size; | |
421 } else { | |
422 size = attach->data.size; | |
423 } | |
424 DEBUG_RET(); | |
425 return size; | |
426 } | 435 } |
427 | 436 |
428 | 437 |
429 size_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp) { | 438 size_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp) { |
430 pst_index_ll *ptr; | 439 pst_index_ll *ptr; |
829 /** Process the index1 b-tree from the pst file and create the | 838 /** Process the index1 b-tree from the pst file and create the |
830 * pf->i_head linked list from it. This tree holds the location | 839 * pf->i_head linked list from it. This tree holds the location |
831 * (offset and size) of lower level objects (0xbcec descriptor | 840 * (offset and size) of lower level objects (0xbcec descriptor |
832 * blocks, etc) in the pst file. | 841 * blocks, etc) in the pst file. |
833 */ | 842 */ |
834 int pst_build_id_ptr(pst_file *pf, int64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val) { | 843 static int pst_build_id_ptr(pst_file *pf, int64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val) { |
835 struct pst_table_ptr_structn table, table2; | 844 struct pst_table_ptr_structn table, table2; |
836 pst_index_ll *i_ptr=NULL; | 845 pst_index_ll *i_ptr=NULL; |
837 pst_index index; | 846 pst_index index; |
838 int32_t x, item_count; | 847 int32_t x, item_count; |
839 uint64_t old = start_val; | 848 uint64_t old = start_val; |
946 | 955 |
947 /** Process the index2 b-tree from the pst file and create the | 956 /** Process the index2 b-tree from the pst file and create the |
948 * pf->d_head tree from it. This tree holds descriptions of the | 957 * pf->d_head tree from it. This tree holds descriptions of the |
949 * higher level objects (email, contact, etc) in the pst file. | 958 * higher level objects (email, contact, etc) in the pst file. |
950 */ | 959 */ |
951 int pst_build_desc_ptr (pst_file *pf, int64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val) { | 960 static int pst_build_desc_ptr (pst_file *pf, int64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val) { |
952 struct pst_table_ptr_structn table, table2; | 961 struct pst_table_ptr_structn table, table2; |
953 pst_descn desc_rec; | 962 pst_descn desc_rec; |
954 int32_t item_count; | 963 int32_t item_count; |
955 uint64_t old = start_val; | 964 uint64_t old = start_val; |
956 int x; | 965 int x; |
1250 /** Process a low level descriptor block (0x0101, 0xbcec, 0x7cec) into a | 1259 /** Process a low level descriptor block (0x0101, 0xbcec, 0x7cec) into a |
1251 * list of MAPI objects, each of which contains a list of MAPI elements. | 1260 * list of MAPI objects, each of which contains a list of MAPI elements. |
1252 * | 1261 * |
1253 * @return list of MAPI objects | 1262 * @return list of MAPI objects |
1254 */ | 1263 */ |
1255 pst_mapi_object * pst_parse_block(pst_file *pf, uint64_t block_id, pst_id2_ll *i2_head) { | 1264 static pst_mapi_object* pst_parse_block(pst_file *pf, uint64_t block_id, pst_id2_ll *i2_head) { |
1256 pst_mapi_object *mo_head = NULL; | 1265 pst_mapi_object *mo_head = NULL; |
1257 char *buf = NULL; | 1266 char *buf = NULL; |
1258 size_t read_size = 0; | 1267 size_t read_size = 0; |
1259 pst_subblocks subblocks; | 1268 pst_subblocks subblocks; |
1260 pst_mapi_object *mo_ptr = NULL; | 1269 pst_mapi_object *mo_ptr = NULL; |
1969 * this is non-null, the length of the this attachment list | 1978 * this is non-null, the length of the this attachment list |
1970 * must be at least as large as the length of the MAPI objects list. | 1979 * must be at least as large as the length of the MAPI objects list. |
1971 * | 1980 * |
1972 * @return 0 for ok, -1 for error. | 1981 * @return 0 for ok, -1 for error. |
1973 */ | 1982 */ |
1974 int pst_process(pst_mapi_object *list, pst_item *item, pst_item_attach *attach) { | 1983 static int pst_process(pst_mapi_object *list, pst_item *item, pst_item_attach *attach) { |
1975 DEBUG_ENT("pst_process"); | 1984 DEBUG_ENT("pst_process"); |
1976 if (!item) { | 1985 if (!item) { |
1977 DEBUG_EMAIL(("item cannot be NULL.\n")); | 1986 DEBUG_EMAIL(("item cannot be NULL.\n")); |
1978 DEBUG_RET(); | 1987 DEBUG_RET(); |
1979 return -1; | 1988 return -1; |
2991 DEBUG_RET(); | 3000 DEBUG_RET(); |
2992 return 0; | 3001 return 0; |
2993 } | 3002 } |
2994 | 3003 |
2995 | 3004 |
2996 void pst_free_list(pst_mapi_object *list) { | 3005 static void pst_free_list(pst_mapi_object *list) { |
2997 pst_mapi_object *l; | 3006 pst_mapi_object *l; |
2998 DEBUG_ENT("pst_free_list"); | 3007 DEBUG_ENT("pst_free_list"); |
2999 while (list) { | 3008 while (list) { |
3000 if (list->elements) { | 3009 if (list->elements) { |
3001 int32_t x; | 3010 int32_t x; |
3013 } | 3022 } |
3014 DEBUG_RET(); | 3023 DEBUG_RET(); |
3015 } | 3024 } |
3016 | 3025 |
3017 | 3026 |
3018 void pst_free_id2(pst_id2_ll * head) { | 3027 static void pst_free_id2(pst_id2_ll * head) { |
3019 pst_id2_ll *t; | 3028 pst_id2_ll *t; |
3020 DEBUG_ENT("pst_free_id2"); | 3029 DEBUG_ENT("pst_free_id2"); |
3021 while (head) { | 3030 while (head) { |
3022 if (head->child) pst_free_id2(head->child); | 3031 if (head->child) pst_free_id2(head->child); |
3023 t = head->next; | 3032 t = head->next; |
3026 } | 3035 } |
3027 DEBUG_RET(); | 3036 DEBUG_RET(); |
3028 } | 3037 } |
3029 | 3038 |
3030 | 3039 |
3031 void pst_free_id (pst_index_ll *head) { | 3040 static void pst_free_id (pst_index_ll *head) { |
3032 pst_index_ll *t; | 3041 pst_index_ll *t; |
3033 DEBUG_ENT("pst_free_id"); | 3042 DEBUG_ENT("pst_free_id"); |
3034 while (head) { | 3043 while (head) { |
3035 t = head->next; | 3044 t = head->next; |
3036 free(head); | 3045 free(head); |
3038 } | 3047 } |
3039 DEBUG_RET(); | 3048 DEBUG_RET(); |
3040 } | 3049 } |
3041 | 3050 |
3042 | 3051 |
3043 void pst_free_desc (pst_desc_ll *head) { | 3052 static void pst_free_desc (pst_desc_ll *head) { |
3044 pst_desc_ll *t; | 3053 pst_desc_ll *t; |
3045 DEBUG_ENT("pst_free_desc"); | 3054 DEBUG_ENT("pst_free_desc"); |
3046 while (head) { | 3055 while (head) { |
3047 while (head->child) { | 3056 while (head->child) { |
3048 head = head->child; | 3057 head = head->child; |
3062 } | 3071 } |
3063 DEBUG_RET(); | 3072 DEBUG_RET(); |
3064 } | 3073 } |
3065 | 3074 |
3066 | 3075 |
3067 void pst_free_xattrib(pst_x_attrib_ll *x) { | 3076 static void pst_free_xattrib(pst_x_attrib_ll *x) { |
3068 pst_x_attrib_ll *t; | 3077 pst_x_attrib_ll *t; |
3069 DEBUG_ENT("pst_free_xattrib"); | 3078 DEBUG_ENT("pst_free_xattrib"); |
3070 while (x) { | 3079 while (x) { |
3071 if (x->data) free(x->data); | 3080 if (x->data) free(x->data); |
3072 t = x->next; | 3081 t = x->next; |
3075 } | 3084 } |
3076 DEBUG_RET(); | 3085 DEBUG_RET(); |
3077 } | 3086 } |
3078 | 3087 |
3079 | 3088 |
3080 pst_id2_ll * pst_build_id2(pst_file *pf, pst_index_ll* list) { | 3089 static pst_id2_ll * pst_build_id2(pst_file *pf, pst_index_ll* list) { |
3081 pst_block_header block_head; | 3090 pst_block_header block_head; |
3082 pst_id2_ll *head = NULL, *tail = NULL; | 3091 pst_id2_ll *head = NULL, *tail = NULL; |
3083 uint16_t x = 0; | 3092 uint16_t x = 0; |
3084 char *b_ptr = NULL; | 3093 char *b_ptr = NULL; |
3085 char *buf = NULL; | 3094 char *buf = NULL; |
3144 DEBUG_RET(); | 3153 DEBUG_RET(); |
3145 return head; | 3154 return head; |
3146 } | 3155 } |
3147 | 3156 |
3148 | 3157 |
3149 void pst_free_attach(pst_item_attach *attach) { | 3158 static void pst_free_attach(pst_item_attach *attach) { |
3150 while (attach) { | 3159 while (attach) { |
3151 pst_item_attach *t; | 3160 pst_item_attach *t; |
3152 SAFE_FREE_STR(attach->filename1); | 3161 SAFE_FREE_STR(attach->filename1); |
3153 SAFE_FREE_STR(attach->filename2); | 3162 SAFE_FREE_STR(attach->filename2); |
3154 SAFE_FREE_STR(attach->mimetype); | 3163 SAFE_FREE_STR(attach->mimetype); |
3370 * The offset might be zero, in which case we have no data, so return a pair of null pointers. | 3379 * The offset might be zero, in which case we have no data, so return a pair of null pointers. |
3371 * Or, the offset might end in 0xf, so it is an id2 pointer, in which case we read the id2 block. | 3380 * Or, the offset might end in 0xf, so it is an id2 pointer, in which case we read the id2 block. |
3372 * Otherwise, the high order 16 bits of offset is the index into the subblocks, and | 3381 * Otherwise, the high order 16 bits of offset is the index into the subblocks, and |
3373 * the (low order 16 bits of offset)>>4 is an index into the table of offsets in the subblock. | 3382 * the (low order 16 bits of offset)>>4 is an index into the table of offsets in the subblock. |
3374 */ | 3383 */ |
3375 int pst_getBlockOffsetPointer(pst_file *pf, pst_id2_ll *i2_head, pst_subblocks *subblocks, uint32_t offset, pst_block_offset_pointer *p) { | 3384 static int pst_getBlockOffsetPointer(pst_file *pf, pst_id2_ll *i2_head, pst_subblocks *subblocks, uint32_t offset, pst_block_offset_pointer *p) { |
3376 size_t size; | 3385 size_t size; |
3377 pst_block_offset block_offset; | 3386 pst_block_offset block_offset; |
3378 DEBUG_ENT("pst_getBlockOffsetPointer"); | 3387 DEBUG_ENT("pst_getBlockOffsetPointer"); |
3379 if (p->needfree) free(p->from); | 3388 if (p->needfree) free(p->from); |
3380 p->from = NULL; | 3389 p->from = NULL; |
3417 DEBUG_RET(); | 3426 DEBUG_RET(); |
3418 return (p->from) ? 0 : 1; | 3427 return (p->from) ? 0 : 1; |
3419 } | 3428 } |
3420 | 3429 |
3421 | 3430 |
3422 int pst_getBlockOffset(char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p) { | 3431 static int pst_getBlockOffset(char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p) { |
3423 uint32_t low = offset & 0xf; | 3432 uint32_t low = offset & 0xf; |
3424 uint32_t of1 = offset >> 4; | 3433 uint32_t of1 = offset >> 4; |
3425 DEBUG_ENT("pst_getBlockOffset"); | 3434 DEBUG_ENT("pst_getBlockOffset"); |
3426 if (!p || !buf || !i_offset || low || (i_offset+2+of1+sizeof(*p) > read_size)) { | 3435 if (!p || !buf || !i_offset || low || (i_offset+2+of1+sizeof(*p) > read_size)) { |
3427 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)); | 3436 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)); |
3465 DEBUG_RET(); | 3474 DEBUG_RET(); |
3466 return ptr; | 3475 return ptr; |
3467 } | 3476 } |
3468 | 3477 |
3469 | 3478 |
3470 pst_id2_ll *pst_getID2(pst_id2_ll *head, uint64_t id2) { | 3479 static pst_id2_ll *pst_getID2(pst_id2_ll *head, uint64_t id2) { |
3471 DEBUG_ENT("pst_getID2"); | 3480 DEBUG_ENT("pst_getID2"); |
3472 DEBUG_INDEX(("looking for id2 = %#"PRIx64"\n", id2)); | 3481 DEBUG_INDEX(("looking for id2 = %#"PRIx64"\n", id2)); |
3473 pst_id2_ll *ptr = head; | 3482 pst_id2_ll *ptr = head; |
3474 while (ptr) { | 3483 while (ptr) { |
3475 if (ptr->id2 == id2) break; | 3484 if (ptr->id2 == id2) break; |
3499 * @param pf global pst file pointer | 3508 * @param pf global pst file pointer |
3500 * @param d_id the id we are looking for | 3509 * @param d_id the id we are looking for |
3501 * | 3510 * |
3502 * @return pointer to the pst_desc_ll node in the descriptor tree | 3511 * @return pointer to the pst_desc_ll node in the descriptor tree |
3503 */ | 3512 */ |
3504 pst_desc_ll* pst_getDptr(pst_file *pf, uint64_t d_id) { | 3513 static pst_desc_ll* pst_getDptr(pst_file *pf, uint64_t d_id) { |
3505 pst_desc_ll *ptr = pf->d_head; | 3514 pst_desc_ll *ptr = pf->d_head; |
3506 DEBUG_ENT("pst_getDptr"); | 3515 DEBUG_ENT("pst_getDptr"); |
3507 while (ptr && (ptr->d_id != d_id)) { | 3516 while (ptr && (ptr->d_id != d_id)) { |
3508 //DEBUG_INDEX(("Looking for %#"PRIx64" at node %#"PRIx64" with parent %#"PRIx64"\n", id, ptr->d_id, ptr->parent_d_id)); | 3517 //DEBUG_INDEX(("Looking for %#"PRIx64" at node %#"PRIx64" with parent %#"PRIx64"\n", id, ptr->d_id, ptr->parent_d_id)); |
3509 if (ptr->child) { | 3518 if (ptr->child) { |
3518 DEBUG_RET(); | 3527 DEBUG_RET(); |
3519 return ptr; // will be NULL or record we are looking for | 3528 return ptr; // will be NULL or record we are looking for |
3520 } | 3529 } |
3521 | 3530 |
3522 | 3531 |
3523 void pst_printDptr(pst_file *pf, pst_desc_ll *ptr) { | 3532 static void pst_printDptr(pst_file *pf, pst_desc_ll *ptr) { |
3524 DEBUG_ENT("pst_printDptr"); | 3533 DEBUG_ENT("pst_printDptr"); |
3525 while (ptr) { | 3534 while (ptr) { |
3526 DEBUG_INDEX(("%#"PRIx64" [%i] desc=%#"PRIx64", assoc tree=%#"PRIx64"\n", ptr->d_id, ptr->no_child, | 3535 DEBUG_INDEX(("%#"PRIx64" [%i] desc=%#"PRIx64", assoc tree=%#"PRIx64"\n", ptr->d_id, ptr->no_child, |
3527 (ptr->desc ? ptr->desc->i_id : (uint64_t)0), | 3536 (ptr->desc ? ptr->desc->i_id : (uint64_t)0), |
3528 (ptr->assoc_tree ? ptr->assoc_tree->i_id : (uint64_t)0))); | 3537 (ptr->assoc_tree ? ptr->assoc_tree->i_id : (uint64_t)0))); |
3533 } | 3542 } |
3534 DEBUG_RET(); | 3543 DEBUG_RET(); |
3535 } | 3544 } |
3536 | 3545 |
3537 | 3546 |
3538 void pst_printIDptr(pst_file* pf) { | 3547 static void pst_printIDptr(pst_file* pf) { |
3539 pst_index_ll *ptr = pf->i_head; | 3548 pst_index_ll *ptr = pf->i_head; |
3540 DEBUG_ENT("pst_printIDptr"); | 3549 DEBUG_ENT("pst_printIDptr"); |
3541 while (ptr) { | 3550 while (ptr) { |
3542 DEBUG_INDEX(("%#"PRIx64" offset=%#"PRIx64" size=%#"PRIx64"\n", ptr->i_id, ptr->offset, ptr->size)); | 3551 DEBUG_INDEX(("%#"PRIx64" offset=%#"PRIx64" size=%#"PRIx64"\n", ptr->i_id, ptr->offset, ptr->size)); |
3543 ptr = ptr->next; | 3552 ptr = ptr->next; |
3544 } | 3553 } |
3545 DEBUG_RET(); | 3554 DEBUG_RET(); |
3546 } | 3555 } |
3547 | 3556 |
3548 | 3557 |
3549 void pst_printID2ptr(pst_id2_ll *ptr) { | 3558 static void pst_printID2ptr(pst_id2_ll *ptr) { |
3550 DEBUG_ENT("pst_printID2ptr"); | 3559 DEBUG_ENT("pst_printID2ptr"); |
3551 while (ptr) { | 3560 while (ptr) { |
3552 DEBUG_INDEX(("%#"PRIx64" id=%#"PRIx64"\n", ptr->id2, (ptr->id ? ptr->id->i_id : (uint64_t)0))); | 3561 DEBUG_INDEX(("%#"PRIx64" id=%#"PRIx64"\n", ptr->id2, (ptr->id ? ptr->id->i_id : (uint64_t)0))); |
3553 if (ptr->child) pst_printID2ptr(ptr->child); | 3562 if (ptr->child) pst_printID2ptr(ptr->child); |
3554 ptr = ptr->next; | 3563 ptr = ptr->next; |
3564 * @param size size of the block to be read | 3573 * @param size size of the block to be read |
3565 * @param buf reference to pointer to buffer. If this pointer | 3574 * @param buf reference to pointer to buffer. If this pointer |
3566 is non-NULL, it will first be free()d | 3575 is non-NULL, it will first be free()d |
3567 * @return size of block read into memory | 3576 * @return size of block read into memory |
3568 */ | 3577 */ |
3569 size_t pst_read_block_size(pst_file *pf, int64_t offset, size_t size, char **buf) { | 3578 static size_t pst_read_block_size(pst_file *pf, int64_t offset, size_t size, char **buf) { |
3570 size_t rsize; | 3579 size_t rsize; |
3571 DEBUG_ENT("pst_read_block_size"); | 3580 DEBUG_ENT("pst_read_block_size"); |
3572 DEBUG_READ(("Reading block from %#"PRIx64", %x bytes\n", offset, size)); | 3581 DEBUG_READ(("Reading block from %#"PRIx64", %x bytes\n", offset, size)); |
3573 | 3582 |
3574 if (*buf) { | 3583 if (*buf) { |
3640 DEBUG_RET(); | 3649 DEBUG_RET(); |
3641 return 0; | 3650 return 0; |
3642 } | 3651 } |
3643 | 3652 |
3644 | 3653 |
3645 uint64_t pst_getIntAt(pst_file *pf, char *buf) { | 3654 static uint64_t pst_getIntAt(pst_file *pf, char *buf) { |
3646 uint64_t buf64; | 3655 uint64_t buf64; |
3647 uint32_t buf32; | 3656 uint32_t buf32; |
3648 if (pf->do_read64) { | 3657 if (pf->do_read64) { |
3649 memcpy(&buf64, buf, sizeof(buf64)); | 3658 memcpy(&buf64, buf, sizeof(buf64)); |
3650 LE64_CPU(buf64); | 3659 LE64_CPU(buf64); |
3656 return buf32; | 3665 return buf32; |
3657 } | 3666 } |
3658 } | 3667 } |
3659 | 3668 |
3660 | 3669 |
3661 uint64_t pst_getIntAtPos(pst_file *pf, int64_t pos ) { | 3670 static uint64_t pst_getIntAtPos(pst_file *pf, int64_t pos ) { |
3662 uint64_t buf64; | 3671 uint64_t buf64; |
3663 uint32_t buf32; | 3672 uint32_t buf32; |
3664 if (pf->do_read64) { | 3673 if (pf->do_read64) { |
3665 (void)pst_getAtPos(pf, pos, &buf64, sizeof(buf64)); | 3674 (void)pst_getAtPos(pf, pos, &buf64, sizeof(buf64)); |
3666 LE64_CPU(buf64); | 3675 LE64_CPU(buf64); |
3680 * @param pos offset of the data in the pst file | 3689 * @param pos offset of the data in the pst file |
3681 * @param buf buffer to contain the data | 3690 * @param buf buffer to contain the data |
3682 * @param size size of the buffer and the amount of data to be read | 3691 * @param size size of the buffer and the amount of data to be read |
3683 * @return actual read size, 0 if seek error | 3692 * @return actual read size, 0 if seek error |
3684 */ | 3693 */ |
3685 | 3694 static size_t pst_getAtPos(pst_file *pf, int64_t pos, void* buf, size_t size) { |
3686 size_t pst_getAtPos(pst_file *pf, int64_t pos, void* buf, size_t size) { | |
3687 size_t rc; | 3695 size_t rc; |
3688 DEBUG_ENT("pst_getAtPos"); | 3696 DEBUG_ENT("pst_getAtPos"); |
3689 // pst_block_recorder **t = &pf->block_head; | 3697 // pst_block_recorder **t = &pf->block_head; |
3690 // pst_block_recorder *p = pf->block_head; | 3698 // pst_block_recorder *p = pf->block_head; |
3691 // while (p && ((p->offset+p->size) <= pos)) { | 3699 // while (p && ((p->offset+p->size) <= pos)) { |
3765 DEBUG_RET(); | 3773 DEBUG_RET(); |
3766 return rsize; | 3774 return rsize; |
3767 } | 3775 } |
3768 | 3776 |
3769 | 3777 |
3770 size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_id2_ll *id2_head, char** buf) { | 3778 static size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_id2_ll *id2_head, char** buf) { |
3771 size_t ret; | 3779 size_t ret; |
3772 pst_id2_ll* ptr; | 3780 pst_id2_ll* ptr; |
3773 pst_holder h = {buf, NULL, 0}; | 3781 pst_holder h = {buf, NULL, 0}; |
3774 DEBUG_ENT("pst_ff_getID2block"); | 3782 DEBUG_ENT("pst_ff_getID2block"); |
3775 ptr = pst_getID2(id2_head, id2); | 3783 ptr = pst_getID2(id2_head, id2); |
3783 DEBUG_RET(); | 3791 DEBUG_RET(); |
3784 return ret; | 3792 return ret; |
3785 } | 3793 } |
3786 | 3794 |
3787 | 3795 |
3788 size_t pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, pst_holder *h) { | 3796 static size_t pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, pst_holder *h) { |
3789 size_t ret; | 3797 size_t ret; |
3790 char *b = NULL, *t; | 3798 char *b = NULL, *t; |
3791 DEBUG_ENT("pst_ff_getID2data"); | 3799 DEBUG_ENT("pst_ff_getID2data"); |
3792 if (!(ptr->i_id & 0x02)) { | 3800 if (!(ptr->i_id & 0x02)) { |
3793 ret = pst_ff_getIDblock_dec(pf, ptr->i_id, &b); | 3801 ret = pst_ff_getIDblock_dec(pf, ptr->i_id, &b); |
3815 DEBUG_RET(); | 3823 DEBUG_RET(); |
3816 return ret; | 3824 return ret; |
3817 } | 3825 } |
3818 | 3826 |
3819 | 3827 |
3820 size_t pst_ff_compile_ID(pst_file *pf, uint64_t id, pst_holder *h, size_t size) { | 3828 static size_t pst_ff_compile_ID(pst_file *pf, uint64_t id, pst_holder *h, size_t size) { |
3821 size_t z, a; | 3829 size_t z, a; |
3822 uint16_t count, y; | 3830 uint16_t count, y; |
3823 char *buf3 = NULL, *buf2 = NULL, *t; | 3831 char *buf3 = NULL, *buf2 = NULL, *t; |
3824 char *b_ptr; | 3832 char *b_ptr; |
3825 int line_count = 0; | 3833 int line_count = 0; |
3962 } | 3970 } |
3963 | 3971 |
3964 | 3972 |
3965 #endif //_WIN32 | 3973 #endif //_WIN32 |
3966 | 3974 |
3967 int pst_stricmp(char *a, char *b) { | 3975 static int pst_stricmp(char *a, char *b) { |
3968 // compare strings case-insensitive. | 3976 // compare strings case-insensitive. |
3969 // returns -1 if a < b, 0 if a==b, 1 if a > b | 3977 // returns -1 if a < b, 0 if a==b, 1 if a > b |
3970 while(*a != '\0' && *b != '\0' && toupper(*a)==toupper(*b)) { | 3978 while(*a != '\0' && *b != '\0' && toupper(*a)==toupper(*b)) { |
3971 a++; b++; | 3979 a++; b++; |
3972 } | 3980 } |
3977 else | 3985 else |
3978 return 1; | 3986 return 1; |
3979 } | 3987 } |
3980 | 3988 |
3981 | 3989 |
3982 int pst_strincmp(char *a, char *b, size_t x) { | 3990 static int pst_strincmp(char *a, char *b, size_t x) { |
3983 // compare upto x chars in string a and b case-insensitively | 3991 // compare upto x chars in string a and b case-insensitively |
3984 // returns -1 if a < b, 0 if a==b, 1 if a > b | 3992 // returns -1 if a < b, 0 if a==b, 1 if a > b |
3985 size_t y = 0; | 3993 size_t y = 0; |
3986 while (*a != '\0' && *b != '\0' && y < x && toupper(*a)==toupper(*b)) { | 3994 while (*a != '\0' && *b != '\0' && y < x && toupper(*a)==toupper(*b)) { |
3987 a++; b++; y++; | 3995 a++; b++; y++; |
4008 DEBUG_RET(); | 4016 DEBUG_RET(); |
4009 return r; | 4017 return r; |
4010 } | 4018 } |
4011 | 4019 |
4012 | 4020 |
4013 char * pst_wide_to_single(char *wt, size_t size) { | 4021 static char* pst_wide_to_single(char *wt, size_t size) { |
4014 // returns the first byte of each wide char. the size is the number of bytes in source | 4022 // returns the first byte of each wide char. the size is the number of bytes in source |
4015 char *x, *y; | 4023 char *x, *y; |
4016 DEBUG_ENT("pst_wide_to_single"); | 4024 DEBUG_ENT("pst_wide_to_single"); |
4017 x = pst_malloc((size/2)+1); | 4025 x = pst_malloc((size/2)+1); |
4018 y = x; | 4026 y = x; |
4084 DEBUG_RET(); | 4092 DEBUG_RET(); |
4085 return ret; | 4093 return ret; |
4086 } | 4094 } |
4087 | 4095 |
4088 | 4096 |
4089 int pst_chr_count(char *str, char x) { | 4097 static int pst_chr_count(char *str, char x) { |
4090 int r = 0; | 4098 int r = 0; |
4091 while (*str) { | 4099 while (*str) { |
4092 if (*str == x) r++; | 4100 if (*str == x) r++; |
4093 str++; | 4101 str++; |
4094 } | 4102 } |