changeset 204:268458c79e9b

more cleanup of the shared library interface, but still not fully thread safe
author Carl Byington <carl@five-ten-sg.com>
date Sat, 06 Jun 2009 11:39:02 -0700
parents 9fb600ef4e03
children 5f3fa53cb0e1
files ChangeLog python/python-libpst.cpp python/test.py src/libpst.c src/libpst.h xml/libpst.in
diffstat 6 files changed, 29 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue May 19 10:20:33 2009 -0700
+++ b/ChangeLog	Sat Jun 06 11:39:02 2009 -0700
@@ -9,10 +9,12 @@
     * removed contact->access_method since we don't have a mapi element for it.
     * changed pst_attach_to_mem to return pst_binary structure.
     * decode more recurrence mapi elements.
-    * change interfaces to be thread safe.
+    * change some interfaces to be thread safe.
     * readpst changes for parallel operation on multi processor machines.
     * remove readpstlog - the debug log files are now plain ascii. Add locking
       if needed so parallel jobs can produce debug logs.
+    * more cleanup of the shared library interface, but still not fully
+      thread safe.
 
 LibPST 0.6.37 (2009-04-17)
 ===============================
--- a/python/python-libpst.cpp	Tue May 19 10:20:33 2009 -0700
+++ b/python/python-libpst.cpp	Sat Jun 06 11:39:02 2009 -0700
@@ -37,9 +37,7 @@
     pst_item*       pst_parse_item(pst_desc_tree *d_ptr, pst_id2_tree *m_head);
     void            pst_freeItem(pst_item *item);
     pst_index_ll*   pst_getID(uint64_t i_id);
-    int             pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type);
     size_t          pst_ff_getIDblock_dec(uint64_t i_id, char **buf);
-    size_t          pst_ff_getIDblock(uint64_t i_id, char** buf);
     string          pst_rfc2426_escape(char *str);
     string          pst_rfc2425_datetime_format(const FILETIME *ft);
     string          pst_rfc2445_datetime_format(const FILETIME *ft);
@@ -71,8 +69,8 @@
     if (is_open) {
         ::pst_load_index(&pf);
         ::pst_load_extended_attributes(&pf);
-        root = ::pst_parse_item(&pf, pf.d_head, NULL);
-        topf = ::pst_getTopOfFolders(&pf, root)->child;
+        if (pf.d_head) root = ::pst_parse_item(&pf, pf.d_head, NULL);
+        if (root)      topf = ::pst_getTopOfFolders(&pf, root)->child;
     }
 }
 
@@ -117,18 +115,10 @@
     return ::pst_getID(&pf, i_id);
 }
 
-int             pst::pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type) {
-    return ::pst_decrypt(i_id, buf, size, type);
-}
-
 size_t          pst::pst_ff_getIDblock_dec(uint64_t i_id, char **buf) {
     return ::pst_ff_getIDblock_dec(&pf, i_id, buf);
 }
 
-size_t          pst::pst_ff_getIDblock(uint64_t i_id, char** buf) {
-    return ::pst_ff_getIDblock(&pf, i_id, buf);
-}
-
 string          pst::pst_rfc2426_escape(char *str) {
     return ::pst_rfc2426_escape(str);
 }
@@ -614,9 +604,7 @@
         .def("pst_parse_item",              &pst::pst_parse_item,      return_value_policy<reference_existing_object>())
         .def("pst_freeItem",                &pst::pst_freeItem)
         .def("pst_getID",                   &pst::pst_getID,           return_value_policy<reference_existing_object>())
-        .def("pst_decrypt",                 &pst::pst_decrypt)
         .def("pst_ff_getIDblock_dec",       &pst::pst_ff_getIDblock_dec)
-        .def("pst_ff_getIDblock",           &pst::pst_ff_getIDblock)
         .def("pst_rfc2426_escape",          &pst::pst_rfc2426_escape)
         .def("pst_rfc2425_datetime_format", &pst::pst_rfc2425_datetime_format)
         .def("pst_rfc2445_datetime_format", &pst::pst_rfc2445_datetime_format)
