Commit 3005e5c0 authored by Joachim Metz's avatar Joachim Metz
Browse files

Worked on Python bindings

parent dfc94612
TODO
* pypff fix get_root_item
IOError: pypff_file_get_item_type_object: unable to retrieve item type.
libpff_table_read: invalid table: 0 - missing data identifier.
libpff_item_values_read: unable to read table.
libpff_item_values_get_record_entry_by_type: unable to read item values.
libpff_item_determine_type: unable to retrieve record entry: 0x001a.
libpff_item_get_type: unable to determine item type.
* refactor libpff_message_get_entry_value_utf8_string to match naming schema
* add specific entry value flag for string types?
* add fallback inflate implementation
......
......@@ -2012,6 +2012,17 @@ int libpff_file_get_root_item(
}
internal_file = (libpff_internal_file_t *) file;
if( internal_file->file_io_handle == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid file - missing file IO handle.",
function );
return( -1 );
}
if( internal_file->item_tree_root_node == NULL )
{
libcerror_error_set(
......@@ -2107,6 +2118,17 @@ int libpff_file_get_message_store(
}
internal_file = (libpff_internal_file_t *) file;
if( internal_file->file_io_handle == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid file - missing file IO handle.",
function );
return( -1 );
}
if( message_store == NULL )
{
libcerror_error_set(
......@@ -2212,6 +2234,17 @@ int libpff_file_get_name_to_id_map(
}
internal_file = (libpff_internal_file_t *) file;
if( internal_file->file_io_handle == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid file - missing file IO handle.",
function );
return( -1 );
}
if( name_to_id_map == NULL )
{
libcerror_error_set(
......@@ -2315,6 +2348,17 @@ int libpff_file_get_root_folder(
}
internal_file = (libpff_internal_file_t *) file;
if( internal_file->file_io_handle == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid file - missing file IO handle.",
function );
return( -1 );
}
if( root_folder == NULL )
{
libcerror_error_set(
......@@ -2404,6 +2448,17 @@ int libpff_file_get_item_by_identifier(
}
internal_file = (libpff_internal_file_t *) file;
if( internal_file->file_io_handle == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid file - missing file IO handle.",
function );
return( -1 );
}
if( internal_file->item_tree_root_node == NULL )
{
libcerror_error_set(
......@@ -2529,6 +2584,17 @@ int libpff_file_get_number_of_orphan_items(
}
internal_file = (libpff_internal_file_t *) file;
if( internal_file->file_io_handle == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid file - missing file IO handle.",
function );
return( -1 );
}
if( libcdata_list_get_number_of_elements(
internal_file->orphan_item_list,
number_of_orphan_items,
......@@ -2573,13 +2639,13 @@ int libpff_file_get_orphan_item(
}
internal_file = (libpff_internal_file_t *) file;
if( internal_file->orphan_item_list == NULL )
if( internal_file->file_io_handle == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid file - missing orphan item list.",
"%s: invalid file - missing file IO handle.",
function );
return( -1 );
......@@ -2670,6 +2736,17 @@ int libpff_file_get_number_of_recovered_items(
}
internal_file = (libpff_internal_file_t *) file;
if( internal_file->file_io_handle == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid file - missing file IO handle.",
function );
return( -1 );
}
if( libcdata_list_get_number_of_elements(
internal_file->recovered_item_list,
number_of_recovered_items,
......@@ -2714,6 +2791,17 @@ int libpff_file_get_recovered_item(
}
internal_file = (libpff_internal_file_t *) file;
if( internal_file->file_io_handle == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid file - missing file IO handle.",
function );
return( -1 );
}
if( recovered_item == NULL )
{
libcerror_error_set(
......
......@@ -504,7 +504,7 @@ int libpff_item_determine_type(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_GET_FAILED,
"%s: unable to retrieve record entry: 0x04" PRIx32 ".",
"%s: unable to retrieve record entry: 0x%04" PRIx32 ".",
function,
LIBPFF_ENTRY_TYPE_MESSAGE_CLASS );
......@@ -1303,7 +1303,7 @@ int libpff_internal_item_get_entry_value_32bit_integer(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_GET_FAILED,
"%s: unable to retrieve record entry: 0x04" PRIx32 " 0x%04" PRIx32 ".",
"%s: unable to retrieve record entry: 0x%04" PRIx32 " 0x%04" PRIx32 ".",
function,
entry_type,
LIBPFF_VALUE_TYPE_INTEGER_32BIT_SIGNED );
......@@ -1406,7 +1406,7 @@ int libpff_internal_item_get_entry_value_filetime(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_GET_FAILED,
"%s: unable to retrieve record entry: 0x04" PRIx32 " 0x%04" PRIx32 ".",
"%s: unable to retrieve record entry: 0x%04" PRIx32 " 0x%04" PRIx32 ".",
function,
entry_type,
LIBPFF_VALUE_TYPE_FILETIME );
......@@ -1523,7 +1523,7 @@ int libpff_internal_item_get_entry_value_utf8_string_size(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_GET_FAILED,
"%s: unable to retrieve record entry: 0x04" PRIx32 ".",
"%s: unable to retrieve record entry: 0x%04" PRIx32 ".",
function,
entry_type );
......@@ -1668,7 +1668,7 @@ int libpff_internal_item_get_entry_value_utf8_string(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_GET_FAILED,
"%s: unable to retrieve record entry: 0x04" PRIx32 ".",
"%s: unable to retrieve record entry: 0x%04" PRIx32 ".",
function,
entry_type );
......@@ -1813,7 +1813,7 @@ int libpff_internal_item_get_entry_value_utf16_string_size(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_GET_FAILED,
"%s: unable to retrieve record entry: 0x04" PRIx32 ".",
"%s: unable to retrieve record entry: 0x%04" PRIx32 ".",
function,
entry_type );
......@@ -1958,7 +1958,7 @@ int libpff_internal_item_get_entry_value_utf16_string(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_GET_FAILED,
"%s: unable to retrieve record entry: 0x04" PRIx32 ".",
"%s: unable to retrieve record entry: 0x%04" PRIx32 ".",
function,
entry_type );
......
......@@ -27,6 +27,7 @@
#include <stdlib.h>
#endif
#include "pypff_attachment.h"
#include "pypff_codepage.h"
#include "pypff_error.h"
#include "pypff_file.h"
......@@ -1442,7 +1443,7 @@ int pypff_file_set_ascii_codepage_setter(
* Returns a Python type object if successful or NULL on error
*/
PyTypeObject *pypff_file_get_item_type_object(
libpff_item_t *item PYPFF_ATTRIBUTE_UNUSED )
libpff_item_t *item )
{
libcerror_error_t *error = NULL;
static char *function = "pypff_file_get_item_type_object";
......@@ -1505,10 +1506,12 @@ PyTypeObject *pypff_file_get_item_type_object(
case LIBPFF_ITEM_TYPE_VOICEMAIL:
return( &pypff_message_type_object );
case LIBPFF_ITEM_TYPE_ATTACHMENT:
return( &pypff_attachment_type_object );
case LIBPFF_ITEM_TYPE_FOLDER:
return( &pypff_folder_type_object );
case LIBPFF_ITEM_TYPE_ATTACHMENT:
case LIBPFF_ITEM_TYPE_ATTACHMENTS:
case LIBPFF_ITEM_TYPE_RECIPIENTS:
case LIBPFF_ITEM_TYPE_SUB_ASSOCIATED_CONTENTS:
......
......@@ -141,6 +141,116 @@ class FileTypeTests(unittest.TestCase):
with self.assertRaises(RuntimeError):
pff_file.set_ascii_codepage(codepage)
# TODO: add tests for get_root_item.
def test_get_message_store(self):
"""Tests the get_message_store function."""
pff_file = pypff.file()
with self.assertRaises(IOError):
pff_file.get_message_store()
with self.assertRaises(IOError):
pff_file.message_store
if not unittest.source:
return
pff_file = pypff.file()
pff_file.open(unittest.source)
pff_file.get_message_store()
_ = pff_file.message_store
pff_file.close()
def test_get_name_to_id_map(self):
"""Tests the get_name_to_id_map function."""
pff_file = pypff.file()
with self.assertRaises(IOError):
pff_file.get_name_to_id_map()
with self.assertRaises(IOError):
pff_file.name_to_id_map
if not unittest.source:
return
pff_file = pypff.file()
pff_file.open(unittest.source)
pff_file.get_name_to_id_map()
_ = pff_file.name_to_id_map
pff_file.close()
def test_get_root_folder(self):
"""Tests the get_root_folder function."""
pff_file = pypff.file()
with self.assertRaises(IOError):
pff_file.get_root_folder()
with self.assertRaises(IOError):
pff_file.root_folder
if not unittest.source:
return
pff_file = pypff.file()
pff_file.open(unittest.source)
pff_file.get_root_folder()
_ = pff_file.root_folder
pff_file.close()
def test_get_number_of_orphan_items(self):
"""Tests the get_number_of_orphan_items function."""
pff_file = pypff.file()
with self.assertRaises(IOError):
pff_file.get_number_of_orphan_items()
with self.assertRaises(IOError):
pff_file.number_of_orphan_items
if not unittest.source:
return
pff_file = pypff.file()
pff_file.open(unittest.source)
number_of_items = pff_file.get_number_of_orphan_items()
self.assertIsNotNone(number_of_items)
self.assertIsNotNone(pff_file.number_of_orphan_items)
pff_file.close()
def test_get_orphan_item(self):
"""Tests the get_orphan_item function."""
pff_file = pypff.file()
with self.assertRaises(IOError):
pff_file.get_orphan_item(0)
if not unittest.source:
return
pff_file = pypff.file()
pff_file.open(unittest.source)
if pff_file.number_of_orphan_items > 0:
item = pff_file.get_orphan_item(0)
self.assertIsNotNone(item)
pff_file.close()
if __name__ == "__main__":
argument_parser = argparse.ArgumentParser()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment