comparison src/libpst.h @ 201:3850a3b11745

fixes for parallel readpst
author Carl Byington <carl@five-ten-sg.com>
date Sat, 16 May 2009 10:32:26 -0700
parents e3a46f66332b
children 268458c79e9b
comparison
equal deleted inserted replaced
200:d360f96f71f6 201:3850a3b11745
848 int readcount; 848 int readcount;
849 } pst_block_recorder; 849 } pst_block_recorder;
850 850
851 851
852 typedef struct pst_file { 852 typedef struct pst_file {
853 /** file pointer to opened PST file */
854 FILE* fp;
855 /** original cwd when the file was opened */
856 char* cwd;
857 /** original file name when the file was opened */
858 char* fname;
853 /** the head and tail of the linked list of index structures */ 859 /** the head and tail of the linked list of index structures */
854 pst_index_ll *i_head, *i_tail; 860 pst_index_ll *i_head, *i_tail;
855 /** the head and tail of the top level of the descriptor tree */ 861 /** the head and tail of the top level of the descriptor tree */
856 pst_desc_tree *d_head, *d_tail; 862 pst_desc_tree *d_head, *d_tail;
857 /** the head of the extended attributes linked list */ 863 /** the head of the extended attributes linked list */
870 uint64_t index1_back; 876 uint64_t index1_back;
871 /** file offset of the first b-tree node in the descriptor tree*/ 877 /** file offset of the first b-tree node in the descriptor tree*/
872 uint64_t index2; 878 uint64_t index2;
873 /** back pointer value in the first b-tree node in the descriptor tree */ 879 /** back pointer value in the first b-tree node in the descriptor tree */
874 uint64_t index2_back; 880 uint64_t index2_back;
875 /** file pointer to opened PST file */
876 FILE * fp;
877 /** size of the pst file */ 881 /** size of the pst file */
878 uint64_t size; 882 uint64_t size;
879 /** @li 0 PST_NO_ENCRYPT, none 883 /** @li 0 PST_NO_ENCRYPT, none
880 * @li 1 PST_COMP_ENCRYPT, simple byte substitution cipher with fixed key 884 * @li 1 PST_COMP_ENCRYPT, simple byte substitution cipher with fixed key
881 * @li 2 PST_ENCRYPT, german enigma 3 rotor cipher with fixed key */ 885 * @li 2 PST_ENCRYPT, german enigma 3 rotor cipher with fixed key */
893 * @param pf pointer to uninitialized pst_file structure. This structure 897 * @param pf pointer to uninitialized pst_file structure. This structure
894 * will be filled in by this function. 898 * will be filled in by this function.
895 * @param name name of the file, suitable for fopen(). 899 * @param name name of the file, suitable for fopen().
896 * @return 0 if ok, -1 if error 900 * @return 0 if ok, -1 if error
897 */ 901 */
898 int pst_open(pst_file *pf, const char *name); 902 int pst_open(pst_file *pf, const char *name);
903
904
905 /** Reopen the pst file after a fork
906 * @param pf pointer to the pst_file structure setup by pst_open().
907 * @return 0 if ok, -1 if error
908 */
909 int pst_reopen(pst_file *pf);
899 910
900 911
901 /** Load the index entries from the pst file. This loads both the 912 /** Load the index entries from the pst file. This loads both the
902 * i_id linked list, and the d_id tree, and should normally be the 913 * i_id linked list, and the d_id tree, and should normally be the
903 * first call after pst_open(). 914 * first call after pst_open().
904 * @param pf pointer to the pst_file structure setup by pst_open(). 915 * @param pf pointer to the pst_file structure setup by pst_open().
905 */ 916 */
906 int pst_load_index (pst_file *pf); 917 int pst_load_index (pst_file *pf);
907 918
908 919
909 /** Load the extended attribute mapping table from the pst file. This 920 /** Load the extended attribute mapping table from the pst file. This
910 * should normally be the second call after pst_open(). 921 * should normally be the second call after pst_open().
911 * @param pf pointer to the pst_file structure setup by pst_open(). 922 * @param pf pointer to the pst_file structure setup by pst_open().
912 */ 923 */
913 int pst_load_extended_attributes(pst_file *pf); 924 int pst_load_extended_attributes(pst_file *pf);
914 925
915 926
916 /** Close a pst file. 927 /** Close a pst file.
917 * @param pf pointer to the pst_file structure setup by pst_open(). 928 * @param pf pointer to the pst_file structure setup by pst_open().
918 */ 929 */
919 int pst_close(pst_file *pf); 930 int pst_close(pst_file *pf);
920 931
921 932
922 /** Get the top of folders descriptor tree. This is the main descriptor tree 933 /** Get the top of folders descriptor tree. This is the main descriptor tree
923 * that needs to be walked to look at every item in the pst file. 934 * that needs to be walked to look at every item in the pst file.
924 * @param pf pointer to the pst_file structure setup by pst_open(). 935 * @param pf pointer to the pst_file structure setup by pst_open().
925 * @param root root item, which can be obtained by pst_parse_item(pf, pf->d.head, NULL). 936 * @param root root item, which can be obtained by pst_parse_item(pf, pf->d.head, NULL).
926 */ 937 */
927 pst_desc_tree* pst_getTopOfFolders(pst_file *pf, const pst_item *root); 938 pst_desc_tree* pst_getTopOfFolders(pst_file *pf, const pst_item *root);
928 939
929 940
930 /** Assemble the binary attachment into a single buffer. 941 /** Assemble the binary attachment into a single buffer.
931 * @param pf pointer to the pst_file structure setup by pst_open(). 942 * @param pf pointer to the pst_file structure setup by pst_open().
932 * @param attach pointer to the attachment record 943 * @param attach pointer to the attachment record
933 * @return structure containing size of and pointer to the buffer. 944 * @return structure containing size of and pointer to the buffer.
934 * the caller must free this buffer. 945 * the caller must free this buffer.
935 */ 946 */
936 pst_binary pst_attach_to_mem(pst_file *pf, pst_item_attach *attach); 947 pst_binary pst_attach_to_mem(pst_file *pf, pst_item_attach *attach);
937 948
938 949
939 /** Write a binary attachment to a file. 950 /** Write a binary attachment to a file.
940 * @param pf pointer to the pst_file structure setup by pst_open(). 951 * @param pf pointer to the pst_file structure setup by pst_open().
941 * @param attach pointer to the attachment record 952 * @param attach pointer to the attachment record
942 * @param fp pointer to an open FILE. 953 * @param fp pointer to an open FILE.
943 */ 954 */
944 size_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp); 955 size_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp);
945 956
946 957
947 /** Write a binary attachment base64 encoded to a file. 958 /** Write a binary attachment base64 encoded to a file.
948 * @param pf pointer to the pst_file structure setup by pst_open(). 959 * @param pf pointer to the pst_file structure setup by pst_open().
949 * @param attach pointer to the attachment record 960 * @param attach pointer to the attachment record
950 * @param fp pointer to an open FILE. 961 * @param fp pointer to an open FILE.
951 */ 962 */
952 size_t pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp); 963 size_t pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp);
953 964
954 965
955 /** Walk the descriptor tree. 966 /** Walk the descriptor tree.
956 * @param d pointer to the current item in the descriptor tree. 967 * @param d pointer to the current item in the descriptor tree.
957 * @return pointer to the next item in the descriptor tree. 968 * @return pointer to the next item in the descriptor tree.
958 */ 969 */
959 pst_desc_tree* pst_getNextDptr(pst_desc_tree* d); 970 pst_desc_tree* pst_getNextDptr(pst_desc_tree* d);
960 971
961 972
962 /** Assemble a mapi object from a descriptor pointer. 973 /** Assemble a mapi object from a descriptor pointer.
963 * @param pf pointer to the pst_file structure setup by pst_open(). 974 * @param pf pointer to the pst_file structure setup by pst_open().
964 * @param d_ptr pointer to an item in the descriptor tree. 975 * @param d_ptr pointer to an item in the descriptor tree.
965 * @param m_head normally NULL. This is only used when processing embedded 976 * @param m_head normally NULL. This is only used when processing embedded
966 * attached rfc822 messages, in which case it is attach->id2_head. 977 * attached rfc822 messages, in which case it is attach->id2_head.
967 * @return pointer to the mapi object. Must be free'd by pst_freeItem(). 978 * @return pointer to the mapi object. Must be free'd by pst_freeItem().
968 */ 979 */
969 pst_item* pst_parse_item (pst_file *pf, pst_desc_tree *d_ptr, pst_id2_tree *m_head); 980 pst_item* pst_parse_item (pst_file *pf, pst_desc_tree *d_ptr, pst_id2_tree *m_head);
970 981
971 982
972 /** Free the item returned by pst_parse_item(). 983 /** Free the item returned by pst_parse_item().
973 * @param item pointer to item returned from pst_parse_item(). 984 * @param item pointer to item returned from pst_parse_item().
974 */ 985 */
975 void pst_freeItem(pst_item *item); 986 void pst_freeItem(pst_item *item);
976 987
977 988
978 /** Lookup the i_id in the index linked list, and return a pointer to the element. 989 /** Lookup the i_id in the index linked list, and return a pointer to the element.
979 * @param pf pointer to the pst_file structure setup by pst_open(). 990 * @param pf pointer to the pst_file structure setup by pst_open().
980 * @param i_id key for the index linked list 991 * @param i_id key for the index linked list
981 * @return pointer to the element, or NULL if not found. 992 * @return pointer to the element, or NULL if not found.
982 */ 993 */
983 pst_index_ll* pst_getID(pst_file* pf, uint64_t i_id); 994 pst_index_ll* pst_getID(pst_file* pf, uint64_t i_id);
984 995
985 996
986 /** Decrypt a block of data from the pst file. 997 /** Decrypt a block of data from the pst file.
987 * @param i_id identifier of this block, needed as part of the key for the enigma cipher 998 * @param i_id identifier of this block, needed as part of the key for the enigma cipher
988 * @param buf pointer to the buffer to be decrypted in place 999 * @param buf pointer to the buffer to be decrypted in place
991 @li 0 PST_NO_ENCRYPT, none 1002 @li 0 PST_NO_ENCRYPT, none
992 @li 1 PST_COMP_ENCRYPT, simple byte substitution cipher with fixed key 1003 @li 1 PST_COMP_ENCRYPT, simple byte substitution cipher with fixed key
993 @li 2 PST_ENCRYPT, german enigma 3 rotor cipher with fixed key 1004 @li 2 PST_ENCRYPT, german enigma 3 rotor cipher with fixed key
994 * @return 0 if ok, -1 if error (NULL buffer or unknown encryption type) 1005 * @return 0 if ok, -1 if error (NULL buffer or unknown encryption type)
995 */ 1006 */
996 int pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type); 1007 int pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type);
997 1008
998 1009
999 /** Get an ID block from the file using pst_ff_getIDblock() and decrypt if necessary. 1010 /** Get an ID block from the file using pst_ff_getIDblock() and decrypt if necessary.
1000 * @param pf pointer to the pst_file structure setup by pst_open(). 1011 * @param pf pointer to the pst_file structure setup by pst_open().
1001 * @param i_id ID of block to retrieve 1012 * @param i_id ID of block to retrieve
1002 * @param buf reference to pointer to buffer that will contain the data block. 1013 * @param buf reference to pointer to buffer that will contain the data block.
1003 * If this pointer is non-NULL, it will first be free()d. 1014 * If this pointer is non-NULL, it will first be free()d.
1004 * @return Size of block read into memory 1015 * @return Size of block read into memory
1005 */ 1016 */
1006 size_t pst_ff_getIDblock_dec(pst_file *pf, uint64_t i_id, char **buf); 1017 size_t pst_ff_getIDblock_dec(pst_file *pf, uint64_t i_id, char **buf);
1007 1018
1008 1019
1009 /** Read a block of data from the file into memory. 1020 /** Read a block of data from the file into memory.
1010 * @param pf pointer to the pst_file structure setup by pst_open(). 1021 * @param pf pointer to the pst_file structure setup by pst_open().
1011 * @param i_id ID of block to read 1022 * @param i_id ID of block to read
1012 * @param buf reference to pointer to buffer that will contain the data block. 1023 * @param buf reference to pointer to buffer that will contain the data block.
1013 * If this pointer is non-NULL, it will first be free()d. 1024 * If this pointer is non-NULL, it will first be free()d.
1014 * @return size of block read into memory 1025 * @return size of block read into memory
1015 */ 1026 */
1016 size_t pst_ff_getIDblock(pst_file *pf, uint64_t i_id, char** buf); 1027 size_t pst_ff_getIDblock(pst_file *pf, uint64_t i_id, char** buf);
1017 1028
1018 1029
1019 /** fwrite with checking for null pointer. 1030 /** fwrite with checking for null pointer.
1020 * @param ptr pointer to the buffer 1031 * @param ptr pointer to the buffer
1021 * @param size size of each item 1032 * @param size size of each item
1022 * @param nmemb number of items 1033 * @param nmemb number of items
1023 * @param stream output file 1034 * @param stream output file
1024 * @return number of bytes written, zero if ptr==NULL 1035 * @return number of bytes written, zero if ptr==NULL
1025 */ 1036 */
1026 size_t pst_fwrite(const void* ptr, size_t size, size_t nmemb, FILE* stream); 1037 size_t pst_fwrite(const void* ptr, size_t size, size_t nmemb, FILE* stream);
1027 1038
1028 1039
1029 /** Add any necessary escape characters for rfc2426 vcard format 1040 /** Add any necessary escape characters for rfc2426 vcard format
1030 * @param str pointer to input string 1041 * @param str pointer to input string
1031 * @return pointer to output string, either the input pointer if 1042 * @return pointer to output string, either the input pointer if
1032 * there are no characters that need escapes, or a pointer 1043 * there are no characters that need escapes, or a pointer
1033 * to a different buffer containing the escaped string. In 1044 * to a different buffer containing the escaped string. In
1034 * either case, you don't need to free this returned pointer. 1045 * either case, you don't need to free this returned pointer.
1035 */ 1046 */
1036 char* pst_rfc2426_escape(char *str); 1047 char* pst_rfc2426_escape(char *str);
1037 1048
1038 1049
1039 /** Convert a FILETIME into rfc2425 date/time format 1953-10-15T23:10:00Z 1050 /** Convert a FILETIME into rfc2425 date/time format 1953-10-15T23:10:00Z
1040 * which is the same as one of the forms in the ISO3601 standard 1051 * which is the same as one of the forms in the ISO3601 standard
1041 * @param[in] ft time to be converted 1052 * @param[in] ft time to be converted
1042 * @param[in] buflen length of the output buffer 1053 * @param[in] buflen length of the output buffer
1043 * @param[out] result pointer to output buffer, must be at least 30 bytes 1054 * @param[out] result pointer to output buffer, must be at least 30 bytes
1044 * @return time in rfc2425 format 1055 * @return time in rfc2425 format
1045 */ 1056 */
1046 char* pst_rfc2425_datetime_format(const FILETIME* ft, int buflen, char* result); 1057 char* pst_rfc2425_datetime_format(const FILETIME* ft, int buflen, char* result);
1047 1058
1048 1059
1049 /** Convert a FILETIME into rfc2445 date/time format 19531015T231000Z 1060 /** Convert a FILETIME into rfc2445 date/time format 19531015T231000Z
1050 * @param[in] ft time to be converted 1061 * @param[in] ft time to be converted
1051 * @param[in] buflen length of the output buffer 1062 * @param[in] buflen length of the output buffer
1052 * @param[out] result pointer to output buffer, must be at least 30 bytes 1063 * @param[out] result pointer to output buffer, must be at least 30 bytes
1053 * @return time in rfc2445 format 1064 * @return time in rfc2445 format
1054 */ 1065 */
1055 char* pst_rfc2445_datetime_format(const FILETIME* ft, int buflen, char* result); 1066 char* pst_rfc2445_datetime_format(const FILETIME* ft, int buflen, char* result);
1056 1067
1057 1068
1058 /** Convert the current time rfc2445 date/time format 19531015T231000Z 1069 /** Convert the current time rfc2445 date/time format 19531015T231000Z
1059 * @return time in rfc2445 format 1070 * @return time in rfc2445 format
1060 */ 1071 */
1061 char* pst_rfc2445_datetime_format_now(int buflen, char* result); 1072 char* pst_rfc2445_datetime_format_now(int buflen, char* result);
1062 1073
1063 1074
1064 /** Get the default character set for this item. This is used to find 1075 /** Get the default character set for this item. This is used to find
1065 * the charset for pst_string elements that are not already in utf8 encoding. 1076 * the charset for pst_string elements that are not already in utf8 encoding.
1066 * @param item pointer to the mapi item of interest 1077 * @param item pointer to the mapi item of interest
1067 * @return default character set as a string useable by iconv() 1078 * @return default character set as a string useable by iconv()
1068 */ 1079 */
1069 const char* pst_default_charset(pst_item *item); 1080 const char* pst_default_charset(pst_item *item);
1070 1081
1071 1082
1072 /** Convert str to utf8 if possible; null strings are preserved. 1083 /** Convert str to utf8 if possible; null strings are preserved.
1073 * @param item pointer to the containing mapi item 1084 * @param item pointer to the containing mapi item
1074 * @param str pointer to the mapi string of interest 1085 * @param str pointer to the mapi string of interest
1075 */ 1086 */
1076 void pst_convert_utf8_null(pst_item *item, pst_string *str); 1087 void pst_convert_utf8_null(pst_item *item, pst_string *str);
1077 1088
1078 1089
1079 /** Convert str to utf8 if possible; null strings are converted into empty strings. 1090 /** Convert str to utf8 if possible; null strings are converted into empty strings.
1080 * @param item pointer to the containing mapi item 1091 * @param item pointer to the containing mapi item
1081 * @param str pointer to the mapi string of interest 1092 * @param str pointer to the mapi string of interest
1082 */ 1093 */
1083 void pst_convert_utf8(pst_item *item, pst_string *str); 1094 void pst_convert_utf8(pst_item *item, pst_string *str);
1084 1095
1085 1096
1086 /** Decode raw recurrence data into a better structure. 1097 /** Decode raw recurrence data into a better structure.
1087 * @param appt pointer to appointment structure 1098 * @param appt pointer to appointment structure
1088 * @return pointer to decoded recurrence structure that must be free'd by the caller. 1099 * @return pointer to decoded recurrence structure that must be free'd by the caller.
1091 1102
1092 1103
1093 /** Free a recurrence structure. 1104 /** Free a recurrence structure.
1094 * @param r input pointer to be freed 1105 * @param r input pointer to be freed
1095 */ 1106 */
1096 void pst_free_recurrence(pst_recurrence* r); 1107 void pst_free_recurrence(pst_recurrence* r);
1097 1108
1098 1109
1099 1110
1100 // switch from maximal packing back to default packing 1111 // switch from maximal packing back to default packing
1101 // undo the packing from the beginning of this file 1112 // undo the packing from the beginning of this file