--- a/python/test.py	Tue May 19 10:20:33 2009 -0700
+++ b/python/test.py	Sat Jun 06 11:39:02 2009 -0700
@@ -1,8 +1,5 @@
 import _libpst, sys
 
-print _libpst.__dict__
-exit
-
 ft = _libpst.FILETIME()
 ft.dwLowDateTime = 0
 ft.dwHighDateTime = 1
@@ -28,7 +25,7 @@
                     if (ft):
                         print "message arrived at %s" % (pst.pst_rfc2425_datetime_format(ft))
                     if (em.messageid.str):
-                        print "message id is |%s|" % (em.messageid.str)
+                        print "message id is <%s>" % (em.messageid.str)
                     subj = item.subject;
                     if (subj and subj.str):
                         was = subj.is_utf8;
@@ -46,7 +43,7 @@
                         print "attachment id %d" % (attid)
                         att1 = att.filename1
                         att2 = att.filename2
-                        print "attachment file name %s %s" % (att1.str, att2.str)
+                        print "attachment file name short '%s' long '%s'" % (att1.str, att2.str)
                         if (0):
                             attdata = pst.pst_attach_to_mem(att)
                             if (attdata):
--- a/src/libpst.c	Tue May 19 10:20:33 2009 -0700
+++ b/src/libpst.c	Sat Jun 06 11:39:02 2009 -0700
@@ -257,6 +257,7 @@
 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);
 static int              pst_chr_count(char *str, char x);
 static size_t           pst_ff_compile_ID(pst_file *pf, uint64_t i_id, pst_holder *h, size_t size);
+static size_t           pst_ff_getIDblock(pst_file *pf, uint64_t i_id, char** buf);
 static size_t           pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_id2_tree *id2_head, char** buf);
 static size_t           pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, pst_holder *h);
 static void             pst_free_attach(pst_item_attach *attach);
@@ -278,6 +279,7 @@
 static void             pst_printID2ptr(pst_id2_tree *ptr);
 static int              pst_process(pst_mapi_object *list, pst_item *item, pst_item_attach *attach);
 static size_t           pst_read_block_size(pst_file *pf, int64_t offset, size_t size, char **buf);
+static int              pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type);
 static int              pst_stricmp(char *a, char *b);
 static int              pst_strincmp(char *a, char *b, size_t x);
 static char*            pst_wide_to_single(char *wt, size_t size);
@@ -3508,11 +3510,11 @@
 
 
 /**
-  * The offset might be zero, in which case we have no data, so return a pair of null pointers.
-  * Or, the offset might end in 0xf, so it is an id2 pointer, in which case we read the id2 block.
-  * Otherwise, the high order 16 bits of offset is the index into the subblocks, and
-  * the (low order 16 bits of offset)>>4 is an index into the table of offsets in the subblock.
-*/
+ * The offset might be zero, in which case we have no data, so return a pair of null pointers.
+ * Or, the offset might end in 0xf, so it is an id2 pointer, in which case we read the id2 block.
+ * Otherwise, the high order 16 bits of offset is the index into the subblocks, and
+ * the (low order 16 bits of offset)>>4 is an index into the table of offsets in the subblock.
+ */
 static int pst_getBlockOffsetPointer(pst_file *pf, pst_id2_tree *i2_head, pst_subblocks *subblocks, uint32_t offset, pst_block_offset_pointer *p) {
     size_t size;
     pst_block_offset block_offset;
@@ -3560,6 +3562,7 @@
 }
 
 
+/** */
 static int pst_getBlockOffset(char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p) {
     uint32_t low = offset & 0xf;
     uint32_t of1 = offset >> 4;
@@ -3584,6 +3587,7 @@
 }
 
 
+/** */
 pst_index_ll* pst_getID(pst_file* pf, uint64_t i_id) {
     pst_index_ll *ptr;
     DEBUG_ENT("pst_getID");
@@ -3735,7 +3739,17 @@
 }
 
 
-int pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type) {
+/** Decrypt a block of data from the pst file.
+ * @param i_id identifier of this block, needed as part of the key for the enigma cipher
+ * @param buf  pointer to the buffer to be decrypted in place
+ * @param size size of the buffer
+ * @param type
+    @li 0 PST_NO_ENCRYPT, none
+    @li 1 PST_COMP_ENCRYPT, simple byte substitution cipher with fixed key
+    @li 2 PST_ENCRYPT, german enigma 3 rotor cipher with fixed key
+ * @return 0 if ok, -1 if error (NULL buffer or unknown encryption type)
+ */
+static int pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type) {
     size_t x = 0;
     unsigned char y;
     DEBUG_ENT("pst_decrypt");
@@ -3889,7 +3903,7 @@
  *             If this pointer is non-NULL, it will first be free()d.
  * @return     size of block read into memory
  */
-size_t pst_ff_getIDblock(pst_file *pf, uint64_t i_id, char** buf) {
+static size_t pst_ff_getIDblock(pst_file *pf, uint64_t i_id, char** buf) {
     pst_index_ll *rec;
     size_t rsize;
     DEBUG_ENT("pst_ff_getIDblock");
--- a/src/libpst.h	Tue May 19 10:20:33 2009 -0700
+++ b/src/libpst.h	Sat Jun 06 11:39:02 2009 -0700
@@ -994,19 +994,6 @@
 pst_index_ll*   pst_getID(pst_file* pf, uint64_t i_id);
 
 
-/** Decrypt a block of data from the pst file.
- * @param i_id identifier of this block, needed as part of the key for the enigma cipher
- * @param buf  pointer to the buffer to be decrypted in place
- * @param size size of the buffer
- * @param type
-    @li 0 PST_NO_ENCRYPT, none
-    @li 1 PST_COMP_ENCRYPT, simple byte substitution cipher with fixed key
-    @li 2 PST_ENCRYPT, german enigma 3 rotor cipher with fixed key
- * @return 0 if ok, -1 if error (NULL buffer or unknown encryption type)
- */
-int             pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type);
-
-
 /** Get an ID block from the file using pst_ff_getIDblock() and decrypt if necessary.
  * @param pf   pointer to the pst_file structure setup by pst_open().
  * @param i_id ID of block to retrieve
@@ -1017,16 +1004,6 @@
 size_t          pst_ff_getIDblock_dec(pst_file *pf, uint64_t i_id, char **buf);
 
 
-/** Read a block of data from the file into memory.
- * @param pf   pointer to the pst_file structure setup by pst_open().
- * @param i_id ID of block to read
- * @param buf  reference to pointer to buffer that will contain the data block.
- *             If this pointer is non-NULL, it will first be free()d.
- * @return     size of block read into memory
- */
-size_t          pst_ff_getIDblock(pst_file *pf, uint64_t i_id, char** buf);
-
-
 /** fwrite with checking for null pointer.
  * @param ptr pointer to the buffer
  * @param size  size of each item
--- a/xml/libpst.in	Tue May 19 10:20:33 2009 -0700
+++ b/xml/libpst.in	Sat Jun 06 11:39:02 2009 -0700
@@ -61,7 +61,7 @@
                 <arg><option>-c <replaceable class="parameter">format</replaceable></option></arg>
                 <arg><option>-d <replaceable class="parameter">debug-file</replaceable></option></arg>
                 <arg><option>-h</option></arg>
-                <arg><option>-j <replaceable class="parameter">jobs</replaceable</option></arg>
+                <arg><option>-j <replaceable class="parameter">jobs</replaceable></option></arg>
                 <arg><option>-k</option></arg>
                 <arg><option>-o <replaceable class="parameter">output-directory</replaceable></option></arg>
                 <arg><option>-q</option></arg>