diff --git a/Platform/Apple/ePub3.xcodeproj/project.pbxproj b/Platform/Apple/ePub3.xcodeproj/project.pbxproj index a48169bb1..5d2f44ba3 100644 --- a/Platform/Apple/ePub3.xcodeproj/project.pbxproj +++ b/Platform/Apple/ePub3.xcodeproj/project.pbxproj @@ -16,9 +16,108 @@ 1EFA3ACB17AB0BEF003A4BC2 /* filter_manager_impl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1EFA3ACA17AB0BEF003A4BC2 /* filter_manager_impl.cpp */; }; 1EFA3ACC17AB0C7A003A4BC2 /* filter_manager_impl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1EFA3ACA17AB0BEF003A4BC2 /* filter_manager_impl.cpp */; }; 3418BA7D16C4151E009AA7EF /* ring_buffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ABA88FD116C2B4ED00F2014B /* ring_buffer.cpp */; }; + 5876AC1A1BA250B100AF093E /* zip_add_entry.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0911B99A24F00E472DF /* zip_add_entry.c */; }; + 5876AC1B1BA250B400AF093E /* zip_buffer.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0921B99A24F00E472DF /* zip_buffer.c */; }; + 5876AC1C1BA250B800AF093E /* zip_dir_add.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0931B99A24F00E472DF /* zip_dir_add.c */; }; + 5876AC1D1BA250BB00AF093E /* zip_discard.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0941B99A24F00E472DF /* zip_discard.c */; }; + 5876AC1E1BA250BF00AF093E /* zip_entry.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0951B99A24F00E472DF /* zip_entry.c */; }; + 5876AC1F1BA250C200AF093E /* zip_extra_field_api.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0961B99A24F00E472DF /* zip_extra_field_api.c */; }; + 5876AC201BA250C500AF093E /* zip_extra_field.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0971B99A24F00E472DF /* zip_extra_field.c */; }; + 5876AC211BA250C900AF093E /* zip_fdopen.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0981B99A24F00E472DF /* zip_fdopen.c */; }; + 5876AC221BA250CC00AF093E /* zip_file_add.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0991B99A24F00E472DF /* zip_file_add.c */; }; + 5876AC231BA250CF00AF093E /* zip_file_get_comment.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A09A1B99A24F00E472DF /* zip_file_get_comment.c */; }; + 5876AC241BA250D300AF093E /* zip_file_get_external_attributes.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A09B1B99A24F00E472DF /* zip_file_get_external_attributes.c */; }; + 5876AC251BA250D600AF093E /* zip_file_rename.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A09C1B99A24F00E472DF /* zip_file_rename.c */; }; + 5876AC261BA250E900AF093E /* zip_file_replace.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A09D1B99A24F00E472DF /* zip_file_replace.c */; }; + 5876AC271BA250E900AF093E /* zip_file_set_comment.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A09E1B99A24F00E472DF /* zip_file_set_comment.c */; }; + 5876AC281BA250E900AF093E /* zip_file_set_external_attributes.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A09F1B99A24F00E472DF /* zip_file_set_external_attributes.c */; }; + 5876AC291BA250E900AF093E /* zip_file_set_mtime.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A01B99A24F00E472DF /* zip_file_set_mtime.c */; }; + 5876AC2A1BA250E900AF093E /* zip_fopen_encrypted.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A11B99A24F00E472DF /* zip_fopen_encrypted.c */; }; + 5876AC2B1BA250E900AF093E /* zip_fopen_index_encrypted.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A21B99A24F00E472DF /* zip_fopen_index_encrypted.c */; }; + 5876AC2C1BA250E900AF093E /* zip_get_compression_implementation.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A31B99A24F00E472DF /* zip_get_compression_implementation.c */; }; + 5876AC2D1BA250E900AF093E /* zip_get_encryption_implementation.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A41B99A24F00E472DF /* zip_get_encryption_implementation.c */; }; + 5876AC2E1BA250E900AF093E /* zip_get_num_entries.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A51B99A24F00E472DF /* zip_get_num_entries.c */; }; + 5876AC2F1BA250E900AF093E /* zip_io_util.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A61B99A24F00E472DF /* zip_io_util.c */; }; + 5876AC301BA250E900AF093E /* zip_set_default_password.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A71B99A24F00E472DF /* zip_set_default_password.c */; }; + 5876AC311BA250E900AF093E /* zip_set_file_compression.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A81B99A24F00E472DF /* zip_set_file_compression.c */; }; + 5876AC321BA250E900AF093E /* zip_source_begin_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A91B99A24F00E472DF /* zip_source_begin_write.c */; }; + 5876AC331BA250E900AF093E /* zip_source_call.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0AA1B99A24F00E472DF /* zip_source_call.c */; }; + 5876AC341BA250E900AF093E /* zip_source_close.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0AB1B99A24F00E472DF /* zip_source_close.c */; }; + 5876AC351BA250E900AF093E /* zip_source_commit_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0AC1B99A24F00E472DF /* zip_source_commit_write.c */; }; + 5876AC361BA250E900AF093E /* zip_source_crc.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0AD1B99A24F00E472DF /* zip_source_crc.c */; }; + 5876AC371BA250E900AF093E /* zip_source_deflate.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0AE1B99A24F00E472DF /* zip_source_deflate.c */; }; + 5876AC381BA250E900AF093E /* zip_source_error.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0AF1B99A24F00E472DF /* zip_source_error.c */; }; + 5876AC391BA250E900AF093E /* zip_source_is_deleted.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B01B99A24F00E472DF /* zip_source_is_deleted.c */; }; + 5876AC3A1BA250E900AF093E /* zip_source_layered.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B11B99A24F00E472DF /* zip_source_layered.c */; }; + 5876AC3B1BA250FF00AF093E /* zip_source_open.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B21B99A24F00E472DF /* zip_source_open.c */; }; + 5876AC3C1BA250FF00AF093E /* zip_source_pkware.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B31B99A24F00E472DF /* zip_source_pkware.c */; }; + 5876AC3D1BA250FF00AF093E /* zip_source_read.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B41B99A24F00E472DF /* zip_source_read.c */; }; + 5876AC3E1BA250FF00AF093E /* zip_source_remove.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B51B99A24F00E472DF /* zip_source_remove.c */; }; + 5876AC3F1BA250FF00AF093E /* zip_source_rollback_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B61B99A24F00E472DF /* zip_source_rollback_write.c */; }; + 5876AC401BA250FF00AF093E /* zip_source_seek_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B71B99A24F00E472DF /* zip_source_seek_write.c */; }; + 5876AC411BA250FF00AF093E /* zip_source_seek.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B81B99A24F00E472DF /* zip_source_seek.c */; }; + 5876AC421BA250FF00AF093E /* zip_source_stat.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B91B99A24F00E472DF /* zip_source_stat.c */; }; + 5876AC431BA250FF00AF093E /* zip_source_supports.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0BA1B99A24F00E472DF /* zip_source_supports.c */; }; + 5876AC441BA250FF00AF093E /* zip_source_tell_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0BB1B99A24F00E472DF /* zip_source_tell_write.c */; }; + 5876AC451BA250FF00AF093E /* zip_source_tell.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0BC1B99A24F00E472DF /* zip_source_tell.c */; }; + 5876AC461BA250FF00AF093E /* zip_source_window.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0C11B99A24F00E472DF /* zip_source_window.c */; }; + 5876AC471BA250FF00AF093E /* zip_source_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0C21B99A24F00E472DF /* zip_source_write.c */; }; + 5876AC481BA250FF00AF093E /* zip_source_zip_new.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0C31B99A24F00E472DF /* zip_source_zip_new.c */; }; + 5876AC491BA250FF00AF093E /* zip_string.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0C41B99A24F00E472DF /* zip_string.c */; }; + 5876AC4A1BA250FF00AF093E /* zip_utf-8.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0C51B99A24F00E472DF /* zip_utf-8.c */; }; 588D24201A02EF8F006A92BB /* PassThroughFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 588D241E1A02EF8F006A92BB /* PassThroughFilter.cpp */; }; 588D24211A02EF8F006A92BB /* PassThroughFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 588D241E1A02EF8F006A92BB /* PassThroughFilter.cpp */; }; 588D24221A02EF8F006A92BB /* PassThroughFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 588D241F1A02EF8F006A92BB /* PassThroughFilter.h */; }; + 8335A0C81B99A24F00E472DF /* zip_add_entry.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0911B99A24F00E472DF /* zip_add_entry.c */; }; + 8335A0C91B99A24F00E472DF /* zip_buffer.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0921B99A24F00E472DF /* zip_buffer.c */; }; + 8335A0CA1B99A24F00E472DF /* zip_dir_add.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0931B99A24F00E472DF /* zip_dir_add.c */; }; + 8335A0CB1B99A24F00E472DF /* zip_discard.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0941B99A24F00E472DF /* zip_discard.c */; }; + 8335A0CC1B99A24F00E472DF /* zip_entry.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0951B99A24F00E472DF /* zip_entry.c */; }; + 8335A0CD1B99A24F00E472DF /* zip_extra_field_api.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0961B99A24F00E472DF /* zip_extra_field_api.c */; }; + 8335A0CE1B99A24F00E472DF /* zip_extra_field.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0971B99A24F00E472DF /* zip_extra_field.c */; }; + 8335A0CF1B99A24F00E472DF /* zip_fdopen.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0981B99A24F00E472DF /* zip_fdopen.c */; }; + 8335A0D01B99A24F00E472DF /* zip_file_add.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0991B99A24F00E472DF /* zip_file_add.c */; }; + 8335A0D11B99A24F00E472DF /* zip_file_get_comment.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A09A1B99A24F00E472DF /* zip_file_get_comment.c */; }; + 8335A0D21B99A24F00E472DF /* zip_file_get_external_attributes.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A09B1B99A24F00E472DF /* zip_file_get_external_attributes.c */; }; + 8335A0D31B99A24F00E472DF /* zip_file_rename.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A09C1B99A24F00E472DF /* zip_file_rename.c */; }; + 8335A0D41B99A24F00E472DF /* zip_file_replace.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A09D1B99A24F00E472DF /* zip_file_replace.c */; }; + 8335A0D51B99A24F00E472DF /* zip_file_set_comment.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A09E1B99A24F00E472DF /* zip_file_set_comment.c */; }; + 8335A0D61B99A24F00E472DF /* zip_file_set_external_attributes.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A09F1B99A24F00E472DF /* zip_file_set_external_attributes.c */; }; + 8335A0D71B99A24F00E472DF /* zip_file_set_mtime.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A01B99A24F00E472DF /* zip_file_set_mtime.c */; }; + 8335A0D81B99A24F00E472DF /* zip_fopen_encrypted.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A11B99A24F00E472DF /* zip_fopen_encrypted.c */; }; + 8335A0D91B99A24F00E472DF /* zip_fopen_index_encrypted.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A21B99A24F00E472DF /* zip_fopen_index_encrypted.c */; }; + 8335A0DA1B99A24F00E472DF /* zip_get_compression_implementation.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A31B99A24F00E472DF /* zip_get_compression_implementation.c */; }; + 8335A0DB1B99A24F00E472DF /* zip_get_encryption_implementation.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A41B99A24F00E472DF /* zip_get_encryption_implementation.c */; }; + 8335A0DC1B99A24F00E472DF /* zip_get_num_entries.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A51B99A24F00E472DF /* zip_get_num_entries.c */; }; + 8335A0DD1B99A25000E472DF /* zip_io_util.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A61B99A24F00E472DF /* zip_io_util.c */; }; + 8335A0DE1B99A25000E472DF /* zip_set_default_password.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A71B99A24F00E472DF /* zip_set_default_password.c */; }; + 8335A0DF1B99A25000E472DF /* zip_set_file_compression.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A81B99A24F00E472DF /* zip_set_file_compression.c */; }; + 8335A0E01B99A25000E472DF /* zip_source_begin_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0A91B99A24F00E472DF /* zip_source_begin_write.c */; }; + 8335A0E11B99A25000E472DF /* zip_source_call.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0AA1B99A24F00E472DF /* zip_source_call.c */; }; + 8335A0E21B99A25000E472DF /* zip_source_close.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0AB1B99A24F00E472DF /* zip_source_close.c */; }; + 8335A0E31B99A25000E472DF /* zip_source_commit_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0AC1B99A24F00E472DF /* zip_source_commit_write.c */; }; + 8335A0E41B99A25000E472DF /* zip_source_crc.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0AD1B99A24F00E472DF /* zip_source_crc.c */; }; + 8335A0E51B99A25000E472DF /* zip_source_deflate.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0AE1B99A24F00E472DF /* zip_source_deflate.c */; }; + 8335A0E61B99A25000E472DF /* zip_source_error.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0AF1B99A24F00E472DF /* zip_source_error.c */; }; + 8335A0E71B99A25000E472DF /* zip_source_is_deleted.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B01B99A24F00E472DF /* zip_source_is_deleted.c */; }; + 8335A0E81B99A25000E472DF /* zip_source_layered.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B11B99A24F00E472DF /* zip_source_layered.c */; }; + 8335A0E91B99A25000E472DF /* zip_source_open.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B21B99A24F00E472DF /* zip_source_open.c */; }; + 8335A0EA1B99A25000E472DF /* zip_source_pkware.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B31B99A24F00E472DF /* zip_source_pkware.c */; }; + 8335A0EB1B99A25000E472DF /* zip_source_read.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B41B99A24F00E472DF /* zip_source_read.c */; }; + 8335A0EC1B99A25000E472DF /* zip_source_remove.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B51B99A24F00E472DF /* zip_source_remove.c */; }; + 8335A0ED1B99A25000E472DF /* zip_source_rollback_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B61B99A24F00E472DF /* zip_source_rollback_write.c */; }; + 8335A0EE1B99A25000E472DF /* zip_source_seek_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B71B99A24F00E472DF /* zip_source_seek_write.c */; }; + 8335A0EF1B99A25000E472DF /* zip_source_seek.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B81B99A24F00E472DF /* zip_source_seek.c */; }; + 8335A0F01B99A25000E472DF /* zip_source_stat.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0B91B99A24F00E472DF /* zip_source_stat.c */; }; + 8335A0F11B99A25000E472DF /* zip_source_supports.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0BA1B99A24F00E472DF /* zip_source_supports.c */; }; + 8335A0F21B99A25000E472DF /* zip_source_tell_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0BB1B99A24F00E472DF /* zip_source_tell_write.c */; }; + 8335A0F31B99A25000E472DF /* zip_source_tell.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0BC1B99A24F00E472DF /* zip_source_tell.c */; }; + 8335A0F81B99A25000E472DF /* zip_source_window.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0C11B99A24F00E472DF /* zip_source_window.c */; }; + 8335A0F91B99A25000E472DF /* zip_source_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0C21B99A24F00E472DF /* zip_source_write.c */; }; + 8335A0FA1B99A25000E472DF /* zip_source_zip_new.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0C31B99A24F00E472DF /* zip_source_zip_new.c */; }; + 8335A0FB1B99A25000E472DF /* zip_string.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0C41B99A24F00E472DF /* zip_string.c */; }; + 8335A0FC1B99A25000E472DF /* zip_utf-8.c in Sources */ = {isa = PBXBuildFile; fileRef = 8335A0C51B99A24F00E472DF /* zip_utf-8.c */; }; + 8335A0FD1B99A25000E472DF /* zipconf.h in Headers */ = {isa = PBXBuildFile; fileRef = 8335A0C61B99A24F00E472DF /* zipconf.h */; }; 834B09011A0BD015006AEB12 /* filter_chain_byte_stream_range.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A250D33BAFB8E8EAEF5FE5B5 /* filter_chain_byte_stream_range.cpp */; }; 834B09021A0BD018006AEB12 /* filter_chain_byte_stream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A250DFDBD90C7E9C632B1E00 /* filter_chain_byte_stream.cpp */; }; 850B1AE916A75AC600619C3C /* TestData in CopyFiles */ = {isa = PBXBuildFile; fileRef = 850B1AE816A75AB000619C3C /* TestData */; }; @@ -98,10 +197,6 @@ AB95448A16BAF11000EFD2FD /* object_preprocessor.h in Headers */ = {isa = PBXBuildFile; fileRef = AB95448716BAF11000EFD2FD /* object_preprocessor.h */; }; AB95448C16BC28F300EFD2FD /* switch_preproc_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB95448B16BC28F300EFD2FD /* switch_preproc_tests.cpp */; }; AB95448E16BC539200EFD2FD /* object_preproc_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB95448D16BC539200EFD2FD /* object_preproc_tests.cpp */; }; - AB95FABB181ACB09007D8DAC /* zip_fseek.c in Sources */ = {isa = PBXBuildFile; fileRef = AB95FABA181ACB09007D8DAC /* zip_fseek.c */; }; - AB95FABC181ACB09007D8DAC /* zip_fseek.c in Sources */ = {isa = PBXBuildFile; fileRef = AB95FABA181ACB09007D8DAC /* zip_fseek.c */; }; - AB95FABE181ADC11007D8DAC /* zip_ftell.c in Sources */ = {isa = PBXBuildFile; fileRef = AB95FABD181ADC11007D8DAC /* zip_ftell.c */; }; - AB95FABF181ADC11007D8DAC /* zip_ftell.c in Sources */ = {isa = PBXBuildFile; fileRef = AB95FABD181ADC11007D8DAC /* zip_ftell.c */; }; AB976C4A173443DD00AC26CF /* property.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB976C48173443DD00AC26CF /* property.cpp */; }; AB976C4B173443DD00AC26CF /* property.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB976C48173443DD00AC26CF /* property.cpp */; }; AB976C4C173443DD00AC26CF /* property.h in Headers */ = {isa = PBXBuildFile; fileRef = AB976C49173443DD00AC26CF /* property.h */; }; @@ -196,8 +291,6 @@ ABA4BB0A16ADF64400161B77 /* zip_close.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB11656863300CFC651 /* zip_close.c */; }; ABA4BB0B16ADF64400161B77 /* zip_delete.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB21656863300CFC651 /* zip_delete.c */; }; ABA4BB0C16ADF64400161B77 /* zip_dirent.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB31656863300CFC651 /* zip_dirent.c */; }; - ABA4BB0D16ADF64400161B77 /* zip_entry_free.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB41656863300CFC651 /* zip_entry_free.c */; }; - ABA4BB0E16ADF64400161B77 /* zip_entry_new.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB51656863300CFC651 /* zip_entry_new.c */; }; ABA4BB0F16ADF64400161B77 /* zip_err_str.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB61656863300CFC651 /* zip_err_str.c */; }; ABA4BB1016ADF64400161B77 /* zip_error.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB71656863300CFC651 /* zip_error.c */; }; ABA4BB1116ADF64400161B77 /* zip_error_clear.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB81656863300CFC651 /* zip_error_clear.c */; }; @@ -214,7 +307,6 @@ ABA4BB1C16ADF64400161B77 /* zip_fopen.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FC31656863300CFC651 /* zip_fopen.c */; }; ABA4BB1D16ADF64400161B77 /* zip_fopen_index.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FC41656863300CFC651 /* zip_fopen_index.c */; }; ABA4BB1E16ADF64400161B77 /* zip_fread.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FC51656863300CFC651 /* zip_fread.c */; }; - ABA4BB1F16ADF64400161B77 /* zip_free.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FC61656863300CFC651 /* zip_free.c */; }; ABA4BB2016ADF64400161B77 /* zip_get_archive_comment.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FC71656863300CFC651 /* zip_get_archive_comment.c */; }; ABA4BB2116ADF64400161B77 /* zip_get_archive_flag.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FC81656863300CFC651 /* zip_get_archive_flag.c */; }; ABA4BB2216ADF64400161B77 /* zip_get_file_comment.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FC91656863300CFC651 /* zip_get_file_comment.c */; }; @@ -303,8 +395,6 @@ ABB18FEA1656863300CFC651 /* zip_close.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB11656863300CFC651 /* zip_close.c */; }; ABB18FEB1656863300CFC651 /* zip_delete.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB21656863300CFC651 /* zip_delete.c */; }; ABB18FEC1656863300CFC651 /* zip_dirent.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB31656863300CFC651 /* zip_dirent.c */; }; - ABB18FED1656863300CFC651 /* zip_entry_free.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB41656863300CFC651 /* zip_entry_free.c */; }; - ABB18FEE1656863300CFC651 /* zip_entry_new.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB51656863300CFC651 /* zip_entry_new.c */; }; ABB18FEF1656863300CFC651 /* zip_err_str.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB61656863300CFC651 /* zip_err_str.c */; }; ABB18FF01656863300CFC651 /* zip_error.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB71656863300CFC651 /* zip_error.c */; }; ABB18FF11656863300CFC651 /* zip_error_clear.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FB81656863300CFC651 /* zip_error_clear.c */; }; @@ -321,7 +411,6 @@ ABB18FFC1656863300CFC651 /* zip_fopen.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FC31656863300CFC651 /* zip_fopen.c */; }; ABB18FFD1656863300CFC651 /* zip_fopen_index.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FC41656863300CFC651 /* zip_fopen_index.c */; }; ABB18FFE1656863300CFC651 /* zip_fread.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FC51656863300CFC651 /* zip_fread.c */; }; - ABB18FFF1656863300CFC651 /* zip_free.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FC61656863300CFC651 /* zip_free.c */; }; ABB190001656863300CFC651 /* zip_get_archive_comment.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FC71656863300CFC651 /* zip_get_archive_comment.c */; }; ABB190011656863300CFC651 /* zip_get_archive_flag.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FC81656863300CFC651 /* zip_get_archive_flag.c */; }; ABB190021656863300CFC651 /* zip_get_file_comment.c in Sources */ = {isa = PBXBuildFile; fileRef = ABB18FC91656863300CFC651 /* zip_get_file_comment.c */; }; @@ -447,6 +536,56 @@ 1EFA3ACA17AB0BEF003A4BC2 /* filter_manager_impl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = filter_manager_impl.cpp; sourceTree = ""; }; 588D241E1A02EF8F006A92BB /* PassThroughFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PassThroughFilter.cpp; sourceTree = ""; }; 588D241F1A02EF8F006A92BB /* PassThroughFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PassThroughFilter.h; sourceTree = ""; }; + 8335A0911B99A24F00E472DF /* zip_add_entry.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_add_entry.c; sourceTree = ""; }; + 8335A0921B99A24F00E472DF /* zip_buffer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_buffer.c; sourceTree = ""; }; + 8335A0931B99A24F00E472DF /* zip_dir_add.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_dir_add.c; sourceTree = ""; }; + 8335A0941B99A24F00E472DF /* zip_discard.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_discard.c; sourceTree = ""; }; + 8335A0951B99A24F00E472DF /* zip_entry.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_entry.c; sourceTree = ""; }; + 8335A0961B99A24F00E472DF /* zip_extra_field_api.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_extra_field_api.c; sourceTree = ""; }; + 8335A0971B99A24F00E472DF /* zip_extra_field.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_extra_field.c; sourceTree = ""; }; + 8335A0981B99A24F00E472DF /* zip_fdopen.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_fdopen.c; sourceTree = ""; }; + 8335A0991B99A24F00E472DF /* zip_file_add.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_file_add.c; sourceTree = ""; }; + 8335A09A1B99A24F00E472DF /* zip_file_get_comment.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_file_get_comment.c; sourceTree = ""; }; + 8335A09B1B99A24F00E472DF /* zip_file_get_external_attributes.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_file_get_external_attributes.c; sourceTree = ""; }; + 8335A09C1B99A24F00E472DF /* zip_file_rename.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_file_rename.c; sourceTree = ""; }; + 8335A09D1B99A24F00E472DF /* zip_file_replace.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_file_replace.c; sourceTree = ""; }; + 8335A09E1B99A24F00E472DF /* zip_file_set_comment.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_file_set_comment.c; sourceTree = ""; }; + 8335A09F1B99A24F00E472DF /* zip_file_set_external_attributes.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_file_set_external_attributes.c; sourceTree = ""; }; + 8335A0A01B99A24F00E472DF /* zip_file_set_mtime.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_file_set_mtime.c; sourceTree = ""; }; + 8335A0A11B99A24F00E472DF /* zip_fopen_encrypted.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_fopen_encrypted.c; sourceTree = ""; }; + 8335A0A21B99A24F00E472DF /* zip_fopen_index_encrypted.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_fopen_index_encrypted.c; sourceTree = ""; }; + 8335A0A31B99A24F00E472DF /* zip_get_compression_implementation.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_get_compression_implementation.c; sourceTree = ""; }; + 8335A0A41B99A24F00E472DF /* zip_get_encryption_implementation.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_get_encryption_implementation.c; sourceTree = ""; }; + 8335A0A51B99A24F00E472DF /* zip_get_num_entries.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_get_num_entries.c; sourceTree = ""; }; + 8335A0A61B99A24F00E472DF /* zip_io_util.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_io_util.c; sourceTree = ""; }; + 8335A0A71B99A24F00E472DF /* zip_set_default_password.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_set_default_password.c; sourceTree = ""; }; + 8335A0A81B99A24F00E472DF /* zip_set_file_compression.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_set_file_compression.c; sourceTree = ""; }; + 8335A0A91B99A24F00E472DF /* zip_source_begin_write.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_begin_write.c; sourceTree = ""; }; + 8335A0AA1B99A24F00E472DF /* zip_source_call.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_call.c; sourceTree = ""; }; + 8335A0AB1B99A24F00E472DF /* zip_source_close.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_close.c; sourceTree = ""; }; + 8335A0AC1B99A24F00E472DF /* zip_source_commit_write.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_commit_write.c; sourceTree = ""; }; + 8335A0AD1B99A24F00E472DF /* zip_source_crc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_crc.c; sourceTree = ""; }; + 8335A0AE1B99A24F00E472DF /* zip_source_deflate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_deflate.c; sourceTree = ""; }; + 8335A0AF1B99A24F00E472DF /* zip_source_error.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_error.c; sourceTree = ""; }; + 8335A0B01B99A24F00E472DF /* zip_source_is_deleted.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_is_deleted.c; sourceTree = ""; }; + 8335A0B11B99A24F00E472DF /* zip_source_layered.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_layered.c; sourceTree = ""; }; + 8335A0B21B99A24F00E472DF /* zip_source_open.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_open.c; sourceTree = ""; }; + 8335A0B31B99A24F00E472DF /* zip_source_pkware.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_pkware.c; sourceTree = ""; }; + 8335A0B41B99A24F00E472DF /* zip_source_read.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_read.c; sourceTree = ""; }; + 8335A0B51B99A24F00E472DF /* zip_source_remove.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_remove.c; sourceTree = ""; }; + 8335A0B61B99A24F00E472DF /* zip_source_rollback_write.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_rollback_write.c; sourceTree = ""; }; + 8335A0B71B99A24F00E472DF /* zip_source_seek_write.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_seek_write.c; sourceTree = ""; }; + 8335A0B81B99A24F00E472DF /* zip_source_seek.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_seek.c; sourceTree = ""; }; + 8335A0B91B99A24F00E472DF /* zip_source_stat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_stat.c; sourceTree = ""; }; + 8335A0BA1B99A24F00E472DF /* zip_source_supports.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_supports.c; sourceTree = ""; }; + 8335A0BB1B99A24F00E472DF /* zip_source_tell_write.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_tell_write.c; sourceTree = ""; }; + 8335A0BC1B99A24F00E472DF /* zip_source_tell.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_tell.c; sourceTree = ""; }; + 8335A0C11B99A24F00E472DF /* zip_source_window.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_window.c; sourceTree = ""; }; + 8335A0C21B99A24F00E472DF /* zip_source_write.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_write.c; sourceTree = ""; }; + 8335A0C31B99A24F00E472DF /* zip_source_zip_new.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_source_zip_new.c; sourceTree = ""; }; + 8335A0C41B99A24F00E472DF /* zip_string.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_string.c; sourceTree = ""; }; + 8335A0C51B99A24F00E472DF /* zip_utf-8.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "zip_utf-8.c"; sourceTree = ""; }; + 8335A0C61B99A24F00E472DF /* zipconf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = zipconf.h; sourceTree = ""; }; 850B1AE816A75AB000619C3C /* TestData */ = {isa = PBXFileReference; lastKnownFileType = folder; name = TestData; path = ../../TestData; sourceTree = ""; }; A250D0D74FF2AD1AB643D2FA /* media-overlays_smil_data.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "media-overlays_smil_data.h"; sourceTree = ""; }; A250D119DCB804938466E3D6 /* media-overlays_smil_model.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "media-overlays_smil_model.cpp"; sourceTree = ""; }; @@ -524,8 +663,6 @@ AB95448716BAF11000EFD2FD /* object_preprocessor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = object_preprocessor.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; AB95448B16BC28F300EFD2FD /* switch_preproc_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = switch_preproc_tests.cpp; sourceTree = ""; }; AB95448D16BC539200EFD2FD /* object_preproc_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = object_preproc_tests.cpp; sourceTree = ""; }; - AB95FABA181ACB09007D8DAC /* zip_fseek.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_fseek.c; sourceTree = ""; }; - AB95FABD181ADC11007D8DAC /* zip_ftell.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_ftell.c; sourceTree = ""; }; AB95FAC0181ADD7D007D8DAC /* xmlstring.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xmlstring.h; sourceTree = ""; }; AB976C48173443DD00AC26CF /* property.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = property.cpp; sourceTree = ""; }; AB976C49173443DD00AC26CF /* property.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = property.h; sourceTree = ""; }; @@ -820,8 +957,6 @@ ABB18FB11656863300CFC651 /* zip_close.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_close.c; sourceTree = ""; }; ABB18FB21656863300CFC651 /* zip_delete.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_delete.c; sourceTree = ""; }; ABB18FB31656863300CFC651 /* zip_dirent.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_dirent.c; sourceTree = ""; }; - ABB18FB41656863300CFC651 /* zip_entry_free.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_entry_free.c; sourceTree = ""; }; - ABB18FB51656863300CFC651 /* zip_entry_new.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_entry_new.c; sourceTree = ""; }; ABB18FB61656863300CFC651 /* zip_err_str.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_err_str.c; sourceTree = ""; }; ABB18FB71656863300CFC651 /* zip_error.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_error.c; sourceTree = ""; }; ABB18FB81656863300CFC651 /* zip_error_clear.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_error_clear.c; sourceTree = ""; }; @@ -838,7 +973,6 @@ ABB18FC31656863300CFC651 /* zip_fopen.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_fopen.c; sourceTree = ""; }; ABB18FC41656863300CFC651 /* zip_fopen_index.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_fopen_index.c; sourceTree = ""; }; ABB18FC51656863300CFC651 /* zip_fread.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_fread.c; sourceTree = ""; }; - ABB18FC61656863300CFC651 /* zip_free.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_free.c; sourceTree = ""; }; ABB18FC71656863300CFC651 /* zip_get_archive_comment.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_get_archive_comment.c; sourceTree = ""; }; ABB18FC81656863300CFC651 /* zip_get_archive_flag.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_get_archive_flag.c; sourceTree = ""; }; ABB18FC91656863300CFC651 /* zip_get_file_comment.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_get_file_comment.c; sourceTree = ""; }; @@ -1655,6 +1789,56 @@ ABB18FAB1656863300CFC651 /* libzip */ = { isa = PBXGroup; children = ( + 8335A0911B99A24F00E472DF /* zip_add_entry.c */, + 8335A0921B99A24F00E472DF /* zip_buffer.c */, + 8335A0931B99A24F00E472DF /* zip_dir_add.c */, + 8335A0941B99A24F00E472DF /* zip_discard.c */, + 8335A0951B99A24F00E472DF /* zip_entry.c */, + 8335A0961B99A24F00E472DF /* zip_extra_field_api.c */, + 8335A0971B99A24F00E472DF /* zip_extra_field.c */, + 8335A0981B99A24F00E472DF /* zip_fdopen.c */, + 8335A0991B99A24F00E472DF /* zip_file_add.c */, + 8335A09A1B99A24F00E472DF /* zip_file_get_comment.c */, + 8335A09B1B99A24F00E472DF /* zip_file_get_external_attributes.c */, + 8335A09C1B99A24F00E472DF /* zip_file_rename.c */, + 8335A09D1B99A24F00E472DF /* zip_file_replace.c */, + 8335A09E1B99A24F00E472DF /* zip_file_set_comment.c */, + 8335A09F1B99A24F00E472DF /* zip_file_set_external_attributes.c */, + 8335A0A01B99A24F00E472DF /* zip_file_set_mtime.c */, + 8335A0A11B99A24F00E472DF /* zip_fopen_encrypted.c */, + 8335A0A21B99A24F00E472DF /* zip_fopen_index_encrypted.c */, + 8335A0A31B99A24F00E472DF /* zip_get_compression_implementation.c */, + 8335A0A41B99A24F00E472DF /* zip_get_encryption_implementation.c */, + 8335A0A51B99A24F00E472DF /* zip_get_num_entries.c */, + 8335A0A61B99A24F00E472DF /* zip_io_util.c */, + 8335A0A71B99A24F00E472DF /* zip_set_default_password.c */, + 8335A0A81B99A24F00E472DF /* zip_set_file_compression.c */, + 8335A0A91B99A24F00E472DF /* zip_source_begin_write.c */, + 8335A0AA1B99A24F00E472DF /* zip_source_call.c */, + 8335A0AB1B99A24F00E472DF /* zip_source_close.c */, + 8335A0AC1B99A24F00E472DF /* zip_source_commit_write.c */, + 8335A0AD1B99A24F00E472DF /* zip_source_crc.c */, + 8335A0AE1B99A24F00E472DF /* zip_source_deflate.c */, + 8335A0AF1B99A24F00E472DF /* zip_source_error.c */, + 8335A0B01B99A24F00E472DF /* zip_source_is_deleted.c */, + 8335A0B11B99A24F00E472DF /* zip_source_layered.c */, + 8335A0B21B99A24F00E472DF /* zip_source_open.c */, + 8335A0B31B99A24F00E472DF /* zip_source_pkware.c */, + 8335A0B41B99A24F00E472DF /* zip_source_read.c */, + 8335A0B51B99A24F00E472DF /* zip_source_remove.c */, + 8335A0B61B99A24F00E472DF /* zip_source_rollback_write.c */, + 8335A0B71B99A24F00E472DF /* zip_source_seek_write.c */, + 8335A0B81B99A24F00E472DF /* zip_source_seek.c */, + 8335A0B91B99A24F00E472DF /* zip_source_stat.c */, + 8335A0BA1B99A24F00E472DF /* zip_source_supports.c */, + 8335A0BB1B99A24F00E472DF /* zip_source_tell_write.c */, + 8335A0BC1B99A24F00E472DF /* zip_source_tell.c */, + 8335A0C11B99A24F00E472DF /* zip_source_window.c */, + 8335A0C21B99A24F00E472DF /* zip_source_write.c */, + 8335A0C31B99A24F00E472DF /* zip_source_zip_new.c */, + 8335A0C41B99A24F00E472DF /* zip_string.c */, + 8335A0C51B99A24F00E472DF /* zip_utf-8.c */, + 8335A0C61B99A24F00E472DF /* zipconf.h */, ABB18FAC1656863300CFC651 /* Config.h */, ABB18FAD1656863300CFC651 /* mkstemp.c */, ABB18FAE1656863300CFC651 /* zip.h */, @@ -1663,8 +1847,6 @@ ABB18FB11656863300CFC651 /* zip_close.c */, ABB18FB21656863300CFC651 /* zip_delete.c */, ABB18FB31656863300CFC651 /* zip_dirent.c */, - ABB18FB41656863300CFC651 /* zip_entry_free.c */, - ABB18FB51656863300CFC651 /* zip_entry_new.c */, ABB18FB61656863300CFC651 /* zip_err_str.c */, ABB18FB71656863300CFC651 /* zip_error.c */, ABB18FB81656863300CFC651 /* zip_error_clear.c */, @@ -1681,9 +1863,6 @@ ABB18FC31656863300CFC651 /* zip_fopen.c */, ABB18FC41656863300CFC651 /* zip_fopen_index.c */, ABB18FC51656863300CFC651 /* zip_fread.c */, - AB95FABA181ACB09007D8DAC /* zip_fseek.c */, - AB95FABD181ADC11007D8DAC /* zip_ftell.c */, - ABB18FC61656863300CFC651 /* zip_free.c */, ABB18FC71656863300CFC651 /* zip_get_archive_comment.c */, ABB18FC81656863300CFC651 /* zip_get_archive_flag.c */, ABB18FC91656863300CFC651 /* zip_get_file_comment.c */, @@ -1853,6 +2032,7 @@ ABA4BAA916A7414000161B77 /* url_util_internal.h in Headers */, ABA4BAB116A7518B00161B77 /* url_canon_cpp11.h in Headers */, AB95447F16B9730B00EFD2FD /* content_handler.h in Headers */, + 8335A0FD1B99A25000E472DF /* zipconf.h in Headers */, AB95448516BAD32000EFD2FD /* switch_preprocessor.h in Headers */, AB95448A16BAF11000EFD2FD /* object_preprocessor.h in Headers */, ABA88FC016C062BF00F2014B /* media_support_info.h in Headers */, @@ -2029,6 +2209,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 5876AC281BA250E900AF093E /* zip_file_set_external_attributes.c in Sources */, ABA4BAEF16ADF64400161B77 /* string16.cc in Sources */, ABA4BAF016ADF64400161B77 /* gurl.cc in Sources */, AB5284D417CBC395003D7BBF /* CPUCacheUtils.c in Sources */, @@ -2037,32 +2218,47 @@ ABA4BAF516ADF64400161B77 /* url_canon_fileurl.cc in Sources */, ABA4BAF616ADF64400161B77 /* url_canon_host.cc in Sources */, ABA4BAF716ADF64400161B77 /* url_canon_cpp11.cc in Sources */, + 5876AC201BA250C500AF093E /* zip_extra_field.c in Sources */, ABA4BAF916ADF64400161B77 /* url_canon_internal.cc in Sources */, ABA4BAFA16ADF64400161B77 /* url_canon_ip.cc in Sources */, AB5284D517CBC47A003D7BBF /* CPUCacheUtils_i386.S in Sources */, + 5876AC2D1BA250E900AF093E /* zip_get_encryption_implementation.c in Sources */, ABA4BAFB16ADF64400161B77 /* url_canon_mailtourl.cc in Sources */, ABA4BAFC16ADF64400161B77 /* url_canon_path.cc in Sources */, + 5876AC3B1BA250FF00AF093E /* zip_source_open.c in Sources */, ABA4BAFD16ADF64400161B77 /* url_canon_pathurl.cc in Sources */, + 5876AC361BA250E900AF093E /* zip_source_crc.c in Sources */, ABA4BAFE16ADF64400161B77 /* url_canon_query.cc in Sources */, ABA4BAFF16ADF64400161B77 /* url_canon_relative.cc in Sources */, ABA4BB0016ADF64400161B77 /* url_canon_stdurl.cc in Sources */, 834B09011A0BD015006AEB12 /* filter_chain_byte_stream_range.cpp in Sources */, ABA4BB0216ADF64400161B77 /* url_parse.cc in Sources */, + 5876AC271BA250E900AF093E /* zip_file_set_comment.c in Sources */, ABA4BB0316ADF64400161B77 /* url_parse_file.cc in Sources */, ABA4BB0516ADF64400161B77 /* url_util.cc in Sources */, + 5876AC2F1BA250E900AF093E /* zip_io_util.c in Sources */, ABA4BB0716ADF64400161B77 /* mkstemp.c in Sources */, + 5876AC3C1BA250FF00AF093E /* zip_source_pkware.c in Sources */, + 5876AC1A1BA250B100AF093E /* zip_add_entry.c in Sources */, ABA4BB0816ADF64400161B77 /* zip_add.c in Sources */, + 5876AC3A1BA250E900AF093E /* zip_source_layered.c in Sources */, ABB394C31836808D00F19CA7 /* future.cpp in Sources */, + 5876AC431BA250FF00AF093E /* zip_source_supports.c in Sources */, ABA4BB0916ADF64400161B77 /* zip_add_dir.c in Sources */, + 5876AC381BA250E900AF093E /* zip_source_error.c in Sources */, + 5876AC411BA250FF00AF093E /* zip_source_seek.c in Sources */, + 5876AC251BA250D600AF093E /* zip_file_rename.c in Sources */, ABA4BB0A16ADF64400161B77 /* zip_close.c in Sources */, ABA4BB0B16ADF64400161B77 /* zip_delete.c in Sources */, AB5284D617CBC4DA003D7BBF /* CPUCacheUtils_x64.S in Sources */, ABA4BB0C16ADF64400161B77 /* zip_dirent.c in Sources */, - ABA4BB0D16ADF64400161B77 /* zip_entry_free.c in Sources */, - ABA4BB0E16ADF64400161B77 /* zip_entry_new.c in Sources */, + 5876AC2E1BA250E900AF093E /* zip_get_num_entries.c in Sources */, ABA4BB0F16ADF64400161B77 /* zip_err_str.c in Sources */, + 5876AC4A1BA250FF00AF093E /* zip_utf-8.c in Sources */, ABA4BB1016ADF64400161B77 /* zip_error.c in Sources */, ABA4BB1116ADF64400161B77 /* zip_error_clear.c in Sources */, + 5876AC481BA250FF00AF093E /* zip_source_zip_new.c in Sources */, + 5876AC291BA250E900AF093E /* zip_file_set_mtime.c in Sources */, AB5284DC17CCDF8E003D7BBF /* filter_chain.cpp in Sources */, ABA4BB1216ADF64400161B77 /* zip_error_get.c in Sources */, ABA4BB1316ADF64400161B77 /* zip_error_get_sys_type.c in Sources */, @@ -2078,18 +2274,23 @@ ABA4BB1D16ADF64400161B77 /* zip_fopen_index.c in Sources */, ABA4BB1E16ADF64400161B77 /* zip_fread.c in Sources */, 588D24211A02EF8F006A92BB /* PassThroughFilter.cpp in Sources */, - ABA4BB1F16ADF64400161B77 /* zip_free.c in Sources */, + 5876AC1C1BA250B800AF093E /* zip_dir_add.c in Sources */, ABA4BB2016ADF64400161B77 /* zip_get_archive_comment.c in Sources */, ABA4BB2116ADF64400161B77 /* zip_get_archive_flag.c in Sources */, ABA4BB2216ADF64400161B77 /* zip_get_file_comment.c in Sources */, ABA4BB2316ADF64400161B77 /* zip_get_name.c in Sources */, ABA4BB2416ADF64400161B77 /* zip_get_num_files.c in Sources */, + 5876AC441BA250FF00AF093E /* zip_source_tell_write.c in Sources */, + 5876AC221BA250CC00AF093E /* zip_file_add.c in Sources */, ABA4BB2516ADF64400161B77 /* zip_memdup.c in Sources */, + 5876AC331BA250E900AF093E /* zip_source_call.c in Sources */, ABA4BB2616ADF64400161B77 /* zip_name_locate.c in Sources */, ABA4BB2716ADF64400161B77 /* zip_new.c in Sources */, ABA4BB2816ADF64400161B77 /* zip_open.c in Sources */, ABB39517183D21AC00F19CA7 /* path_help.cpp in Sources */, 834B09021A0BD018006AEB12 /* filter_chain_byte_stream.cpp in Sources */, + 5876AC341BA250E900AF093E /* zip_source_close.c in Sources */, + 5876AC301BA250E900AF093E /* zip_set_default_password.c in Sources */, ABA4BB2916ADF64400161B77 /* zip_rename.c in Sources */, ABA4BB2A16ADF64400161B77 /* zip_replace.c in Sources */, ABA4BB2B16ADF64400161B77 /* zip_set_archive_comment.c in Sources */, @@ -2097,9 +2298,10 @@ ABA4BB2D16ADF64400161B77 /* zip_set_file_comment.c in Sources */, ABA4BB2E16ADF64400161B77 /* zip_set_name.c in Sources */, ABA4BB2F16ADF64400161B77 /* zip_source_buffer.c in Sources */, - AB95FABC181ACB09007D8DAC /* zip_fseek.c in Sources */, ABA4BB3016ADF64400161B77 /* zip_source_file.c in Sources */, + 5876AC1F1BA250C200AF093E /* zip_extra_field_api.c in Sources */, ABA4BB3116ADF64400161B77 /* zip_source_filep.c in Sources */, + 5876AC471BA250FF00AF093E /* zip_source_write.c in Sources */, ABA4BB3216ADF64400161B77 /* zip_source_free.c in Sources */, ABA4BB3316ADF64400161B77 /* zip_source_function.c in Sources */, ABB395221847FBAA00F19CA7 /* link.cpp in Sources */, @@ -2107,12 +2309,18 @@ ABA4BB3516ADF64400161B77 /* zip_stat.c in Sources */, ABA4BB3616ADF64400161B77 /* zip_stat_index.c in Sources */, ABA4BB3716ADF64400161B77 /* zip_stat_init.c in Sources */, + 5876AC321BA250E900AF093E /* zip_source_begin_write.c in Sources */, ABA4BB3816ADF64400161B77 /* zip_strerror.c in Sources */, ABA4BB3916ADF64400161B77 /* zip_unchange.c in Sources */, AB906FAF182C1DFF0097A7FE /* optional.cpp in Sources */, ABA4BB3A16ADF64400161B77 /* zip_unchange_all.c in Sources */, ABA4BB3B16ADF64400161B77 /* zip_unchange_archive.c in Sources */, + 5876AC351BA250E900AF093E /* zip_source_commit_write.c in Sources */, ABA4BB3C16ADF64400161B77 /* zip_unchange_data.c in Sources */, + 5876AC311BA250E900AF093E /* zip_set_file_compression.c in Sources */, + 5876AC1E1BA250BF00AF093E /* zip_entry.c in Sources */, + 5876AC461BA250FF00AF093E /* zip_source_window.c in Sources */, + 5876AC1D1BA250BB00AF093E /* zip_discard.c in Sources */, ABA4BB3D16ADF64400161B77 /* utfstring.cpp in Sources */, ABA4BB3E16ADF64400161B77 /* iri.cpp in Sources */, ABA4BB3F16ADF64400161B77 /* font_obfuscation.cpp in Sources */, @@ -2124,6 +2332,8 @@ ABA4BB4816ADF64400161B77 /* package.cpp in Sources */, ABA4BB4916ADF64400161B77 /* spine.cpp in Sources */, ABA4BB4A16ADF64400161B77 /* manifest.cpp in Sources */, + 5876AC3F1BA250FF00AF093E /* zip_source_rollback_write.c in Sources */, + 5876AC231BA250CF00AF093E /* zip_file_get_comment.c in Sources */, ABA4BB4C16ADF64400161B77 /* xpath_wrangler.cpp in Sources */, ABA4BB4D16ADF64400161B77 /* cfi.cpp in Sources */, ABA4BB4E16ADF64400161B77 /* encryption.cpp in Sources */, @@ -2131,23 +2341,33 @@ ABA4BB5016ADF64400161B77 /* archive.cpp in Sources */, ABA4BB5116ADF64400161B77 /* archive_xml.cpp in Sources */, ABA4BB5216ADF64400161B77 /* zip_archive.cpp in Sources */, + 5876AC1B1BA250B400AF093E /* zip_buffer.c in Sources */, + 5876AC2C1BA250E900AF093E /* zip_get_compression_implementation.c in Sources */, ABA4BB5316ADF64400161B77 /* document.cpp in Sources */, AB8C79751821A2160013054F /* credential_request.cpp in Sources */, - AB95FABF181ADC11007D8DAC /* zip_ftell.c in Sources */, ABA4BB5416ADF64400161B77 /* node.cpp in Sources */, + 5876AC451BA250FF00AF093E /* zip_source_tell.c in Sources */, ABA4BB5516ADF64400161B77 /* element.cpp in Sources */, ABA4BB5616ADF64400161B77 /* xpath.cpp in Sources */, + 5876AC391BA250E900AF093E /* zip_source_is_deleted.c in Sources */, ABA4BB5716ADF64400161B77 /* base.cpp in Sources */, ABA4BB5816ADF64400161B77 /* io.cpp in Sources */, + 5876AC2B1BA250E900AF093E /* zip_fopen_index_encrypted.c in Sources */, + 5876AC421BA250FF00AF093E /* zip_source_stat.c in Sources */, + 5876AC2A1BA250E900AF093E /* zip_fopen_encrypted.c in Sources */, ABA4BB5916ADF64400161B77 /* schema.cpp in Sources */, ABA4BB5A16ADF64400161B77 /* ns.cpp in Sources */, + 5876AC241BA250D300AF093E /* zip_file_get_external_attributes.c in Sources */, ABA4BB5B16ADF64400161B77 /* c14n.cpp in Sources */, AB95447E16B9730B00EFD2FD /* content_handler.cpp in Sources */, AB95448416BAD32000EFD2FD /* switch_preprocessor.cpp in Sources */, AB95448916BAF11000EFD2FD /* object_preprocessor.cpp in Sources */, ABA88FBF16C062BF00F2014B /* media_support_info.cpp in Sources */, + 5876AC211BA250C900AF093E /* zip_fdopen.c in Sources */, + 5876AC491BA250FF00AF093E /* zip_string.c in Sources */, ABA88FC416C1534900F2014B /* byte_stream.cpp in Sources */, 3418BA7D16C4151E009AA7EF /* ring_buffer.cpp in Sources */, + 5876AC371BA250E900AF093E /* zip_source_deflate.c in Sources */, ABB3951D1847E5FD00F19CA7 /* epub_collection.cpp in Sources */, AB8C7970182191A20013054F /* content_module_manager.cpp in Sources */, ABA88FD916C4415D00F2014B /* ios_get_progname.m in Sources */, @@ -2159,8 +2379,12 @@ AB976C591738057900AC26CF /* property_holder.cpp in Sources */, AB976C5F17393AD600AC26CF /* epub_locale.cpp in Sources */, AB976C651742D15500AC26CF /* error_handler.cpp in Sources */, + 5876AC261BA250E900AF093E /* zip_file_replace.c in Sources */, + 5876AC401BA250FF00AF093E /* zip_source_seek_write.c in Sources */, + 5876AC3D1BA250FF00AF093E /* zip_source_read.c in Sources */, 1ED0083C17A9B7F800819EBD /* byte_buffer.cpp in Sources */, 1ED0084517A9D6E800819EBD /* filter_manager.cpp in Sources */, + 5876AC3E1BA250FF00AF093E /* zip_source_remove.c in Sources */, A250D734238DE7D230862196 /* media-overlays_smil_model.cpp in Sources */, A250D59027FBAC9390F2D39C /* media-overlays_smil_data.cpp in Sources */, 1ED0084917A9DC6F00819EBD /* initialization.cpp in Sources */, @@ -2177,44 +2401,58 @@ AB718C04184CEEA900F86C6B /* xml_bridge_dtrace_probes.d in Sources */, ABB18FE81656863300CFC651 /* zip_add.c in Sources */, ABB18FE91656863300CFC651 /* zip_add_dir.c in Sources */, + 8335A0F01B99A25000E472DF /* zip_source_stat.c in Sources */, ABB18FEA1656863300CFC651 /* zip_close.c in Sources */, + 8335A0D81B99A24F00E472DF /* zip_fopen_encrypted.c in Sources */, + 8335A0DE1B99A25000E472DF /* zip_set_default_password.c in Sources */, ABB18FEB1656863300CFC651 /* zip_delete.c in Sources */, ABB18FEC1656863300CFC651 /* zip_dirent.c in Sources */, - ABB18FED1656863300CFC651 /* zip_entry_free.c in Sources */, - ABB18FEE1656863300CFC651 /* zip_entry_new.c in Sources */, AB5284CA17CBAB78003D7BBF /* CPUCacheUtils_i386.S in Sources */, + 8335A0CC1B99A24F00E472DF /* zip_entry.c in Sources */, + 8335A0DF1B99A25000E472DF /* zip_set_file_compression.c in Sources */, + 8335A0CF1B99A24F00E472DF /* zip_fdopen.c in Sources */, ABB18FEF1656863300CFC651 /* zip_err_str.c in Sources */, + 8335A0D41B99A24F00E472DF /* zip_file_replace.c in Sources */, ABB18FF01656863300CFC651 /* zip_error.c in Sources */, ABB18FF11656863300CFC651 /* zip_error_clear.c in Sources */, ABB18FF21656863300CFC651 /* zip_error_get.c in Sources */, ABB18FF31656863300CFC651 /* zip_error_get_sys_type.c in Sources */, + 8335A0D21B99A24F00E472DF /* zip_file_get_external_attributes.c in Sources */, ABB18FF41656863300CFC651 /* zip_error_strerror.c in Sources */, ABB18FF51656863300CFC651 /* zip_error_to_str.c in Sources */, ABB18FF61656863300CFC651 /* zip_fclose.c in Sources */, ABB18FF71656863300CFC651 /* zip_file_error_clear.c in Sources */, + 8335A0D91B99A24F00E472DF /* zip_fopen_index_encrypted.c in Sources */, ABB18FF81656863300CFC651 /* zip_file_error_get.c in Sources */, ABB18FF91656863300CFC651 /* zip_file_get_offset.c in Sources */, ABB18FFA1656863300CFC651 /* zip_file_strerror.c in Sources */, + 8335A0E11B99A25000E472DF /* zip_source_call.c in Sources */, ABB18FFB1656863300CFC651 /* zip_filerange_crc.c in Sources */, ABB18FFC1656863300CFC651 /* zip_fopen.c in Sources */, ABB18FFD1656863300CFC651 /* zip_fopen_index.c in Sources */, + 8335A0CD1B99A24F00E472DF /* zip_extra_field_api.c in Sources */, ABB395211847FBAA00F19CA7 /* link.cpp in Sources */, ABB18FFE1656863300CFC651 /* zip_fread.c in Sources */, ABB3951C1847E5FD00F19CA7 /* epub_collection.cpp in Sources */, - ABB18FFF1656863300CFC651 /* zip_free.c in Sources */, AB8C79741821A2160013054F /* credential_request.cpp in Sources */, ABB190001656863300CFC651 /* zip_get_archive_comment.c in Sources */, + 8335A0EB1B99A25000E472DF /* zip_source_read.c in Sources */, ABB190011656863300CFC651 /* zip_get_archive_flag.c in Sources */, AB8C796F182191A20013054F /* content_module_manager.cpp in Sources */, ABB190021656863300CFC651 /* zip_get_file_comment.c in Sources */, ABB190031656863300CFC651 /* zip_get_name.c in Sources */, ABB190041656863300CFC651 /* zip_get_num_files.c in Sources */, + 8335A0D51B99A24F00E472DF /* zip_file_set_comment.c in Sources */, + 8335A0E41B99A25000E472DF /* zip_source_crc.c in Sources */, + 8335A0C91B99A24F00E472DF /* zip_buffer.c in Sources */, ABB190051656863300CFC651 /* zip_memdup.c in Sources */, 588D24201A02EF8F006A92BB /* PassThroughFilter.cpp in Sources */, ABB190061656863300CFC651 /* zip_name_locate.c in Sources */, ABB190071656863300CFC651 /* zip_new.c in Sources */, + 8335A0F81B99A25000E472DF /* zip_source_window.c in Sources */, ABB190081656863300CFC651 /* zip_open.c in Sources */, ABB190091656863300CFC651 /* zip_rename.c in Sources */, + 8335A0CE1B99A24F00E472DF /* zip_extra_field.c in Sources */, ABB1900A1656863300CFC651 /* zip_replace.c in Sources */, ABB1900B1656863300CFC651 /* zip_set_archive_comment.c in Sources */, ABB1900C1656863300CFC651 /* zip_set_archive_flag.c in Sources */, @@ -2222,11 +2460,17 @@ ABB1900E1656863300CFC651 /* zip_set_name.c in Sources */, ABB1900F1656863300CFC651 /* zip_source_buffer.c in Sources */, ABB190101656863300CFC651 /* zip_source_file.c in Sources */, + 8335A0F21B99A25000E472DF /* zip_source_tell_write.c in Sources */, + 8335A0E51B99A25000E472DF /* zip_source_deflate.c in Sources */, ABB190111656863300CFC651 /* zip_source_filep.c in Sources */, ABB190121656863300CFC651 /* zip_source_free.c in Sources */, AB5284D317CBC395003D7BBF /* CPUCacheUtils.c in Sources */, + 8335A0D71B99A24F00E472DF /* zip_file_set_mtime.c in Sources */, ABB190131656863300CFC651 /* zip_source_function.c in Sources */, + 8335A0E61B99A25000E472DF /* zip_source_error.c in Sources */, ABB190141656863300CFC651 /* zip_source_zip.c in Sources */, + 8335A0E21B99A25000E472DF /* zip_source_close.c in Sources */, + 8335A0EF1B99A25000E472DF /* zip_source_seek.c in Sources */, ABB190151656863300CFC651 /* zip_stat.c in Sources */, ABB190161656863300CFC651 /* zip_stat_index.c in Sources */, ABB190171656863300CFC651 /* zip_stat_init.c in Sources */, @@ -2234,6 +2478,7 @@ ABB190191656863300CFC651 /* zip_unchange.c in Sources */, ABB1901A1656863300CFC651 /* zip_unchange_all.c in Sources */, ABB1901B1656863300CFC651 /* zip_unchange_archive.c in Sources */, + 8335A0DA1B99A24F00E472DF /* zip_get_compression_implementation.c in Sources */, ABB1901C1656863300CFC651 /* zip_unchange_data.c in Sources */, ABB190351656E82100CFC651 /* io.cpp in Sources */, ABB19039165A7E1000CFC651 /* schema.cpp in Sources */, @@ -2242,6 +2487,7 @@ ABB19049165ADD6A00CFC651 /* ns.cpp in Sources */, ABB1904C165C13FF00CFC651 /* base.cpp in Sources */, ABB19053165C1F9100CFC651 /* document.cpp in Sources */, + 8335A0C81B99A24F00E472DF /* zip_add_entry.c in Sources */, AB9B5B31165D816400F11069 /* c14n.cpp in Sources */, ABAB94B016652C200018D451 /* element.cpp in Sources */, ABAB94BF166560980018D451 /* zip_archive.cpp in Sources */, @@ -2250,18 +2496,22 @@ ABAB94C61666AC6D0018D451 /* container.cpp in Sources */, ABAB94CA1666AEA10018D451 /* package.cpp in Sources */, ABAB94D21667B6FD0018D451 /* archive_xml.cpp in Sources */, + 8335A0EE1B99A25000E472DF /* zip_source_seek_write.c in Sources */, ABF2D99F1667F7860036B8CA /* xpath_wrangler.cpp in Sources */, ABF2D9A716682E1E0036B8CA /* spine.cpp in Sources */, + 8335A0FA1B99A25000E472DF /* zip_source_zip_new.c in Sources */, ABF2D9AC1668301D0036B8CA /* manifest.cpp in Sources */, + 8335A0D61B99A24F00E472DF /* zip_file_set_external_attributes.c in Sources */, ABA38A8F16767CA400CB8EDB /* cfi.cpp in Sources */, - AB95FABE181ADC11007D8DAC /* zip_ftell.c in Sources */, ABA38A951677E21A00CB8EDB /* nav_point.cpp in Sources */, ABA38A991677E78F00CB8EDB /* nav_table.cpp in Sources */, ABA38A9E167A868100CB8EDB /* glossary.cpp in Sources */, ABA38AA6167BA6FA00CB8EDB /* library.cpp in Sources */, AB6AC7251684B93C000DE924 /* font_obfuscation.cpp in Sources */, + 8335A0F31B99A25000E472DF /* zip_source_tell.c in Sources */, AB6AC729168E05A3000DE924 /* encryption.cpp in Sources */, - AB95FABB181ACB09007D8DAC /* zip_fseek.c in Sources */, + 8335A0D11B99A24F00E472DF /* zip_file_get_comment.c in Sources */, + 8335A0FC1B99A25000E472DF /* zip_utf-8.c in Sources */, AB52850317CE6EE6003D7BBF /* executor.cpp in Sources */, AB6AC736169225E3000DE924 /* signatures.cpp in Sources */, ABA4BA0F16A5F1B100161B77 /* iri.cpp in Sources */, @@ -2272,22 +2522,37 @@ ABA4BA7116A7414000161B77 /* url_canon_filesystemurl.cc in Sources */, ABA4BA7316A7414000161B77 /* url_canon_fileurl.cc in Sources */, ABA4BA7516A7414000161B77 /* url_canon_host.cc in Sources */, + 8335A0DD1B99A25000E472DF /* zip_io_util.c in Sources */, ABA4BA7B16A7414000161B77 /* url_canon_internal.cc in Sources */, ABA4BA8116A7414000161B77 /* url_canon_ip.cc in Sources */, ABA4BA8516A7414000161B77 /* url_canon_mailtourl.cc in Sources */, ABA4BA8716A7414000161B77 /* url_canon_path.cc in Sources */, + 8335A0ED1B99A25000E472DF /* zip_source_rollback_write.c in Sources */, AB5284D017CBC0FA003D7BBF /* CPUCacheUtils_x64.S in Sources */, + 8335A0E71B99A25000E472DF /* zip_source_is_deleted.c in Sources */, + 8335A0E01B99A25000E472DF /* zip_source_begin_write.c in Sources */, ABA4BA8916A7414000161B77 /* url_canon_pathurl.cc in Sources */, + 8335A0CB1B99A24F00E472DF /* zip_discard.c in Sources */, ABB394C21836808D00F19CA7 /* future.cpp in Sources */, + 8335A0F11B99A25000E472DF /* zip_source_supports.c in Sources */, ABA4BA8B16A7414000161B77 /* url_canon_query.cc in Sources */, + 8335A0E81B99A25000E472DF /* zip_source_layered.c in Sources */, + 8335A0EA1B99A25000E472DF /* zip_source_pkware.c in Sources */, + 8335A0EC1B99A25000E472DF /* zip_source_remove.c in Sources */, + 8335A0D31B99A24F00E472DF /* zip_file_rename.c in Sources */, + 8335A0FB1B99A25000E472DF /* zip_string.c in Sources */, + 8335A0E91B99A25000E472DF /* zip_source_open.c in Sources */, ABA4BA8D16A7414000161B77 /* url_canon_relative.cc in Sources */, + 8335A0CA1B99A24F00E472DF /* zip_dir_add.c in Sources */, ABA4BA9116A7414000161B77 /* url_canon_stdurl.cc in Sources */, ABA4BA9916A7414000161B77 /* url_parse.cc in Sources */, + 8335A0D01B99A24F00E472DF /* zip_file_add.c in Sources */, ABA4BA9D16A7414000161B77 /* url_parse_file.cc in Sources */, ABA4BAA516A7414000161B77 /* url_util.cc in Sources */, ABA4BAAF16A7518B00161B77 /* url_canon_cpp11.cc in Sources */, AB95447D16B9730B00EFD2FD /* content_handler.cpp in Sources */, AB95448316BAD32000EFD2FD /* switch_preprocessor.cpp in Sources */, + 8335A0F91B99A25000E472DF /* zip_source_write.c in Sources */, A250D88B759805B9F12BB47A /* filter_chain_byte_stream.cpp in Sources */, A250D7BA140B24A6ECC960D8 /* filter_chain_byte_stream_range.cpp in Sources */, AB5284DB17CCDF8E003D7BBF /* filter_chain.cpp in Sources */, @@ -2295,9 +2560,12 @@ ABA88FBE16C062BF00F2014B /* media_support_info.cpp in Sources */, ABA88FC316C1534900F2014B /* byte_stream.cpp in Sources */, AB906FAE182C1DFF0097A7FE /* optional.cpp in Sources */, + 8335A0DC1B99A24F00E472DF /* zip_get_num_entries.c in Sources */, ABA88FD216C2B4ED00F2014B /* ring_buffer.cpp in Sources */, AB17B29E171301C800FD5917 /* run_loop_cf.cpp in Sources */, + 8335A0E31B99A25000E472DF /* zip_source_commit_write.c in Sources */, AB976C4A173443DD00AC26CF /* property.cpp in Sources */, + 8335A0DB1B99A24F00E472DF /* zip_get_encryption_implementation.c in Sources */, AB976C4F173803F800AC26CF /* property_extension.cpp in Sources */, AB976C581738057900AC26CF /* property_holder.cpp in Sources */, AB976C5E17393AD600AC26CF /* epub_locale.cpp in Sources */, diff --git a/Platform/Windows/ReadiumSDK/ReadiumSDK.vcxproj b/Platform/Windows/ReadiumSDK/ReadiumSDK.vcxproj index 9b0a5b21e..ed9ab562e 100644 --- a/Platform/Windows/ReadiumSDK/ReadiumSDK.vcxproj +++ b/Platform/Windows/ReadiumSDK/ReadiumSDK.vcxproj @@ -13,20 +13,23 @@ {033B6AAA-D741-4696-B687-F5BA0520436F} ReadiumSDK + ePub3 - Application + DynamicLibrary true - v110 - MultiByte + v120 + Unicode + Dynamic - Application + StaticLibrary false - v110 + v120 true - MultiByte + Unicode + Dynamic @@ -38,15 +41,36 @@ - + + C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) + Level3 Disabled + $(MSBuildProjectDirectory)\include;$(MSBuildProjectDirectory)\..\..\ePub3;$(MSBuildProjectDirectory)\..\..\ePub3\utilities;$(MSBuildProjectDirectory)\..\..\ePub3\ePub;$(MSBuildProjectDirectory)\..\..\ePub3\xml;$(MSBuildProjectDirectory)\Prebuilt\Include;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty\google-url\src;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty\utf8-cpp\include;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty\icu4c\include;$(MSBuildProjectDirectory)\..\..\Platform\Windows\include\libzip + HAVE_CONFIG_H;WIN32;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;BUILDING_EPUB3;_DEBUG;_LIB;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) + NotUsing + true + true + true + false + StreamingSIMDExtensions2 + true + CompileAsCpp true + $(MSBuildProjectDirectory)\Prebuilt\Lib\x86\libxml2_a.lib;$(MSBuildProjectDirectory)\Prebuilt\Lib\x86\zlib.lib;Advapi32.lib;ws2_32.lib;%(AdditionalDependencies) + + cd $(MSBuildProjectDirectory) +cscript MakeHeaders.js + + + Build canonical headers + @@ -54,97 +78,302 @@ MaxSpeed true true + WIN32;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;BUILDING_EPUB3;NDEBUG;_LIB;HAVE_CONFIG_H;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) + NotUsing + $(MSBuildProjectDirectory)\include;$(MSBuildProjectDirectory)\..\..\ePub3;$(MSBuildProjectDirectory)\..\..\ePub3\utilities;$(MSBuildProjectDirectory)\..\..\ePub3\ePub;$(MSBuildProjectDirectory)\..\..\ePub3\xml;$(MSBuildProjectDirectory)\Prebuilt\Include;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty\google-url\src;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty\utf8-cpp\include;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty\icu4c\include;$(MSBuildProjectDirectory)\..\..\Platform\Windows\include\libzip;%(AdditionalIncludeDirectories) true true true + + cd $(MSBuildProjectDirectory) +cscript MakeHeaders.js + + + Build canonical headers + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + true + + + true + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Platform/Windows/ReadiumSDK/ePub3/ePub3.vcxproj b/Platform/Windows/ReadiumSDK/ePub3/ePub3.vcxproj index f5571dbcb..ec02585d8 100644 --- a/Platform/Windows/ReadiumSDK/ePub3/ePub3.vcxproj +++ b/Platform/Windows/ReadiumSDK/ePub3/ePub3.vcxproj @@ -27,7 +27,7 @@ DynamicLibrary true - v110 + v120 Unicode @@ -39,7 +39,7 @@ DynamicLibrary false - v110 + v120 true Unicode @@ -72,7 +72,7 @@ Use Level3 Disabled - WIN32;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;BUILDING_EPUB3;_SCL_SECURE_NO_WARNINGS;_DEBUG;_LIB;%(PreprocessorDefinitions) + _CRT_NONSTDC_NO_DEPRECATE;HAVE_CONFIG_H;WIN32;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;BUILDING_EPUB3;_SCL_SECURE_NO_WARNINGS;_DEBUG;_LIB;%(PreprocessorDefinitions) true $(MSBuildProjectDirectory)\..\..\include;$(MSBuildProjectDirectory)\..\..\..\..\ePub3;$(MSBuildProjectDirectory)\..\..\..\..\ePub3\utilities;$(MSBuildProjectDirectory)\..\..\..\..\ePub3\ePub;$(MSBuildProjectDirectory)\..\..\..\..\ePub3\ThirdParty;$(MSBuildProjectDirectory)\..\Prebuilt\Include true @@ -226,7 +226,9 @@ cscript MakeHeaders.js + + @@ -261,16 +263,29 @@ cscript MakeHeaders.js + + + + + + + + + + + + + @@ -301,11 +316,14 @@ cscript MakeHeaders.js + + - - + + + @@ -313,21 +331,37 @@ cscript MakeHeaders.js + + + + + + + + + + + + + - + + + + @@ -336,25 +370,60 @@ cscript MakeHeaders.js + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Platform/Windows/ReadiumSDK/ePub3/ePub3.vcxproj.filters b/Platform/Windows/ReadiumSDK/ePub3/ePub3.vcxproj.filters index 8dbf59a90..939145751 100644 --- a/Platform/Windows/ReadiumSDK/ePub3/ePub3.vcxproj.filters +++ b/Platform/Windows/ReadiumSDK/ePub3/ePub3.vcxproj.filters @@ -216,15 +216,6 @@ Source Files\ThirdParty\utf8 - - Source Files\ThirdParty\libzip - - - Source Files\ThirdParty\libzip - - - Source Files\ThirdParty\libzip - Source Files\ThirdParty\google-url @@ -297,6 +288,21 @@ Source Files\utilities + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + @@ -404,239 +410,440 @@ Source Files\ePub\Filters\Encryption - + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\ThirdParty\google-url + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\ePub\Components\Properties + + + Source Files\ePub\Components\Properties + + + Source Files\ePub\Components\Properties + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\ePub + + + Source Files\ePub + + + Source Files\ePub + + + Source Files\ePub + + + Source Files\ePub + + + Source Files\ePub + + + Source Files\ePub + + + Source Files\ePub + + + Source Files\ePub + + + Source Files\ePub + + + Source Files\ePub + + + Source Files\ePub + + + Source Files\ePub + + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + + Source Files\ThirdParty\libzip + + Source Files\ThirdParty\libzip Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\ThirdParty\google-url + + Source Files\ThirdParty\libzip - - Source Files\utilities + + Source Files\ThirdParty\libzip - - Source Files\utilities + + Source Files\ThirdParty\libzip - - Source Files\ePub\Components\Properties + + Source Files\ThirdParty\libzip - - Source Files\ePub\Components\Properties + + Source Files\ThirdParty\libzip - - Source Files\ePub\Components\Properties + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip + + + Source Files\ThirdParty\libzip \ No newline at end of file diff --git a/Platform/Windows/epub3.vcxproj b/Platform/Windows/epub3.vcxproj new file mode 100644 index 000000000..919aa2d1f --- /dev/null +++ b/Platform/Windows/epub3.vcxproj @@ -0,0 +1,372 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {033B6AAA-D741-4696-B687-F5BA0520436F} + ReadiumSDK + ePub3 + + + + DynamicLibrary + true + v120 + Unicode + Dynamic + + + DynamicLibrary + false + v120 + true + Unicode + Dynamic + + + + + + + + + + + + + C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) + + + + Level3 + Disabled + $(MSBuildProjectDirectory)\include;$(MSBuildProjectDirectory)\ReadiumSDK\include;$(MSBuildProjectDirectory)\..\..\ePub3;$(MSBuildProjectDirectory)\..\..\ePub3\utilities;$(MSBuildProjectDirectory)\..\..\ePub3\ePub;$(MSBuildProjectDirectory)\..\..\ePub3\xml;$(MSBuildProjectDirectory)\ReadiumSDK\Prebuilt\Include;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty\google-url\src;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty\utf8-cpp\include;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty\icu4c\include;$(MSBuildProjectDirectory)\..\..\Platform\Windows\include\libzip + HAVE_CONFIG_H;WIN32;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;BUILDING_EPUB3;_DEBUG;_LIB;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) + NotUsing + true + true + true + false + StreamingSIMDExtensions2 + true + CompileAsCpp + + + true + $(MSBuildProjectDirectory)\ReadiumSDK\Prebuilt\Lib\x86\libxml2_a.lib;$(MSBuildProjectDirectory)\ReadiumSDK\Prebuilt\Lib\x86\zlib.lib;Advapi32.lib;ws2_32.lib;User32.lib;%(AdditionalDependencies) + + + cd $(MSBuildProjectDirectory) +cscript MakeHeaders.js + + + Build canonical headers + + + + + Level3 + MaxSpeed + true + true + WIN32;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;BUILDING_EPUB3;NDEBUG;_LIB;HAVE_CONFIG_H;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) + NotUsing + $(MSBuildProjectDirectory)\include;$(MSBuildProjectDirectory)\ReadiumSDK\include;$(MSBuildProjectDirectory)\..\..\ePub3;$(MSBuildProjectDirectory)\..\..\ePub3\utilities;$(MSBuildProjectDirectory)\..\..\ePub3\ePub;$(MSBuildProjectDirectory)\..\..\ePub3\xml;$(MSBuildProjectDirectory)\ReadiumSDK\Prebuilt\Include;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty\google-url\src;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty\utf8-cpp\include;$(MSBuildProjectDirectory)\..\..\ePub3\ThirdParty\icu4c\include;$(MSBuildProjectDirectory)\..\..\Platform\Windows\include\libzip + CompileAsCpp + + + true + true + true + $(MSBuildProjectDirectory)\ReadiumSDK\Prebuilt\Lib\x86\libxml2_a.lib;$(MSBuildProjectDirectory)\ReadiumSDK\Prebuilt\Lib\x86\zlib.lib;Advapi32.lib;ws2_32.lib;User32.lib;%(AdditionalDependencies) + + + cd $(MSBuildProjectDirectory) +cscript MakeHeaders.js + + + Build canonical headers + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Platform/Windows/epub3.vcxproj.filters b/Platform/Windows/epub3.vcxproj.filters new file mode 100644 index 000000000..af88cfe6e --- /dev/null +++ b/Platform/Windows/epub3.vcxproj.filters @@ -0,0 +1,754 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {afa645f5-2d31-49e2-85f0-2fa15012e244} + + + {d75aec3e-6138-4f03-a72e-c61c820da48c} + + + {e272d31a-ccf9-4c62-adfe-e58dd60d3009} + + + {d49d9ad5-0d07-48ca-aa55-2c97922147b1} + + + {094bac38-d3f5-4631-8371-a1c62b373e97} + + + {07d6c06d-10a0-4527-8e68-c17579021edf} + + + {5d940eab-d1ac-41e6-a93c-ae879e6f3e9d} + + + {34a6dd0d-6bad-43ec-97b8-b04a5a3012f6} + + + {f1194f5b-a1ad-4989-b752-df56e26108c4} + + + {d191bace-f94d-4ff3-b99c-30d367f159dd} + + + {3fd56628-c13c-4451-9d60-0af975645dc0} + + + {4a0c3adc-86a0-40d4-bcd4-25545973e941} + + + {71aedce8-b6a4-404f-aeb0-dd44e23b3223} + + + + + Source Files\xml\tree + + + Source Files\xml\tree + + + Source Files\xml\tree + + + Source Files\xml\validation + + + Source Files\xml\validation + + + Source Files\xml\tree + + + Source Files\xml\utilities + + + Source Files\xml\utilities + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\ePub\filters\content preprocessing + + + Source Files\ePub\filters\content preprocessing + + + Source Files\ePub\filters\encrpytion + + + Source Files\ePub\library + + + Source Files\ePub\components\navigation + + + Source Files\ePub\components\navigation + + + Source Files\ePub\components\navigation + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\archives + + + Source Files\ePub\archives + + + Source Files\ePub\archives + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Source Files\xml\validation + + + Source Files\xml\validation + + + Source Files\xml\validation + + + Source Files\xml\validation + + + Source Files\xml\tree + + + Source Files\xml\tree + + + Source Files\xml\tree + + + Source Files\xml\tree + + + Source Files\xml\utilities + + + Source Files\xml\utilities + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\utilities + + + Source Files\ePub\filters\content preprocessing + + + Source Files\ePub\filters\encrpytion + + + Source Files\ePub\filters + + + Source Files\ePub\library + + + Source Files\ePub\components\navigation + + + Source Files\ePub\components\navigation + + + Source Files\ePub\components\navigation + + + Source Files\ePub\components\navigation + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\components + + + Source Files\ePub\archives + + + Source Files\ePub\archives + + + Source Files\ePub\archives + + + Source Files\ePub + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ePub3/ThirdParty/google-url/base/logging.h b/ePub3/ThirdParty/google-url/base/logging.h index 22c328618..87d3386e3 100644 --- a/ePub3/ThirdParty/google-url/base/logging.h +++ b/ePub3/ThirdParty/google-url/base/logging.h @@ -417,7 +417,12 @@ enum { DEBUG_MODE = 0 }; // above. class LogMessage { public: - LogMessage(const char* file, int line, LogSeverity severity, int ctr) {} + LogMessage(const char* file, int line, LogSeverity severity, int ctr) +#if _WIN32 || _WIN64 + ; +#else + {} +#endif // Two special constructors that generate reduced amounts of code at // LOG call sites for common cases. @@ -427,22 +432,42 @@ class LogMessage { // // Using this constructor instead of the more complex constructor above // saves a couple of bytes per call site. - LogMessage(const char* file, int line) {} + LogMessage(const char* file, int line) +#if _WIN32 || _WIN64 + ; +#else + {} +#endif // Used for LOG(severity) where severity != INFO. Implied // are: ctr = 0 // // Using this constructor instead of the more complex constructor above // saves a couple of bytes per call site. - LogMessage(const char* file, int line, LogSeverity severity) {} + LogMessage(const char* file, int line, LogSeverity severity) +#if _WIN32 || _WIN64 + ; +#else + {} +#endif // A special constructor used for check failures. // Implied severity = LOG_FATAL - LogMessage(const char* file, int line, const CheckOpString& result) {} + LogMessage(const char* file, int line, const CheckOpString& result) +#if _WIN32 || _WIN64 + ; +#else + {} +#endif - ~LogMessage() {} + ~LogMessage() +#if _WIN32 || _WIN64 + ; +#else + {} +#endif - std::ostream& stream() { return stream_; } + std::ostream& stream() { return stream_; } private: void Init(const char* file, int line); diff --git a/ePub3/ThirdParty/libzip/CMakeLists.txt b/ePub3/ThirdParty/libzip/CMakeLists.txt new file mode 100644 index 000000000..3bfc6227f --- /dev/null +++ b/ePub3/ThirdParty/libzip/CMakeLists.txt @@ -0,0 +1,192 @@ +INCLUDE(CheckFunctionExists) + +INSTALL(FILES zip.h DESTINATION include) + +# from http://www.cmake.org/Wiki/CMakeMacroLibtoolFile +MACRO(GET_TARGET_PROPERTY_WITH_DEFAULT _variable _target _property _default_value) + + GET_TARGET_PROPERTY (${_variable} ${_target} ${_property}) + IF (${_variable} STREQUAL NOTFOUND) + SET (${_variable} ${_default_value}) + ENDIF (${_variable} STREQUAL NOTFOUND) + +ENDMACRO (GET_TARGET_PROPERTY_WITH_DEFAULT) + +MACRO(CREATE_LIBTOOL_FILE _target _install_DIR) + GET_TARGET_PROPERTY(_target_location ${_target} LOCATION) + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_static_lib ${_target} STATIC_LIB "") + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dependency_libs ${_target} LT_DEPENDENCY_LIBS "") + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_current ${_target} LT_VERSION_CURRENT 4) + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_revision ${_target} LT_VERSION_REVISION 0) + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_age ${_target} LT_VERSION_AGE 0) + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_installed ${_target} LT_INSTALLED yes) + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_shouldnotlink ${_target} LT_SHOULDNOTLINK yes) + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dlopen ${_target} LT_DLOPEN "") + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dlpreopen ${_target} LT_DLPREOPEN "") + GET_FILENAME_COMPONENT(_laname ${_target_location} NAME_WE) + GET_FILENAME_COMPONENT(_soname ${_target_location} NAME) + SET(_laname ${_laname}.la) + FILE(WRITE ${_laname} "# ${_laname} - a libtool library file, generated by cmake \n") + FILE(APPEND ${_laname} "# The name that we can dlopen(3).\n") + FILE(APPEND ${_laname} "dlname='${_soname}'\n") + FILE(APPEND ${_laname} "# Names of this library\n") + FILE(APPEND ${_laname} "library_names='${_soname}.${_target_current}.${_target_age}.${_target_revision} ${_soname}.${_target_current} ${_soname}'\n") + FILE(APPEND ${_laname} "# The name of the static archive\n") + FILE(APPEND ${_laname} "old_library='${_target_static_lib}'\n") + FILE(APPEND ${_laname} "# Libraries that this one depends upon.\n") + FILE(APPEND ${_laname} "dependency_libs='${_target_dependency_libs}'\n") + FILE(APPEND ${_laname} "# Version information.\n") + FILE(APPEND ${_laname} "current=${_target_current}\n") + FILE(APPEND ${_laname} "age=${_target_age}\n") + FILE(APPEND ${_laname} "revision=${_target_revision}\n") + FILE(APPEND ${_laname} "# Is this an already installed library?\n") + FILE(APPEND ${_laname} "installed=${_target_installed}\n") + FILE(APPEND ${_laname} "# Should we warn about portability when linking against -modules?\n") + FILE(APPEND ${_laname} "shouldnotlink=${_target_shouldnotlink}\n") + FILE(APPEND ${_laname} "# Files to dlopen/dlpreopen\n") + FILE(APPEND ${_laname} "dlopen='${_target_dlopen}'\n") + FILE(APPEND ${_laname} "dlpreopen='${_target_dlpreopen}'\n") + FILE(APPEND ${_laname} "# Directory that this library needs to be installed in:\n") + FILE(APPEND ${_laname} "libdir='${CMAKE_INSTALL_PREFIX}/${_install_DIR}'\n") + INSTALL( FILES ${_laname} ${_soname} + DESTINATION ${CMAKE_INSTALL_PREFIX}${_install_DIR}) +ENDMACRO(CREATE_LIBTOOL_FILE) + +SET(LIBZIP_SOURCES + zip_add.c + zip_add_dir.c + zip_add_entry.c + zip_buffer.c + zip_close.c + zip_delete.c + zip_dir_add.c + zip_dirent.c + zip_discard.c + zip_entry.c + zip_err_str.c + zip_error.c + zip_error_clear.c + zip_error_get.c + zip_error_get_sys_type.c + zip_error_strerror.c + zip_error_to_str.c + zip_extra_field.c + zip_extra_field_api.c + zip_fclose.c + zip_fdopen.c + zip_file_add.c + zip_file_error_clear.c + zip_file_error_get.c + zip_file_get_comment.c + zip_file_get_external_attributes.c + zip_file_get_offset.c + zip_file_rename.c + zip_file_replace.c + zip_file_set_comment.c + zip_file_set_external_attributes.c + zip_file_set_mtime.c + zip_file_strerror.c + zip_filerange_crc.c + zip_fopen.c + zip_fopen_encrypted.c + zip_fopen_index.c + zip_fopen_index_encrypted.c + zip_fread.c + zip_get_archive_comment.c + zip_get_archive_flag.c + zip_get_compression_implementation.c + zip_get_encryption_implementation.c + zip_get_file_comment.c + zip_get_name.c + zip_get_num_entries.c + zip_get_num_files.c + zip_io_util.c + zip_memdup.c + zip_name_locate.c + zip_new.c + zip_open.c + zip_rename.c + zip_replace.c + zip_set_archive_comment.c + zip_set_archive_flag.c + zip_set_default_password.c + zip_set_file_comment.c + zip_set_file_compression.c + zip_set_name.c + zip_source_begin_write.c + zip_source_buffer.c + zip_source_call.c + zip_source_close.c + zip_source_commit_write.c + zip_source_crc.c + zip_source_deflate.c + zip_source_error.c + zip_source_filep.c + zip_source_free.c + zip_source_function.c + zip_source_is_deleted.c + zip_source_layered.c + zip_source_open.c + zip_source_pkware.c + zip_source_read.c + zip_source_remove.c + zip_source_rollback_write.c + zip_source_seek.c + zip_source_seek_write.c + zip_source_stat.c + zip_source_supports.c + zip_source_tell.c + zip_source_tell_write.c + zip_source_window.c + zip_source_write.c + zip_source_zip.c + zip_source_zip_new.c + zip_stat.c + zip_stat_index.c + zip_stat_init.c + zip_strerror.c + zip_string.c + zip_unchange.c + zip_unchange_all.c + zip_unchange_archive.c + zip_unchange_data.c + zip_utf-8.c +) + +IF(WIN32) + SET(LIBZIP_OPSYS_FILES + zip_source_win32a.c + zip_source_win32handle.c + zip_source_win32utf8.c + zip_source_win32w.c + ) +ELSE(WIN32) + SET(LIBZIP_OPSYS_FILES + zip_source_file.c + ) +ENDIF(WIN32) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR}/..) + +# TODO: distribute instead? +#ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zip_err_str.c +# COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/make_zip_err_str.sh +# ${CMAKE_CURRENT_SOURCE_DIR}/zip.h +# ${CMAKE_CURRENT_BINARY_DIR}/zip_err_str.c +# DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/zip.h +# ${CMAKE_CURRENT_SOURCE_DIR}/make_zip_err_str.sh +#) +CHECK_FUNCTION_EXISTS(mkstemp HAVE_MKSTEMP) +IF(NOT HAVE_MKSTEMP) + SET(LIBZIP_EXTRA_FILES mkstemp.c) +ENDIF(NOT HAVE_MKSTEMP) + +ADD_LIBRARY(zip SHARED ${LIBZIP_SOURCES} ${LIBZIP_EXTRA_FILES} ${LIBZIP_OPSYS_FILES}) +SET_TARGET_PROPERTIES(zip PROPERTIES VERSION 3.0 SOVERSION 3 ) +TARGET_LINK_LIBRARIES(zip ${ZLIB_LIBRARY}) +INSTALL(TARGETS zip + RUNTIME DESTINATION bin + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib) +#CREATE_LIBTOOL_FILE(zip lib) diff --git a/ePub3/ThirdParty/libzip/Config.h b/ePub3/ThirdParty/libzip/Config.h index 301434810..697f15307 100644 --- a/ePub3/ThirdParty/libzip/Config.h +++ b/ePub3/ThirdParty/libzip/Config.h @@ -1,8 +1,64 @@ -#ifndef _ZIP_CONFIG_ -#define _ZIP_CONFIG_ +#ifndef HAD_CONFIG_H +#define HAD_CONFIG_H +#ifndef _HAD_ZIPCONF_H +#include "zipconf.h" +#endif +/* BEGIN DEFINES */ +//#define off_t zip_int64_t +#define HAVE__CLOSE +#define HAVE__DUP +#define HAVE__FDOPEN +#define HAVE__FILENO +#define HAVE__OPEN +#define HAVE__SNPRINTF +#define HAVE__STRDUP +//#define HAVE__STRICMP +//#define __STDC__ 1 +#define HAVE_STDBOOL_H -#define HAVE_MKSTEMP 1 -#define HAVE_FSEEKO 1 -#define HAVE_FTELLO 1 +#define HAVE_FSEEKO +#define HAVE_FTELLO -#endif /* _ZIP_CONFIG_ */ +/* #undef HAVE_FSEEKO */ +/* #undef HAVE_FTELLO */ +//#define HAVE_OPEN +/* #undef HAVE_MKSTEMP */ +/* #undef HAVE_SNPRINTF */ +/* #undef HAVE_STRCASECMP */ +#define HAVE_STRDUP +/* #undef HAVE_STRUCT_TM_TM_ZONE */ +#define HAVE_MOVEFILEEXA +/* #undef HAVE_STRINGS_H */ +/* #undef HAVE_UNISTD_H */ +#define __INT8_LIBZIP 1 +#define INT8_T_LIBZIP 1 +#define UINT8_T_LIBZIP 1 +#define __INT16_LIBZIP 2 +#define INT16_T_LIBZIP 2 +#define UINT16_T_LIBZIP 2 +#define __INT32_LIBZIP 4 +#define INT32_T_LIBZIP 4 +#define UINT32_T_LIBZIP 4 +#define __INT64_LIBZIP 8 +#define INT64_T_LIBZIP 8 +#define UINT64_T_LIBZIP 8 +#define SIZEOF_OFF_T 8 +#define SIZE_T_LIBZIP 4 +/* #undef SSIZE_T_LIBZIP */ +/* END DEFINES */ +#define PACKAGE "libzip" +#define VERSION "0.11.2" + +/*#ifndef HAVE_SSIZE_T_LIBZIP +# if SIZE_T_LIBZIP == INT_LIBZIP +typedef int ssize_t; +# elif SIZE_T_LIBZIP == LONG_LIBZIP +typedef long ssize_t; +# elif SIZE_T_LIBZIP == LONG_LONG_LIBZIP +typedef long long ssize_t; +# else +#error no suitable type for ssize_t found +# endif +#endif*/ + +#endif /* HAD_CONFIG_H */ diff --git a/ePub3/ThirdParty/libzip/Makefile.am b/ePub3/ThirdParty/libzip/Makefile.am new file mode 100644 index 000000000..c43ed4b9b --- /dev/null +++ b/ePub3/ThirdParty/libzip/Makefile.am @@ -0,0 +1,130 @@ +AM_CFLAGS= @CFLAG_VISIBILITY@ +libincludedir = ${libdir}/@PACKAGE@/include + +lib_LTLIBRARIES = libzip.la +noinst_HEADERS = zipint.h +include_HEADERS = zip.h +nodist_libinclude_HEADERS = zipconf.h + +# also update CMakeLists.txt when changing version +libzip_la_LDFLAGS=-no-undefined -version-info 4:0:0 +libzip_la_LIBADD=@LTLIBOBJS@ + +libzip_la_SOURCES=\ + zip_add.c \ + zip_add_dir.c \ + zip_add_entry.c \ + zip_buffer.c \ + zip_close.c \ + zip_delete.c \ + zip_dir_add.c \ + zip_dirent.c \ + zip_discard.c \ + zip_entry.c \ + zip_err_str.c \ + zip_error.c \ + zip_error_clear.c \ + zip_error_get.c \ + zip_error_get_sys_type.c \ + zip_error_strerror.c \ + zip_error_to_str.c \ + zip_extra_field.c \ + zip_extra_field_api.c \ + zip_fclose.c \ + zip_fdopen.c \ + zip_file_add.c \ + zip_file_error_clear.c \ + zip_file_error_get.c \ + zip_file_get_comment.c \ + zip_file_get_external_attributes.c \ + zip_file_get_offset.c \ + zip_file_rename.c \ + zip_file_replace.c \ + zip_file_set_comment.c \ + zip_file_set_external_attributes.c \ + zip_file_set_mtime.c \ + zip_file_strerror.c \ + zip_filerange_crc.c \ + zip_fopen.c \ + zip_fopen_encrypted.c \ + zip_fopen_index.c \ + zip_fopen_index_encrypted.c \ + zip_fread.c \ + zip_get_archive_comment.c \ + zip_get_archive_flag.c \ + zip_get_compression_implementation.c \ + zip_get_encryption_implementation.c \ + zip_get_file_comment.c \ + zip_get_num_entries.c \ + zip_get_num_files.c \ + zip_get_name.c \ + zip_io_util.c \ + zip_memdup.c \ + zip_name_locate.c \ + zip_new.c \ + zip_open.c \ + zip_rename.c \ + zip_replace.c \ + zip_set_archive_comment.c \ + zip_set_archive_flag.c \ + zip_set_default_password.c \ + zip_set_file_comment.c \ + zip_set_file_compression.c \ + zip_set_name.c \ + zip_source_begin_write.c \ + zip_source_buffer.c \ + zip_source_call.c \ + zip_source_close.c \ + zip_source_commit_write.c \ + zip_source_crc.c \ + zip_source_deflate.c \ + zip_source_error.c \ + zip_source_file.c \ + zip_source_filep.c \ + zip_source_free.c \ + zip_source_function.c \ + zip_source_is_deleted.c \ + zip_source_layered.c \ + zip_source_open.c \ + zip_source_pkware.c \ + zip_source_read.c \ + zip_source_remove.c \ + zip_source_rollback_write.c \ + zip_source_seek.c \ + zip_source_seek_write.c \ + zip_source_stat.c \ + zip_source_supports.c \ + zip_source_tell.c \ + zip_source_tell_write.c \ + zip_source_window.c \ + zip_source_write.c \ + zip_source_zip.c \ + zip_source_zip_new.c \ + zip_stat.c \ + zip_stat_index.c \ + zip_stat_init.c \ + zip_strerror.c \ + zip_string.c \ + zip_unchange.c \ + zip_unchange_all.c \ + zip_unchange_archive.c \ + zip_unchange_data.c \ + zip_utf-8.c + +BUILT_SOURCES=zipconf.h +CLEANFILES= ${BUILT_SOURCES} + +EXTRA_DIST= CMakeLists.txt \ + make_zip_err_str.sh \ + make_zipconf.sh \ + zip_source_win32a.c \ + zip_source_win32handle.c \ + zip_source_win32utf8.c \ + zip_source_win32w.c \ + zipwin32.h + +zip_err_str.c: zip.h make_zip_err_str.sh + sh $(srcdir)/make_zip_err_str.sh $(srcdir)/zip.h zip_err_str.c + +zipconf.h: ${top_builddir}/config.h make_zipconf.sh + sh ${srcdir}/make_zipconf.sh ${top_builddir}/config.h zipconf.h diff --git a/ePub3/ThirdParty/libzip/make_zip_err_str.sh b/ePub3/ThirdParty/libzip/make_zip_err_str.sh new file mode 100755 index 000000000..8d98f2351 --- /dev/null +++ b/ePub3/ThirdParty/libzip/make_zip_err_str.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# make_zip_err_str.sh: create zip_err_str.c from zip.h +# Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner +# +# This file is part of libzip, a library to manipulate ZIP archives. +# The authors can be contacted at +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. The names of the authors may not be used to endorse or promote +# products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +if [ "$#" -ne 2 ] +then + echo "Usage: $0 in_file out_file" >&2 + echo " e.g. $0 zip.h zip_err_str.c" >&2 + exit 1 +fi + +if [ "$1" = "$2" ] +then + echo "$0: error: output file = input file" >&2 + exit 1 +fi + +cat <> "$2.$$" || exit 1 +/* + This file was generated automatically by $0 + from $1; make changes there. + */ + +#include "zipint.h" + +const char * const _zip_err_str[] = { +EOF + +sed -n '/^#define ZIP_ER_/ s/.*\/\* . \([^*]*\) \*\// "\1",/p' "$1" \ + >> "$2.$$" || exit 1 + +cat <> "$2.$$" || exit 1 +}; + +const int _zip_nerr_str = sizeof(_zip_err_str)/sizeof(_zip_err_str[0]); + +#define N ZIP_ET_NONE +#define S ZIP_ET_SYS +#define Z ZIP_ET_ZLIB + +const int _zip_err_type[] = { +EOF + +sed -n '/^#define ZIP_ER_/ s/.*\/\* \(.\) \([^*]*\) \*\// \1,/p' "$1" \ + >> "$2.$$" || exit 1 + +echo '};' >> "$2.$$" || exit 1 + +mv "$2.$$" "$2" || exit 1 diff --git a/ePub3/ThirdParty/libzip/make_zipconf.sh b/ePub3/ThirdParty/libzip/make_zipconf.sh new file mode 100755 index 000000000..12e7b0a72 --- /dev/null +++ b/ePub3/ThirdParty/libzip/make_zipconf.sh @@ -0,0 +1,163 @@ +#!/bin/sh + +# make_zipconf.sh: create platform specific include file zipconf.h +# Copyright (C) 1999-2009 Dieter Baron and Thomas Klausner +# +# This file is part of libzip, a library to manipulate ZIP archives. +# The authors can be contacted at +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. The names of the authors may not be used to endorse or promote +# products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +set -e + +define_type() +{ + short=$1 + long=$2 + bytes=$3 + infile="$4" + outfile="$5" + + bits=`expr $bytes '*' 8` + type="${short}int${bits}" + TYPE=`echo $type | tr '[a-z]' '[A-Z]'` + if grep "define HAVE_${TYPE}_T" "$infile" > /dev/null + then + echo "typedef ${type}_t zip_${type}_t;" >> "$outfile" + LTYPE="$TYPE" + else + SHORT=`echo $short | tr '[a-z]' '[A-Z]'` + if [ -z "$SHORT" ] + then + SHORT='S' + fi + if [ "$bytes" -eq 1 ] + then + if [ -z "$long" ] + then + long='signed' + fi + echo "typedef $long char ${type}_t;" >> $outfile + LTYPE="${SHORT}CHAR" + else + ctype=`sed -n "s/.define SIZEOF_\([A-Z_]*\) $bytes/\1/p" "$infile" \ + | head -1 | tr '[A-Z_]' '[a-z ]'` + if [ -z "$ctype" ] + then + echo "$0: no $bits bit type found" >&2 + exit 1 + fi + echo "typedef $long $ctype ${type}_t;" >> "$outfile" + case "$ctype" in + short) LTYPE=${SHORT}SHRT;; + int) LTYPE=${SHORT}INT;; + long) LTYPE=${SHORT}LONG;; + "long long") LTYPE=${SHORT}LLONG;; + esac + fi + fi + + if [ -z "$long" ] + then + echo "#define ZIP_${TYPE}_MIN ${LTYPE}_MIN" >> "$outfile" + fi + echo "#define ZIP_${TYPE}_MAX ${LTYPE}_MAX" >> "$outfile" + echo >> "$outfile" +} + + +if [ "$#" -ne 2 ] +then + echo "Usage: $0 config_h_file out_file" >&2 + echo " e.g. $0 ../config.h zip_err_str.c" >&2 + exit 1 +fi + +if [ "$1" = "$2" ] +then + echo "$0: error: output file = input file" >&2 + exit 1 +fi + +cat < "$2.$$" +#ifndef _HAD_ZIPCONF_H +#define _HAD_ZIPCONF_H + +/* + zipconf.h -- platform specific include file + + This file was generated automatically by $0 + based on $1. + */ + +EOF + +version=`sed -n 's/^#define VERSION "\(.*\)"/\1/p' "$1"` + +version_major=`expr "$version" : '^\([0-9]*\)' || true` +version_minor=`expr "$version" : '^[0-9]*\.\([0-9]*\)' || true` +version_micro=`expr "$version" : '^[0-9]*\.[0-9]\.\([0-9]*\)' || true` + +if [ -z "$version_major" ] +then + version_major=0 +fi +if [ -z "$version_minor" ] +then + version_minor=0 +fi +if [ -z "$version_micro" ] +then + version_micro=0 +fi + +cat <> "$2.$$" +#define LIBZIP_VERSION "$version" +#define LIBZIP_VERSION_MAJOR $version_major +#define LIBZIP_VERSION_MINOR $version_minor +#define LIBZIP_VERSION_MICRO $version_micro + +EOF + +if grep 'define HAVE_INTTYPES_H' "$1" > /dev/null +then + echo '#include ' >> "$2.$$" +else + echo '#include ' >> "$2.$$" +fi +echo >> "$2.$$" + +for size in 1 2 4 8 +do + define_type '' '' $size "$1" "$2.$$" + define_type u unsigned $size "$1" "$2.$$" +done + +echo >> "$2.$$" +echo '#endif /* zipconf.h */' >> "$2.$$" + +mv "$2.$$" "$2" diff --git a/ePub3/ThirdParty/libzip/mkstemp.c b/ePub3/ThirdParty/libzip/mkstemp.c index f399bb9bf..d0995e8a7 100644 --- a/ePub3/ThirdParty/libzip/mkstemp.c +++ b/ePub3/ThirdParty/libzip/mkstemp.c @@ -1,5 +1,3 @@ -/* $NiH: mkstemp.c,v 1.3 2006/04/23 14:51:45 wiz Exp $ */ - /* Adapted from NetBSB libc by Dieter Baron */ /* NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp */ @@ -40,51 +38,45 @@ #include #include #include +#ifdef _WIN32 +#include +#endif #include #include -#if defined(_MSC_VER) -# include -# include -# define open _open -#else -# include -#endif + +#include +#include #ifndef O_BINARY #define O_BINARY 0 #endif - int _zip_mkstemp(char *path) { +#ifdef _WIN32 + int ret; + ret = _creat(_mktemp(path), _S_IREAD|_S_IWRITE); + if (ret == -1) { + return 0; + } else { + return ret; + } +#else int fd; char *start, *trv; - struct stat sbuf; - -#if defined(_MSC_VER) - unsigned long long pid; - { - SYSTEMTIME st; - FILETIME ft; - - GetSystemTime(&st); - SystemTimeToFileTime(&st, &ft); - - pid = ((unsigned long long)ft.dwHighDateTime << 32) | (unsigned long long)ft.dwLowDateTime; - } -#else + struct stat sbuf; pid_t pid; - pid = getpid(); -#endif /* To guarantee multiple calls generate unique names even if the file is not created. 676 different possibilities with 7 or more X's, 26 with 6 or less. */ - static char xtra[2] = {'a','a'}; + static char xtra[2] = "aa"; int xcnt = 0; + pid = getpid(); + /* Move to end of path and count trailing X's. */ for (trv = path; *trv; ++trv) if (*trv == 'X') @@ -126,7 +118,7 @@ _zip_mkstemp(char *path) *trv = '\0'; if (stat(path, &sbuf)) return (0); - if ((sbuf.st_mode & S_IFDIR) != S_IFDIR) { + if (!S_ISDIR(sbuf.st_mode)) { errno = ENOTDIR; return (0); } @@ -157,4 +149,5 @@ _zip_mkstemp(char *path) } } /*NOTREACHED*/ +#endif } diff --git a/ePub3/ThirdParty/libzip/zip.h b/ePub3/ThirdParty/libzip/zip.h index 935725e68..b4fed1451 100644 --- a/ePub3/ThirdParty/libzip/zip.h +++ b/ePub3/ThirdParty/libzip/zip.h @@ -3,7 +3,7 @@ /* zip.h -- exported declarations. - Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -34,42 +34,71 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #ifndef ZIP_EXTERN -#ifdef _MSC_VER -#define ZIP_EXTERN __declspec(dllexport) -#else -#define ZIP_EXTERN +# ifndef ZIP_STATIC +# ifdef _WIN32 +# define ZIP_EXTERN __declspec(dllimport) +# elif defined(__GNUC__) && __GNUC__ >= 4 +# define ZIP_EXTERN __attribute__ ((visibility ("default"))) +# else +# define ZIP_EXTERN +# endif +# else +# define ZIP_EXTERN +# endif #endif + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* fix autoindent */ #endif +#endif + +#include "zipconf.h" #include #include #include -#ifdef __cplusplus -extern "C" { -#endif - /* flags for zip_open */ #define ZIP_CREATE 1 #define ZIP_EXCL 2 #define ZIP_CHECKCONS 4 +#define ZIP_TRUNCATE 8 +#define ZIP_RDONLY 16 /* flags for zip_name_locate, zip_fopen, zip_stat, ... */ -#define ZIP_FL_NOCASE 1 /* ignore case on name lookup */ -#define ZIP_FL_NODIR 2 /* ignore directory component */ -#define ZIP_FL_COMPRESSED 4 /* read compressed data */ -#define ZIP_FL_UNCHANGED 8 /* use original data, ignoring changes */ -#define ZIP_FL_RECOMPRESS 16 /* force recompression of data */ +#define ZIP_FL_NOCASE 1u /* ignore case on name lookup */ +#define ZIP_FL_NODIR 2u /* ignore directory component */ +#define ZIP_FL_COMPRESSED 4u /* read compressed data */ +#define ZIP_FL_UNCHANGED 8u /* use original data, ignoring changes */ +#define ZIP_FL_RECOMPRESS 16u /* force recompression of data */ +#define ZIP_FL_ENCRYPTED 32u /* read encrypted data (implies ZIP_FL_COMPRESSED) */ +#define ZIP_FL_ENC_GUESS 0u /* guess string encoding (is default) */ +#define ZIP_FL_ENC_RAW 64u /* get unmodified string */ +#define ZIP_FL_ENC_STRICT 128u /* follow specification strictly */ +#define ZIP_FL_LOCAL 256u /* in local header */ +#define ZIP_FL_CENTRAL 512u /* in central directory */ +/* 1024u reserved for internal use */ +#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */ +#define ZIP_FL_ENC_CP437 4096u /* string is CP437 encoded */ +#define ZIP_FL_OVERWRITE 8192u /* zip_file_add: if file with name exists, overwrite (replace) it */ /* archive global flags flags */ -#define ZIP_AFL_TORRENT 1 /* torrent zipped */ +#define ZIP_AFL_RDONLY 2u /* read only -- cannot be cleared */ + + +/* create a new extra field */ + +#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX +#define ZIP_EXTRA_FIELD_NEW ZIP_UINT16_MAX + /* libzip error codes */ @@ -90,14 +119,20 @@ extern "C" { #define ZIP_ER_MEMORY 14 /* N Malloc failure */ #define ZIP_ER_CHANGED 15 /* N Entry has been changed */ #define ZIP_ER_COMPNOTSUPP 16 /* N Compression method not supported */ -#define ZIP_ER_EOF 17 /* N Premature EOF */ +#define ZIP_ER_EOF 17 /* N Premature end of file */ #define ZIP_ER_INVAL 18 /* N Invalid argument */ #define ZIP_ER_NOZIP 19 /* N Not a zip archive */ #define ZIP_ER_INTERNAL 20 /* N Internal error */ #define ZIP_ER_INCONS 21 /* N Zip archive inconsistent */ #define ZIP_ER_REMOVE 22 /* S Can't remove file */ #define ZIP_ER_DELETED 23 /* N Entry has been deleted */ - +#define ZIP_ER_ENCRNOTSUPP 24 /* N Encryption method not supported */ +#define ZIP_ER_RDONLY 25 /* N Read-only archive */ +#define ZIP_ER_NOPASSWD 26 /* N No password provided */ +#define ZIP_ER_WRONGPASSWD 27 /* N Wrong password provided */ +#define ZIP_ER_OPNOTSUPP 28 /* N Operation not supported */ +#define ZIP_ER_INUSE 29 /* N Resource still in use */ +#define ZIP_ER_TELL 30 /* S Tell error */ /* type of system error value */ @@ -146,85 +181,239 @@ extern "C" { #endif #define ZIP_EM_UNKNOWN 0xffff /* unknown algorithm */ -/* zip_file offset locations */ -#define ZIP_SEEK_SET 0 /* set absolute offset */ -#define ZIP_SEEK_CUR 1 /* set relative to current offset */ -#define ZIP_SEEK_END 2 /* set to EOF plus offset */ +#define ZIP_OPSYS_DOS 0x00u +#define ZIP_OPSYS_AMIGA 0x01u +#define ZIP_OPSYS_OPENVMS 0x02u +#define ZIP_OPSYS_UNIX 0x03u +#define ZIP_OPSYS_VM_CMS 0x04u +#define ZIP_OPSYS_ATARI_ST 0x05u +#define ZIP_OPSYS_OS_2 0x06u +#define ZIP_OPSYS_MACINTOSH 0x07u +#define ZIP_OPSYS_Z_SYSTEM 0x08u +#define ZIP_OPSYS_CPM 0x09u +#define ZIP_OPSYS_WINDOWS_NTFS 0x0au +#define ZIP_OPSYS_MVS 0x0bu +#define ZIP_OPSYS_VSE 0x0cu +#define ZIP_OPSYS_ACORN_RISC 0x0du +#define ZIP_OPSYS_VFAT 0x0eu +#define ZIP_OPSYS_ALTERNATE_MVS 0x0fu +#define ZIP_OPSYS_BEOS 0x10u +#define ZIP_OPSYS_TANDEM 0x11u +#define ZIP_OPSYS_OS_400 0x12u +#define ZIP_OPSYS_OS_X 0x13u + +#define ZIP_OPSYS_DEFAULT ZIP_OPSYS_UNIX + enum zip_source_cmd { - ZIP_SOURCE_OPEN, /* prepare for reading */ - ZIP_SOURCE_READ, /* read data */ - ZIP_SOURCE_CLOSE, /* reading is done */ - ZIP_SOURCE_STAT, /* get meta information */ - ZIP_SOURCE_ERROR, /* get error information */ - ZIP_SOURCE_FREE /* cleanup and free resources */ + ZIP_SOURCE_OPEN, /* prepare for reading */ + ZIP_SOURCE_READ, /* read data */ + ZIP_SOURCE_CLOSE, /* reading is done */ + ZIP_SOURCE_STAT, /* get meta information */ + ZIP_SOURCE_ERROR, /* get error information */ + ZIP_SOURCE_FREE, /* cleanup and free resources */ + ZIP_SOURCE_SEEK, /* set position for reading */ + ZIP_SOURCE_TELL, /* get read position */ + ZIP_SOURCE_BEGIN_WRITE, /* prepare for writing */ + ZIP_SOURCE_COMMIT_WRITE, /* writing is done */ + ZIP_SOURCE_ROLLBACK_WRITE, /* discard written changes */ + ZIP_SOURCE_WRITE, /* write data */ + ZIP_SOURCE_SEEK_WRITE, /* set position for writing */ + ZIP_SOURCE_TELL_WRITE, /* get write position */ + ZIP_SOURCE_SUPPORTS, /* check whether source supports command */ + ZIP_SOURCE_REMOVE /* remove file */ }; +typedef enum zip_source_cmd zip_source_cmd_t; + +#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (1<<(cmd)) + +#define ZIP_SOURCE_SUPPORTS_READABLE (ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \ + | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \ + | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \ + | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \ + | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \ + | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE)) -typedef ssize_t (*zip_source_callback)(void *state, void *data, - size_t len, enum zip_source_cmd cmd); +#define ZIP_SOURCE_SUPPORTS_SEEKABLE (ZIP_SOURCE_SUPPORTS_READABLE \ + | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \ + | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \ + | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS)) + +#define ZIP_SOURCE_SUPPORTS_WRITABLE (ZIP_SOURCE_SUPPORTS_SEEKABLE \ + | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE) \ + | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE) \ + | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE) \ + | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE) \ + | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE) \ + | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE) \ + | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE)) + +/* for use by sources */ +struct zip_source_args_seek { + zip_int64_t offset; + int whence; +}; + +typedef struct zip_source_args_seek zip_source_args_seek_t; +#define ZIP_SOURCE_GET_ARGS(type, data, len, error) ((len) < sizeof(type) ? zip_error_set((error), ZIP_ER_INVAL, 0), (type *)NULL : (type *)(data)) + + +/* error information */ +/* use zip_error_*() to access */ +struct zip_error { + int zip_err; /* libzip error code (ZIP_ER_*) */ + int sys_err; /* copy of errno (E*) or zlib error code */ + char *str; /* string representation or NULL */ +}; + +#define ZIP_STAT_NAME 0x0001u +#define ZIP_STAT_INDEX 0x0002u +#define ZIP_STAT_SIZE 0x0004u +#define ZIP_STAT_COMP_SIZE 0x0008u +#define ZIP_STAT_MTIME 0x0010u +#define ZIP_STAT_CRC 0x0020u +#define ZIP_STAT_COMP_METHOD 0x0040u +#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u +#define ZIP_STAT_FLAGS 0x0100u struct zip_stat { + zip_uint64_t valid; /* which fields have valid values */ const char *name; /* name of the file */ - int index; /* index within archive */ - unsigned int crc; /* crc of file data */ + zip_uint64_t index; /* index within archive */ + zip_uint64_t size; /* size of file (uncompressed) */ + zip_uint64_t comp_size; /* size of file (compressed) */ time_t mtime; /* modification time */ - off_t size; /* size of file (uncompressed) */ - off_t comp_size; /* size of file (compressed) */ - unsigned short comp_method; /* compression method used */ - unsigned short encryption_method; /* encryption method used */ + zip_uint32_t crc; /* crc of file data */ + zip_uint16_t comp_method; /* compression method used */ + zip_uint16_t encryption_method; /* encryption method used */ + zip_uint32_t flags; /* reserved for future use */ }; struct zip; struct zip_file; struct zip_source; -ZIP_EXTERN int zip_add(struct zip *, const char *, struct zip_source *); -ZIP_EXTERN int zip_add_dir(struct zip *, const char *); -ZIP_EXTERN int zip_close(struct zip *); -ZIP_EXTERN int zip_delete(struct zip *, int); -ZIP_EXTERN void zip_error_clear(struct zip *); -ZIP_EXTERN void zip_error_get(struct zip *, int *, int *); -ZIP_EXTERN int zip_error_get_sys_type(int); -ZIP_EXTERN int zip_error_to_str(char *, size_t, int, int); -ZIP_EXTERN int zip_fclose(struct zip_file *); -ZIP_EXTERN void zip_file_error_clear(struct zip_file *); -ZIP_EXTERN void zip_file_error_get(struct zip_file *, int *, int *); -ZIP_EXTERN const char *zip_file_strerror(struct zip_file *); -ZIP_EXTERN struct zip_file *zip_fopen(struct zip *, const char *, int); -ZIP_EXTERN struct zip_file *zip_fopen_index(struct zip *, int, int); -ZIP_EXTERN ssize_t zip_fread(struct zip_file *, void *, size_t); -ZIP_EXTERN int zip_fseek(struct zip_file*, long, int); -ZIP_EXTERN long zip_ftell(struct zip_file*); -ZIP_EXTERN const char *zip_get_archive_comment(struct zip *, int *, int); -ZIP_EXTERN int zip_get_archive_flag(struct zip *, int, int); -ZIP_EXTERN const char *zip_get_file_comment(struct zip *, int, int *, int); -ZIP_EXTERN const char *zip_get_name(struct zip *, int, int); -ZIP_EXTERN int zip_get_num_files(struct zip *); -ZIP_EXTERN int zip_name_locate(struct zip *, const char *, int); -ZIP_EXTERN struct zip *zip_open(const char *, int, int *); -ZIP_EXTERN int zip_rename(struct zip *, int, const char *); -ZIP_EXTERN int zip_replace(struct zip *, int, struct zip_source *); -ZIP_EXTERN int zip_set_archive_comment(struct zip *, const char *, int); -ZIP_EXTERN int zip_set_archive_flag(struct zip *, int, int); -ZIP_EXTERN int zip_set_file_comment(struct zip *, int, const char *, int); -ZIP_EXTERN struct zip_source *zip_source_buffer(struct zip *, const void *, - off_t, int); -ZIP_EXTERN struct zip_source *zip_source_file(struct zip *, const char *, - off_t, off_t); -ZIP_EXTERN struct zip_source *zip_source_filep(struct zip *, FILE *, - off_t, off_t); -ZIP_EXTERN void zip_source_free(struct zip_source *); -ZIP_EXTERN struct zip_source *zip_source_function(struct zip *, - zip_source_callback, void *); -ZIP_EXTERN struct zip_source *zip_source_zip(struct zip *, struct zip *, - int, int, off_t, off_t); -ZIP_EXTERN int zip_stat(struct zip *, const char *, int, struct zip_stat *); -ZIP_EXTERN int zip_stat_index(struct zip *, int, int, struct zip_stat *); -ZIP_EXTERN void zip_stat_init(struct zip_stat *); -ZIP_EXTERN const char *zip_strerror(struct zip *); -ZIP_EXTERN int zip_unchange(struct zip *, int); -ZIP_EXTERN int zip_unchange_all(struct zip *); -ZIP_EXTERN int zip_unchange_archive(struct zip *); +typedef struct zip zip_t; +typedef struct zip_error zip_error_t; +typedef struct zip_file zip_file_t; +typedef struct zip_source zip_source_t; +typedef struct zip_stat zip_stat_t; + +typedef zip_uint32_t zip_flags_t; + +typedef zip_int64_t (*zip_source_callback)(void *, void *, zip_uint64_t, zip_source_cmd_t); + + +#ifndef ZIP_DISABLE_DEPRECATED +ZIP_EXTERN zip_int64_t zip_add(zip_t *, const char *, zip_source_t *); /* use zip_file_add */ +ZIP_EXTERN zip_int64_t zip_add_dir(zip_t *, const char *); /* use zip_dir_add */ +ZIP_EXTERN const char *zip_get_file_comment(zip_t *, zip_uint64_t, int *, int); /* use zip_file_get_comment */ +ZIP_EXTERN int zip_get_num_files(zip_t *); /* use zip_get_num_entries instead */ +ZIP_EXTERN int zip_rename(zip_t *, zip_uint64_t, const char *); /* use zip_file_rename */ +ZIP_EXTERN int zip_replace(zip_t *, zip_uint64_t, zip_source_t *); /* use zip_file_replace */ +ZIP_EXTERN int zip_set_file_comment(zip_t *, zip_uint64_t, const char *, int); /* use zip_file_set_comment */ +ZIP_EXTERN int zip_error_get_sys_type(int); /* use zip_error_system_type */ +ZIP_EXTERN void zip_error_get(zip_t *, int *, int *); /* use zip_get_error, zip_error_code_zip / zip_error_code_system */ +ZIP_EXTERN int zip_error_to_str(char *, zip_uint64_t, int, int); +ZIP_EXTERN void zip_file_error_get(zip_file_t *, int *, int *); /* use zip_file_get_error, zip_error_code_zip / zip_error_code_system */ +#endif + +ZIP_EXTERN int zip_archive_set_tempdir(zip_t *, const char *); +ZIP_EXTERN int zip_close(zip_t *); +ZIP_EXTERN int zip_delete(zip_t *, zip_uint64_t); +ZIP_EXTERN zip_int64_t zip_dir_add(zip_t *, const char *, zip_flags_t); +ZIP_EXTERN void zip_discard(zip_t *); + +ZIP_EXTERN zip_error_t *zip_get_error(zip_t *); +ZIP_EXTERN void zip_error_clear(zip_t *); +ZIP_EXTERN int zip_error_code_zip(const zip_error_t *); +ZIP_EXTERN int zip_error_code_system(const zip_error_t *); +ZIP_EXTERN void zip_error_fini(zip_error_t *); +ZIP_EXTERN void zip_error_init(zip_error_t *); +ZIP_EXTERN void zip_error_init_with_code(zip_error_t *, int); +ZIP_EXTERN void zip_error_set(zip_error_t *, int, int); +ZIP_EXTERN const char *zip_error_strerror(zip_error_t *); +ZIP_EXTERN int zip_error_system_type(const zip_error_t *); +ZIP_EXTERN zip_int64_t zip_error_to_data(const zip_error_t *, void *, zip_uint64_t); + +ZIP_EXTERN int zip_fclose(zip_file_t *); +ZIP_EXTERN zip_t *zip_fdopen(int, int, int *); +ZIP_EXTERN zip_int64_t zip_file_add(zip_t *, const char *, zip_source_t *, zip_flags_t); +ZIP_EXTERN void zip_file_error_clear(zip_file_t *); +ZIP_EXTERN int zip_file_extra_field_delete(zip_t *, zip_uint64_t, zip_uint16_t, zip_flags_t); +ZIP_EXTERN int zip_file_extra_field_delete_by_id(zip_t *, zip_uint64_t, zip_uint16_t, zip_uint16_t, zip_flags_t); +ZIP_EXTERN int zip_file_extra_field_set(zip_t *, zip_uint64_t, zip_uint16_t, zip_uint16_t, const zip_uint8_t *, zip_uint16_t, zip_flags_t); +ZIP_EXTERN zip_int16_t zip_file_extra_fields_count(zip_t *, zip_uint64_t, zip_flags_t); +ZIP_EXTERN zip_int16_t zip_file_extra_fields_count_by_id(zip_t *, zip_uint64_t, zip_uint16_t, zip_flags_t); +ZIP_EXTERN const zip_uint8_t *zip_file_extra_field_get(zip_t *, zip_uint64_t, zip_uint16_t, zip_uint16_t *, zip_uint16_t *, zip_flags_t); +ZIP_EXTERN const zip_uint8_t *zip_file_extra_field_get_by_id(zip_t *, zip_uint64_t, zip_uint16_t, zip_uint16_t, zip_uint16_t *, zip_flags_t); +ZIP_EXTERN const char *zip_file_get_comment(zip_t *, zip_uint64_t, zip_uint32_t *, zip_flags_t); +ZIP_EXTERN zip_error_t *zip_file_get_error(zip_file_t *); +ZIP_EXTERN int zip_file_get_external_attributes(zip_t *, zip_uint64_t, zip_flags_t, zip_uint8_t *, zip_uint32_t *); +ZIP_EXTERN int zip_file_rename(zip_t *, zip_uint64_t, const char *, zip_flags_t); +ZIP_EXTERN int zip_file_replace(zip_t *, zip_uint64_t, zip_source_t *, zip_flags_t); +ZIP_EXTERN int zip_file_set_comment(zip_t *, zip_uint64_t, const char *, zip_uint16_t, zip_flags_t); +ZIP_EXTERN int zip_file_set_external_attributes(zip_t *, zip_uint64_t, zip_flags_t, zip_uint8_t, zip_uint32_t); +ZIP_EXTERN int zip_file_set_mtime(zip_t *, zip_uint64_t, time_t, zip_flags_t); +ZIP_EXTERN const char *zip_file_strerror(zip_file_t *); +ZIP_EXTERN zip_file_t *zip_fopen(zip_t *, const char *, zip_flags_t); +ZIP_EXTERN zip_file_t *zip_fopen_encrypted(zip_t *, const char *, zip_flags_t, const char *); +ZIP_EXTERN zip_file_t *zip_fopen_index(zip_t *, zip_uint64_t, zip_flags_t); +ZIP_EXTERN zip_file_t *zip_fopen_index_encrypted(zip_t *, zip_uint64_t, zip_flags_t, const char *); +ZIP_EXTERN zip_int64_t zip_fread(zip_file_t *, void *, zip_uint64_t); +ZIP_EXTERN const char *zip_get_archive_comment(zip_t *, int *, zip_flags_t); +ZIP_EXTERN int zip_get_archive_flag(zip_t *, zip_flags_t, zip_flags_t); +ZIP_EXTERN const char *zip_get_name(zip_t *, zip_uint64_t, zip_flags_t); +ZIP_EXTERN zip_int64_t zip_get_num_entries(zip_t *, zip_flags_t); +ZIP_EXTERN zip_int64_t zip_name_locate(zip_t *, const char *, zip_flags_t); +ZIP_EXTERN zip_t *zip_open(const char *, int, int *); +ZIP_EXTERN zip_t *zip_open_from_source(zip_source_t *, int, zip_error_t *); +ZIP_EXTERN int zip_set_archive_comment(zip_t *, const char *, zip_uint16_t); +ZIP_EXTERN int zip_set_archive_flag(zip_t *, zip_flags_t, int); +ZIP_EXTERN int zip_set_default_password(zip_t *, const char *); +ZIP_EXTERN int zip_set_file_compression(zip_t *, zip_uint64_t, zip_int32_t, zip_uint32_t); +ZIP_EXTERN int zip_source_begin_write(zip_source_t *); +ZIP_EXTERN zip_source_t *zip_source_buffer(zip_t *, const void *, zip_uint64_t, int); +ZIP_EXTERN zip_source_t *zip_source_buffer_create(const void *, zip_uint64_t, int, zip_error_t *); +ZIP_EXTERN int zip_source_close(zip_source_t *); +ZIP_EXTERN int zip_source_commit_write(zip_source_t *); +ZIP_EXTERN zip_error_t *zip_source_error(zip_source_t *src); +ZIP_EXTERN zip_source_t *zip_source_file(zip_t *, const char *, zip_uint64_t, zip_int64_t); +ZIP_EXTERN zip_source_t *zip_source_file_create(const char *, zip_uint64_t, zip_int64_t, zip_error_t *); +ZIP_EXTERN zip_source_t *zip_source_filep(zip_t *, FILE *, zip_uint64_t, zip_int64_t); +ZIP_EXTERN zip_source_t *zip_source_filep_create(FILE *, zip_uint64_t, zip_int64_t, zip_error_t *); +ZIP_EXTERN void zip_source_free(zip_source_t *); +ZIP_EXTERN zip_source_t *zip_source_function(zip_t *, zip_source_callback, void *); +ZIP_EXTERN zip_source_t *zip_source_function_create(zip_source_callback, void *, zip_error_t *); +ZIP_EXTERN int zip_source_is_deleted(zip_source_t *); +ZIP_EXTERN void zip_source_keep(zip_source_t *); +ZIP_EXTERN zip_int64_t zip_source_make_command_bitmap(zip_source_cmd_t, ...); +ZIP_EXTERN int zip_source_open(zip_source_t *); +ZIP_EXTERN zip_int64_t zip_source_read(zip_source_t *, void *, zip_uint64_t); +ZIP_EXTERN void zip_source_rollback_write(zip_source_t *); +ZIP_EXTERN int zip_source_seek(zip_source_t *, zip_int64_t, int); +ZIP_EXTERN zip_int64_t zip_source_seek_compute_offset(zip_uint64_t, zip_uint64_t, void *, zip_uint64_t, zip_error_t *); +ZIP_EXTERN int zip_source_seek_write(zip_source_t *, zip_int64_t, int); +ZIP_EXTERN int zip_source_stat(zip_source_t *, zip_stat_t *); +ZIP_EXTERN zip_int64_t zip_source_tell(zip_source_t *); +ZIP_EXTERN zip_int64_t zip_source_tell_write(zip_source_t *); +#ifdef _WIN32 +ZIP_EXTERN zip_source_t *zip_source_win32a(zip_t *, const char *, zip_uint64_t, zip_int64_t); +ZIP_EXTERN zip_source_t *zip_source_win32a_create(const char *, zip_uint64_t, zip_int64_t, zip_error_t *); +ZIP_EXTERN zip_source_t *zip_source_win32handle(zip_t *, void *, zip_uint64_t, zip_int64_t); +ZIP_EXTERN zip_source_t *zip_source_win32handle_create(void *, zip_uint64_t, zip_int64_t, zip_error_t *); +ZIP_EXTERN zip_source_t *zip_source_win32w(zip_t *, const wchar_t *, zip_uint64_t, zip_int64_t); +ZIP_EXTERN zip_source_t *zip_source_win32w_create(const wchar_t *, zip_uint64_t, zip_int64_t, zip_error_t *); +#endif +ZIP_EXTERN zip_int64_t zip_source_write(zip_source_t *, const void *, zip_uint64_t); +ZIP_EXTERN zip_source_t *zip_source_zip(zip_t *, zip_t *, zip_uint64_t, zip_flags_t, zip_uint64_t, zip_int64_t); +ZIP_EXTERN int zip_stat(zip_t *, const char *, zip_flags_t, zip_stat_t *); +ZIP_EXTERN int zip_stat_index(zip_t *, zip_uint64_t, zip_flags_t, zip_stat_t *); +ZIP_EXTERN void zip_stat_init(zip_stat_t *); +ZIP_EXTERN const char *zip_strerror(zip_t *); +ZIP_EXTERN int zip_unchange(zip_t *, zip_uint64_t); +ZIP_EXTERN int zip_unchange_all(zip_t *); +ZIP_EXTERN int zip_unchange_archive(zip_t *); #ifdef __cplusplus } diff --git a/ePub3/ThirdParty/libzip/zip_add.c b/ePub3/ThirdParty/libzip/zip_add.c index f6bdb2ab9..d1be133b6 100644 --- a/ePub3/ThirdParty/libzip/zip_add.c +++ b/ePub3/ThirdParty/libzip/zip_add.c @@ -1,6 +1,6 @@ /* zip_add.c -- add file via callback function - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,19 +31,20 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - +#define _ZIP_COMPILING_DEPRECATED #include "zipint.h" - -ZIP_EXTERN int -zip_add(struct zip *za, const char *name, struct zip_source *source) +/* + NOTE: Return type is signed so we can return -1 on error. + The index can not be larger than ZIP_INT64_MAX since the size + of the central directory cannot be larger than + ZIP_UINT64_MAX, and each entry is larger than 2 bytes. +*/ + +ZIP_EXTERN zip_int64_t +zip_add(zip_t *za, const char *name, zip_source_t *source) { - if (name == NULL || source == NULL) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); - return -1; - } - - return _zip_replace(za, -1, name, source); + return zip_file_add(za, name, source, 0); } diff --git a/ePub3/ThirdParty/libzip/zip_add_dir.c b/ePub3/ThirdParty/libzip/zip_add_dir.c index 32683927d..14bdeda11 100644 --- a/ePub3/ThirdParty/libzip/zip_add_dir.c +++ b/ePub3/ThirdParty/libzip/zip_add_dir.c @@ -1,6 +1,6 @@ /* zip_add_dir.c -- add directory - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,51 +31,15 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - - -#include -#include +#define _ZIP_COMPILING_DEPRECATED #include "zipint.h" - - -ZIP_EXTERN int -zip_add_dir(struct zip *za, const char *name) -{ - size_t len; - int ret; - char *s; - struct zip_source *source; - - if (name == NULL) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); - return -1; - } - s = NULL; - len = strlen(name); +/* NOTE: Signed due to -1 on error. See zip_add.c for more details. */ - if (name[len-1] != '/') { - if ((s=(char *)malloc(len+2)) == NULL) { - _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); - return -1; - } - strcpy(s, name); - s[len] = '/'; - s[len+1] = '\0'; - } - - if ((source=zip_source_buffer(za, NULL, 0, 0)) == NULL) { - free(s); - return -1; - } - - ret = _zip_replace(za, -1, s ? s : name, source); - - free(s); - if (ret < 0) - zip_source_free(source); - - return ret; +ZIP_EXTERN zip_int64_t +zip_add_dir(zip_t *za, const char *name) +{ + return zip_dir_add(za, name, 0); } diff --git a/ePub3/ThirdParty/libzip/zip_add_entry.c b/ePub3/ThirdParty/libzip/zip_add_entry.c new file mode 100644 index 000000000..24dbdaf47 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_add_entry.c @@ -0,0 +1,70 @@ +/* + zip_add_entry.c -- create and init struct zip_entry + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include + +#include "zipint.h" + + +/* NOTE: Signed due to -1 on error. See zip_add.c for more details. */ + +zip_int64_t +_zip_add_entry(zip_t *za) +{ + zip_uint64_t idx; + + if (za->nentry+1 >= za->nentry_alloc) { + zip_entry_t *rentries; + zip_uint64_t nalloc = za->nentry_alloc + 16; + zip_uint64_t realloc_size = sizeof(struct zip_entry) * (size_t)nalloc; + + if (sizeof(struct zip_entry) * (size_t)za->nentry_alloc > realloc_size) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return -1; + } + rentries = (zip_entry_t *)realloc(za->entry, sizeof(struct zip_entry) * (size_t)nalloc); + if (!rentries) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return -1; + } + za->entry = rentries; + za->nentry_alloc = nalloc; + } + + idx = za->nentry++; + + _zip_entry_init(za->entry+idx); + + return (zip_int64_t)idx; +} diff --git a/ePub3/ThirdParty/libzip/zip_buffer.c b/ePub3/ThirdParty/libzip/zip_buffer.c new file mode 100644 index 000000000..3d79b09f1 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_buffer.c @@ -0,0 +1,310 @@ +/* + zip_buffer.c -- bounds checked access to memory buffer + Copyright (C) 2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include "zipint.h" + +zip_uint8_t * +_zip_buffer_data(zip_buffer_t *buffer) +{ + return buffer->data; +} + + +void +_zip_buffer_free(zip_buffer_t *buffer) +{ + if (buffer == NULL) { + return; + } + + if (buffer->free_data) { + free(buffer->data); + } + + free(buffer); +} + + +bool +_zip_buffer_eof(zip_buffer_t *buffer) +{ + return buffer->ok && buffer->offset == buffer->size; +} + + +zip_uint8_t * +_zip_buffer_get(zip_buffer_t *buffer, zip_uint64_t length) +{ + zip_uint8_t *data; + + if (!buffer->ok || buffer->offset + length < length || buffer->offset + length > buffer->size) { + buffer->ok = false; + return NULL; + } + + data = buffer->data + buffer->offset; + buffer->offset += length; + return data; +} + + +zip_uint16_t +_zip_buffer_get_16(zip_buffer_t *buffer) +{ + zip_uint8_t *data = _zip_buffer_get(buffer, 2); + + if (data == NULL) { + return 0; + } + + return (zip_uint16_t)(data[0] + (data[1] << 8)); +} + + +zip_uint32_t +_zip_buffer_get_32(zip_buffer_t *buffer) +{ + zip_uint8_t *data = _zip_buffer_get(buffer, 4); + + if (data == NULL) { + return 0; + } + + return ((((((zip_uint32_t)data[3] << 8) + data[2]) << 8) + data[1]) << 8) + data[0]; +} + + +zip_uint64_t +_zip_buffer_get_64(zip_buffer_t *buffer) +{ + zip_uint8_t *data = _zip_buffer_get(buffer, 8); + + if (data == NULL) { + return 0; + } + + return ((zip_uint64_t)data[7] << 56) + ((zip_uint64_t)data[6] << 48) + ((zip_uint64_t)data[5] << 40) + ((zip_uint64_t)data[4] << 32) + ((zip_uint64_t)data[3] << 24) + ((zip_uint64_t)data[2] << 16) + ((zip_uint64_t)data[1] << 8) + (zip_uint64_t)data[0]; +} + + + +zip_uint8_t +_zip_buffer_get_8(zip_buffer_t *buffer) +{ + zip_uint8_t *data = _zip_buffer_get(buffer, 1); + + if (data == NULL) { + return 0; + } + + return data[0]; +} + + +zip_uint64_t +_zip_buffer_left(zip_buffer_t *buffer) +{ + return buffer->ok ? buffer->size - buffer->offset : 0; +} + + +zip_buffer_t * +_zip_buffer_new(zip_uint8_t *data, zip_uint64_t size) +{ + bool free_data = (data == NULL); + zip_buffer_t *buffer; + + if (data == NULL) { + if ((data = (zip_uint8_t *)malloc(size)) == NULL) { + return NULL; + } + } + + if ((buffer = (zip_buffer_t *)malloc(sizeof(*buffer))) == NULL) { + if (free_data) { + free(data); + } + return NULL; + } + + buffer->ok = true; + buffer->data = data; + buffer->size = size; + buffer->offset = 0; + buffer->free_data = free_data; + + return buffer; +} + + +zip_buffer_t * +_zip_buffer_new_from_source(zip_source_t *src, zip_uint64_t size, zip_uint8_t *buf, zip_error_t *error) +{ + zip_buffer_t *buffer; + + if ((buffer = _zip_buffer_new(buf, size)) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + return NULL; + } + + if (_zip_read(src, buffer->data, size, error) < 0) { + _zip_buffer_free(buffer); + return NULL; + } + + return buffer; +} + + +zip_uint64_t +_zip_buffer_offset(zip_buffer_t *buffer) +{ + return buffer->ok ? buffer->offset : 0; +} + + +bool +_zip_buffer_ok(zip_buffer_t *buffer) +{ + return buffer->ok; +} + + +int +_zip_buffer_put(zip_buffer_t *buffer, const void *src, size_t length) +{ + zip_uint8_t *dst = _zip_buffer_get(buffer, length); + + if (dst == NULL) { + return -1; + } + + memcpy(dst, src, length); + return 0; +} + + +int +_zip_buffer_put_16(zip_buffer_t *buffer, zip_uint16_t i) +{ + zip_uint8_t *data = _zip_buffer_get(buffer, 2); + + if (data == NULL) { + return -1; + } + + data[0] = (zip_uint8_t)(i & 0xff); + data[1] = (zip_uint8_t)((i >> 8) & 0xff); + + return 0; +} + + +int +_zip_buffer_put_32(zip_buffer_t *buffer, zip_uint32_t i) +{ + zip_uint8_t *data = _zip_buffer_get(buffer, 4); + + if (data == NULL) { + return -1; + } + + data[0] = (zip_uint8_t)(i & 0xff); + data[1] = (zip_uint8_t)((i >> 8) & 0xff); + data[2] = (zip_uint8_t)((i >> 16) & 0xff); + data[3] = (zip_uint8_t)((i >> 24) & 0xff); + + return 0; +} + + +int +_zip_buffer_put_64(zip_buffer_t *buffer, zip_uint64_t i) +{ + zip_uint8_t *data = _zip_buffer_get(buffer, 8); + + if (data == NULL) { + return -1; + } + + data[0] = (zip_uint8_t)(i & 0xff); + data[1] = (zip_uint8_t)((i >> 8) & 0xff); + data[2] = (zip_uint8_t)((i >> 16) & 0xff); + data[3] = (zip_uint8_t)((i >> 24) & 0xff); + data[4] = (zip_uint8_t)((i >> 32) & 0xff); + data[5] = (zip_uint8_t)((i >> 40) & 0xff); + data[6] = (zip_uint8_t)((i >> 48) & 0xff); + data[7] = (zip_uint8_t)((i >> 56) & 0xff); + + return 0; +} + + +int +_zip_buffer_put_8(zip_buffer_t *buffer, zip_uint8_t i) +{ + zip_uint8_t *data = _zip_buffer_get(buffer, 1); + + if (data == NULL) { + return -1; + } + + data[0] = i; + + return 0; +} + + +int +_zip_buffer_set_offset(zip_buffer_t *buffer, zip_uint64_t offset) +{ + if (offset > buffer->size) { + buffer->ok = false; + return -1; + } + + buffer->ok = true; + buffer->offset = offset; + + return 0; +} + + +zip_uint64_t +_zip_buffer_size(zip_buffer_t *buffer) +{ + return buffer->size; +} diff --git a/ePub3/ThirdParty/libzip/zip_close.c b/ePub3/ThirdParty/libzip/zip_close.c index e42ba8b48..a13e4466b 100644 --- a/ePub3/ThirdParty/libzip/zip_close.c +++ b/ePub3/ThirdParty/libzip/zip_close.c @@ -1,6 +1,6 @@ /* zip_close.c -- close zip archive and update changes - Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,537 +31,380 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - + +#include "zipint.h" #include #include #include -#ifdef _MSC_VER -#include -#else -#include +#ifdef HAVE_STRINGS_H +#include #endif #include +#ifdef HAVE_UNISTD_H +#include +#endif #include #include +#ifdef _WIN32 +#include +#include +#endif -#include "zipint.h" -#if defined(_MSC_VER) -# define strdup _strdup -# define fseeko fseek -# define ftello ftell -# define fileno _fileno -# define fdopen _fdopen -# define strcasecmp _stricmp -typedef unsigned short mode_t; -# define mkstemp _zip_mkstemp -# define close(x) _close(x) -extern int _zip_mkstemp(char *path); -#endif +/* max deflate size increase: size + ceil(size/16k)*5+6 */ +#define MAX_DEFLATE_SIZE_32 4293656963u + +static int add_data(zip_t *, zip_source_t *, zip_dirent_t *); +static int copy_data(zip_t *, zip_uint64_t); +static int copy_source(zip_t *, zip_source_t *); +static int write_cdir(zip_t *, const zip_filelist_t *, zip_uint64_t); -static int add_data(struct zip *, struct zip_source *, struct zip_dirent *, - FILE *); -static int add_data_comp(zip_source_callback, void *, struct zip_stat *, - FILE *, struct zip_error *); -static int add_data_uncomp(struct zip *, zip_source_callback, void *, - struct zip_stat *, FILE *); -static void ch_set_error(struct zip_error *, zip_source_callback, void *); -static int copy_data(FILE *, off_t, FILE *, struct zip_error *); -static int write_cdir(struct zip *, struct zip_cdir *, FILE *); -static int _zip_cdir_set_comment(struct zip_cdir *, struct zip *); -static int _zip_changed(struct zip *, int *); -static char *_zip_create_temp_output(struct zip *, FILE **); -static int _zip_torrentzip_cmp(const void *, const void *); - - - -struct filelist { - int idx; - const char *name; -}; - - ZIP_EXTERN int -zip_close(struct zip *za) +zip_close(zip_t *za) { - int survivors; - int i, j, error; - char *temp; - FILE *out; -#ifndef _MSC_VER - mode_t mask; -#endif - struct zip_cdir *cd; - struct zip_dirent de; - struct filelist *filelist; - int reopen_on_error; - int new_torrentzip; - - reopen_on_error = 0; - + zip_uint64_t i, j, survivors; + zip_int64_t off; + int error; + zip_filelist_t *filelist; + int changed; + if (za == NULL) - return -1; - - if (!_zip_changed(za, &survivors)) { - _zip_free(za); - return 0; - } - + return -1; + + changed = _zip_changed(za, &survivors); + /* don't create zip files with no entries */ if (survivors == 0) { - if (za->zn && za->zp) { - if (remove(za->zn) != 0) { - _zip_error_set(&za->error, ZIP_ER_REMOVE, errno); - return -1; - } - } - _zip_free(za); - return 0; + if ((za->open_flags & ZIP_TRUNCATE) || changed) { + if (zip_source_remove(za->src) < 0) { + _zip_error_set_from_source(&za->error, za->src); + return -1; + } + } + zip_discard(za); + return 0; + } + + if (!changed) { + zip_discard(za); + return 0; } - - if ((filelist=(struct filelist *)malloc(sizeof(filelist[0])*survivors)) - == NULL) - return -1; - - if ((cd=_zip_cdir_new(survivors, &za->error)) == NULL) { - free(filelist); + + if (survivors > za->nentry) { + zip_error_set(&za->error, ZIP_ER_INTERNAL, 0); return -1; } - for (i=0; ientry[i]); - - /* archive comment is special for torrentzip */ - if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0)) { - cd->comment = (char*)_zip_memdup((void*)(TORRENT_SIG "XXXXXXXX"), - TORRENT_SIG_LEN + TORRENT_CRC_LEN, - &za->error); - if (cd->comment == NULL) { - _zip_cdir_free(cd); - free(filelist); - return -1; - } - cd->comment_len = TORRENT_SIG_LEN + TORRENT_CRC_LEN; - } - else if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, ZIP_FL_UNCHANGED) == 0) { - if (_zip_cdir_set_comment(cd, za) == -1) { - _zip_cdir_free(cd); + if ((filelist=(zip_filelist_t *)malloc(sizeof(filelist[0])*(size_t)survivors)) == NULL) + return -1; + + /* create list of files with index into original archive */ + for (i=j=0; inentry; i++) { + if (za->entry[i].deleted) + continue; + + if (j >= survivors) { free(filelist); + zip_error_set(&za->error, ZIP_ER_INTERNAL, 0); return -1; } + + filelist[j].idx = i; + j++; } - - if ((temp=_zip_create_temp_output(za, &out)) == NULL) { - _zip_cdir_free(cd); + if (j < survivors) { free(filelist); + zip_error_set(&za->error, ZIP_ER_INTERNAL, 0); return -1; } - - - /* create list of files with index into original archive */ - for (i=j=0; inentry; i++) { - if (za->entry[i].state == ZIP_ST_DELETED) - continue; - - filelist[j].idx = i; - filelist[j].name = zip_get_name(za, i, 0); - j++; + + if (zip_source_begin_write(za->src) < 0) { + _zip_error_set_from_source(&za->error, za->src); + free(filelist); + return -1; } - survivors = j; - if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0)) - qsort(filelist, survivors, sizeof(filelist[0]), - _zip_torrentzip_cmp); - - new_torrentzip = (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0) == 1 - && zip_get_archive_flag(za, ZIP_AFL_TORRENT, - ZIP_FL_UNCHANGED) == 0); error = 0; for (j=0; jentry+i) || new_torrentzip) { - _zip_dirent_init(&de); - - if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0)) - _zip_dirent_torrent_normalize(&de); - - /* use it as central directory entry */ - memcpy(cd->entry+j, &de, sizeof(cd->entry[j])); - - /* set/update file name */ - if (za->entry[i].ch_filename == NULL) { - if (za->entry[i].state == ZIP_ST_ADDED) { - de.filename = strdup("-"); - de.filename_len = 1; - cd->entry[j].filename = "-"; - cd->entry[j].filename_len = 1; - } - else { - de.filename = strdup(za->cdir->entry[i].filename); - de.filename_len = (unsigned short)strlen(de.filename); - cd->entry[j].filename = za->cdir->entry[i].filename; - cd->entry[j].filename_len = de.filename_len; - } - } - } - else { - /* copy existing directory entries */ - if (fseeko(za->zp, za->cdir->entry[i].offset, SEEK_SET) != 0) { - _zip_error_set(&za->error, ZIP_ER_SEEK, errno); - error = 1; - break; - } - if (_zip_dirent_read(&de, za->zp, NULL, NULL, 1, - &za->error) != 0) { - error = 1; - break; - } - memcpy(cd->entry+j, za->cdir->entry+i, sizeof(cd->entry[j])); - if (de.bitflags & ZIP_GPBF_DATA_DESCRIPTOR) { - de.crc = za->cdir->entry[i].crc; - de.comp_size = za->cdir->entry[i].comp_size; - de.uncomp_size = za->cdir->entry[i].uncomp_size; - de.bitflags &= ~ZIP_GPBF_DATA_DESCRIPTOR; - cd->entry[j].bitflags &= ~ZIP_GPBF_DATA_DESCRIPTOR; - } - } - - if (za->entry[i].ch_filename) { - free(de.filename); - if ((de.filename=strdup(za->entry[i].ch_filename)) == NULL) { - error = 1; - break; - } - de.filename_len = (unsigned short)strlen(de.filename); - cd->entry[j].filename = za->entry[i].ch_filename; - cd->entry[j].filename_len = de.filename_len; - } - - if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0) == 0 - && za->entry[i].ch_comment_len != -1) { - /* as the rest of cd entries, its malloc/free is done by za */ - cd->entry[j].comment = za->entry[i].ch_comment; - cd->entry[j].comment_len = za->entry[i].ch_comment_len; - } - - cd->entry[j].offset = (unsigned int)ftello(out); - - if (ZIP_ENTRY_DATA_CHANGED(za->entry+i) || new_torrentzip) { - struct zip_source *zs; - - zs = NULL; - if (!ZIP_ENTRY_DATA_CHANGED(za->entry+i)) { - if ((zs=zip_source_zip(za, za, i, ZIP_FL_RECOMPRESS, 0, -1)) - == NULL) { - error = 1; - break; - } - } - - if (add_data(za, zs ? zs : za->entry[i].source, &de, out) < 0) { - error = 1; - break; - } - cd->entry[j].last_mod = de.last_mod; - cd->entry[j].comp_method = de.comp_method; - cd->entry[j].comp_size = de.comp_size; - cd->entry[j].uncomp_size = de.uncomp_size; - cd->entry[j].crc = de.crc; - } - else { - if (_zip_dirent_write(&de, out, 1, &za->error) < 0) { - error = 1; - break; - } - /* we just read the local dirent, file is at correct position */ - if (copy_data(za->zp, cd->entry[j].comp_size, out, - &za->error) < 0) { + int new_data; + zip_entry_t *entry; + zip_dirent_t *de; + + i = filelist[j].idx; + entry = za->entry+i; + + new_data = (ZIP_ENTRY_DATA_CHANGED(entry) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_COMP_METHOD)); + + /* create new local directory entry */ + if (entry->changes == NULL) { + if ((entry->changes=_zip_dirent_clone(entry->orig)) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); error = 1; break; - } + } + } + de = entry->changes; + + if (_zip_read_local_ef(za, i) < 0) { + error = 1; + break; + } + + if ((off = zip_source_tell_write(za->src)) < 0) { + error = 1; + break; } - - _zip_dirent_finalize(&de); + de->offset = (zip_uint64_t)off; + + if (new_data) { + zip_source_t *zs; + + zs = NULL; + if (!ZIP_ENTRY_DATA_CHANGED(entry)) { + if ((zs=_zip_source_zip_new(za, za, i, ZIP_FL_UNCHANGED, 0, 0, NULL)) == NULL) { + error = 1; + break; + } + } + + /* add_data writes dirent */ + if (add_data(za, zs ? zs : entry->source, de) < 0) { + error = 1; + if (zs) + zip_source_free(zs); + break; + } + if (zs) + zip_source_free(zs); + } + else { + zip_uint64_t offset; + + /* when copying data, all sizes are known -> no data descriptor needed */ + de->bitflags &= (zip_uint16_t)~ZIP_GPBF_DATA_DESCRIPTOR; + if (_zip_dirent_write(za, de, ZIP_FL_LOCAL) < 0) { + error = 1; + break; + } + if ((offset=_zip_file_get_offset(za, i, &za->error)) == 0) { + error = 1; + break; + } + if (zip_source_seek(za->src, (zip_int64_t)offset, SEEK_SET) < 0) { + _zip_error_set_from_source(&za->error, za->src); + error = 1; + break; + } + if (copy_data(za, de->comp_size) < 0) { + error = 1; + break; + } + } } - + + if (!error) { + if (write_cdir(za, filelist, survivors) < 0) + error = 1; + } + free(filelist); - + if (!error) { - if (write_cdir(za, cd, out) < 0) - error = 1; + if (zip_source_commit_write(za->src) != 0) { + _zip_error_set_from_source(&za->error, za->src); + error = 1; + } } - - /* pointers in cd entries are owned by za */ - cd->nentry = 0; - _zip_cdir_free(cd); - + if (error) { - _zip_dirent_finalize(&de); - fclose(out); - remove(temp); - free(temp); - return -1; - } - - if (fclose(out) != 0) { - _zip_error_set(&za->error, ZIP_ER_CLOSE, errno); - remove(temp); - free(temp); - return -1; - } - - if (za->zp) { - fclose(za->zp); - za->zp = NULL; - reopen_on_error = 1; - } - if (_zip_rename(temp, za->zn) != 0) { - _zip_error_set(&za->error, ZIP_ER_RENAME, errno); - remove(temp); - free(temp); - if (reopen_on_error) { - /* ignore errors, since we're already in an error case */ - za->zp = fopen(za->zn, "rb"); - } - return -1; + zip_source_rollback_write(za->src); + return -1; } -#ifndef _MSC_VER - mask = umask(0); - umask(mask); - chmod(za->zn, 0666&~mask); -#endif - _zip_free(za); - free(temp); + + zip_discard(za); return 0; } - static int -add_data(struct zip *za, struct zip_source *zs, struct zip_dirent *de, FILE *ft) +add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de) { - off_t offstart, offend; - zip_source_callback cb; - void *ud; + zip_int64_t offstart, offdata, offend; struct zip_stat st; + zip_source_t *s2; + int ret; + int is_zip64; + zip_flags_t flags; - cb = zs->f; - ud = zs->ud; - - if (cb(ud, &st, sizeof(st), ZIP_SOURCE_STAT) < (ssize_t)sizeof(st)) { - ch_set_error(&za->error, cb, ud); + if (zip_source_stat(src, &st) < 0) { + _zip_error_set_from_source(&za->error, src); return -1; } - if (cb(ud, NULL, 0, ZIP_SOURCE_OPEN) < 0) { - ch_set_error(&za->error, cb, ud); - return -1; + if ((st.valid & ZIP_STAT_COMP_METHOD) == 0) { + st.valid |= ZIP_STAT_COMP_METHOD; + st.comp_method = ZIP_CM_STORE; } - offstart = ftello(ft); - - if (_zip_dirent_write(de, ft, 1, &za->error) < 0) - return -1; - - if (st.comp_method != ZIP_CM_STORE) { - if (add_data_comp(cb, ud, &st, ft, &za->error) < 0) - return -1; + if (ZIP_CM_IS_DEFAULT(de->comp_method) && st.comp_method != ZIP_CM_STORE) + de->comp_method = st.comp_method; + else if (de->comp_method == ZIP_CM_STORE && (st.valid & ZIP_STAT_SIZE)) { + st.valid |= ZIP_STAT_COMP_SIZE; + st.comp_size = st.size; } else { - if (add_data_uncomp(za, cb, ud, &st, ft) < 0) - return -1; + /* we'll recompress */ + st.valid &= ~ZIP_STAT_COMP_SIZE; } - if (cb(ud, NULL, 0, ZIP_SOURCE_CLOSE) < 0) { - ch_set_error(&za->error, cb, ud); - return -1; - } - offend = ftello(ft); + flags = ZIP_EF_LOCAL; - if (fseeko(ft, offstart, SEEK_SET) < 0) { - _zip_error_set(&za->error, ZIP_ER_SEEK, errno); - return -1; + if ((st.valid & ZIP_STAT_SIZE) == 0) + flags |= ZIP_FL_FORCE_ZIP64; + else { + de->uncomp_size = st.size; + + if ((st.valid & ZIP_STAT_COMP_SIZE) == 0) { + if (( ((de->comp_method == ZIP_CM_DEFLATE || ZIP_CM_IS_DEFAULT(de->comp_method)) && st.size > MAX_DEFLATE_SIZE_32) + || (de->comp_method != ZIP_CM_STORE && de->comp_method != ZIP_CM_DEFLATE && !ZIP_CM_IS_DEFAULT(de->comp_method)))) + flags |= ZIP_FL_FORCE_ZIP64; + } + else + de->comp_size = st.comp_size; } - - de->last_mod = st.mtime; - de->comp_method = st.comp_method; - de->crc = st.crc; - de->uncomp_size = (unsigned int)st.size; - de->comp_size = (unsigned int)st.comp_size; - - if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0)) - _zip_dirent_torrent_normalize(de); - - if (_zip_dirent_write(de, ft, 1, &za->error) < 0) - return -1; - - if (fseeko(ft, offend, SEEK_SET) < 0) { - _zip_error_set(&za->error, ZIP_ER_SEEK, errno); - return -1; + if ((offstart = zip_source_tell_write(za->src)) < 0) { + return -1; } - return 0; -} - - - -static int -add_data_comp(zip_source_callback cb, void *ud, struct zip_stat *st,FILE *ft, - struct zip_error *error) -{ - char buf[BUFSIZE]; - ssize_t n; - - st->comp_size = 0; - while ((n=cb(ud, buf, sizeof(buf), ZIP_SOURCE_READ)) > 0) { - if (fwrite(buf, 1, n, ft) != (size_t)n) { - _zip_error_set(error, ZIP_ER_WRITE, errno); - return -1; - } - - st->comp_size += n; - } - if (n < 0) { - ch_set_error(error, cb, ud); + /* as long as we don't support non-seekable output, clear data descriptor bit */ + de->bitflags &= (zip_uint16_t)~ZIP_GPBF_DATA_DESCRIPTOR; + if ((is_zip64=_zip_dirent_write(za, de, flags)) < 0) return -1; - } - - return 0; -} - -static int -add_data_uncomp(struct zip *za, zip_source_callback cb, void *ud, - struct zip_stat *st, FILE *ft) -{ - char b1[BUFSIZE], b2[BUFSIZE]; - int end, flush, ret; - ssize_t n; - size_t n2; - z_stream zstr; - int mem_level; - - st->comp_method = ZIP_CM_DEFLATE; - st->comp_size = st->size = 0; - st->crc = (unsigned int)crc32(0, NULL, 0); - - zstr.zalloc = Z_NULL; - zstr.zfree = Z_NULL; - zstr.opaque = NULL; - zstr.avail_in = 0; - zstr.avail_out = 0; - - if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0)) - mem_level = TORRENT_MEM_LEVEL; - else - mem_level = MAX_MEM_LEVEL; - - /* -MAX_WBITS: undocumented feature of zlib to _not_ write a zlib header */ - deflateInit2(&zstr, Z_BEST_COMPRESSION, Z_DEFLATED, -MAX_WBITS, mem_level, - Z_DEFAULT_STRATEGY); - - zstr.next_out = (Bytef *)b2; - zstr.avail_out = sizeof(b2); - zstr.next_in = NULL; - zstr.avail_in = 0; - - flush = 0; - end = 0; - while (!end) { - if (zstr.avail_in == 0 && !flush) { - if ((n=cb(ud, b1, sizeof(b1), ZIP_SOURCE_READ)) < 0) { - ch_set_error(&za->error, cb, ud); - deflateEnd(&zstr); + if (st.comp_method == ZIP_CM_STORE || (ZIP_CM_IS_DEFAULT(de->comp_method) && st.comp_method != de->comp_method)) { + zip_source_t *s_store, *s_crc; + zip_compression_implementation comp_impl; + + if (st.comp_method != ZIP_CM_STORE) { + if ((comp_impl=_zip_get_compression_implementation(st.comp_method)) == NULL) { + zip_error_set(&za->error, ZIP_ER_COMPNOTSUPP, 0); return -1; } - if (n > 0) { - zstr.avail_in = (unsigned int)n; - zstr.next_in = (Bytef *)b1; - st->size += n; - st->crc = (unsigned int)crc32(st->crc, (Bytef *)b1, (unsigned int)n); + if ((s_store=comp_impl(za, src, st.comp_method, ZIP_CODEC_DECODE)) == NULL) { + /* error set by comp_impl */ + return -1; } - else - flush = Z_FINISH; + } + else { + /* to have the same reference count to src as in the case where it's not stored */ + zip_source_keep(src); + s_store = src; } - ret = deflate(&zstr, flush); - if (ret != Z_OK && ret != Z_STREAM_END) { - _zip_error_set(&za->error, ZIP_ER_ZLIB, ret); + s_crc = zip_source_crc(za, s_store, 0); + zip_source_free(s_store); + if (s_crc == NULL) { return -1; } - - if (zstr.avail_out != sizeof(b2)) { - n2 = sizeof(b2) - zstr.avail_out; - - if (fwrite(b2, 1, n2, ft) != n2) { - _zip_error_set(&za->error, ZIP_ER_WRITE, errno); + + if (de->comp_method != ZIP_CM_STORE && ((st.valid & ZIP_STAT_SIZE) == 0 || st.size != 0)) { + if ((comp_impl=_zip_get_compression_implementation(de->comp_method)) == NULL) { + zip_error_set(&za->error, ZIP_ER_COMPNOTSUPP, 0); + zip_source_free(s_crc); + return -1; + } + s2 = comp_impl(za, s_crc, de->comp_method, ZIP_CODEC_ENCODE); + zip_source_free(s_crc); + if (s2 == NULL) { return -1; } - - zstr.next_out = (Bytef *)b2; - zstr.avail_out = sizeof(b2); - st->comp_size += (off_t)n2; } - - if (ret == Z_STREAM_END) { - deflateEnd(&zstr); - end = 1; + else { + s2 = s_crc; } } + else { + zip_source_keep(src); + s2 = src; + } - return 0; -} + if ((offdata = zip_source_tell_write(za->src)) < 0) { + return -1; + } + + ret = copy_source(za, s2); + + if (zip_source_stat(s2, &st) < 0) + ret = -1; - + zip_source_free(s2); -static void -ch_set_error(struct zip_error *error, zip_source_callback cb, void *ud) -{ - int e[2]; + if (ret < 0) + return -1; - if ((cb(ud, e, sizeof(e), ZIP_SOURCE_ERROR)) < (ssize_t)sizeof(e)) { - error->zip_err = ZIP_ER_INTERNAL; - error->sys_err = 0; + if ((offend = zip_source_tell_write(za->src)) < 0) { + return -1; } - else { - error->zip_err = e[0]; - error->sys_err = e[1]; + + if (zip_source_seek_write(za->src, offstart, SEEK_SET) < 0) { + _zip_error_set_from_source(&za->error, za->src); + return -1; + } + + if ((st.valid & (ZIP_STAT_COMP_METHOD|ZIP_STAT_CRC|ZIP_STAT_SIZE)) != (ZIP_STAT_COMP_METHOD|ZIP_STAT_CRC|ZIP_STAT_SIZE)) { + zip_error_set(&za->error, ZIP_ER_INTERNAL, 0); + return -1; } + + if ((de->changed & ZIP_DIRENT_LAST_MOD) == 0) { + if (st.valid & ZIP_STAT_MTIME) + de->last_mod = st.mtime; + else + time(&de->last_mod); + } + de->comp_method = st.comp_method; + de->crc = st.crc; + de->uncomp_size = st.size; + de->comp_size = (zip_uint64_t)(offend - offdata); + + if ((ret=_zip_dirent_write(za, de, flags)) < 0) + return -1; + + if (is_zip64 != ret) { + /* Zip64 mismatch between preliminary file header written before data and final file header written afterwards */ + zip_error_set(&za->error, ZIP_ER_INTERNAL, 0); + return -1; + } + + + if (zip_source_seek_write(za->src, offend, SEEK_SET) < 0) { + _zip_error_set_from_source(&za->error, za->src); + return -1; + } + + return 0; } - static int -copy_data(FILE *fs, off_t len, FILE *ft, struct zip_error *error) +copy_data(zip_t *za, zip_uint64_t len) { - char buf[BUFSIZE]; - ssize_t n; - size_t nn; - - if (len == 0) - return 0; + zip_uint8_t buf[BUFSIZE]; + size_t n; while (len > 0) { - nn = len > sizeof(buf) ? sizeof(buf) : (size_t)len; - if ((n=(ssize_t)fread(buf, 1, nn, fs)) < 0) { - _zip_error_set(error, ZIP_ER_READ, errno); - return -1; - } - else if (n == 0) { - _zip_error_set(error, ZIP_ER_EOF, 0); + n = len > sizeof(buf) ? sizeof(buf) : len; + if (_zip_read(za->src, buf, n, &za->error) < 0) { return -1; } - if (fwrite(buf, 1, n, ft) != (size_t)n) { - _zip_error_set(error, ZIP_ER_WRITE, errno); + if (_zip_write(za, buf, n) < 0) { return -1; } @@ -571,133 +414,80 @@ copy_data(FILE *fs, off_t len, FILE *ft, struct zip_error *error) return 0; } - static int -write_cdir(struct zip *za, struct zip_cdir *cd, FILE *out) +copy_source(zip_t *za, zip_source_t *src) { - off_t offset; - uLong crc; - char buf[TORRENT_CRC_LEN+1]; - - if (_zip_cdir_write(cd, out, &za->error) < 0) - return -1; - - if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0) == 0) - return 0; - + zip_uint8_t buf[BUFSIZE]; + zip_int64_t n; + int ret; - /* fix up torrentzip comment */ - - offset = ftello(out); - - if (_zip_filerange_crc(out, cd->offset, cd->size, &crc, &za->error) < 0) - return -1; - - snprintf(buf, sizeof(buf), "%08lX", (long)crc); - - if (fseeko(out, offset-TORRENT_CRC_LEN, SEEK_SET) < 0) { - _zip_error_set(&za->error, ZIP_ER_SEEK, errno); + if (zip_source_open(src) < 0) { + _zip_error_set_from_source(&za->error, src); return -1; } - if (fwrite(buf, TORRENT_CRC_LEN, 1, out) != 1) { - _zip_error_set(&za->error, ZIP_ER_WRITE, errno); - return -1; + ret = 0; + while ((n=zip_source_read(src, buf, sizeof(buf))) > 0) { + if (_zip_write(za, buf, (zip_uint64_t)n) < 0) { + ret = -1; + break; + } + } + + if (n < 0) { + _zip_error_set_from_source(&za->error, src); + ret = -1; } - return 0; + zip_source_close(src); + + return ret; } - static int -_zip_cdir_set_comment(struct zip_cdir *dest, struct zip *src) +write_cdir(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivors) { - if (src->ch_comment_len != -1) { - dest->comment = (char*)_zip_memdup(src->ch_comment, - src->ch_comment_len, &src->error); - if (dest->comment == NULL) - return -1; - dest->comment_len = src->ch_comment_len; - } else { - if (src->cdir && src->cdir->comment) { - dest->comment = (char*)_zip_memdup(src->cdir->comment, - src->cdir->comment_len, &src->error); - if (dest->comment == NULL) - return -1; - dest->comment_len = src->cdir->comment_len; - } + zip_int64_t cd_start, end, size; + + if ((cd_start = zip_source_tell_write(za->src)) < 0) { + return -1; + } + + if ((size=_zip_cdir_write(za, filelist, survivors)) < 0) { + return -1; + } + + if ((end = zip_source_tell_write(za->src)) < 0) { + return -1; } return 0; } - -static int -_zip_changed(struct zip *za, int *survivorsp) +int +_zip_changed(const zip_t *za, zip_uint64_t *survivorsp) { - int changed, i, survivors; + int changed; + zip_uint64_t i, survivors; - changed = survivors = 0; + changed = 0; + survivors = 0; - if (za->ch_comment_len != -1 - || za->ch_flags != za->flags) + if (za->comment_changed || za->ch_flags != za->flags) changed = 1; for (i=0; inentry; i++) { - if ((za->entry[i].state != ZIP_ST_UNCHANGED) - || (za->entry[i].ch_comment_len != -1)) + if (za->entry[i].deleted || za->entry[i].source || (za->entry[i].changes && za->entry[i].changes->changed != 0)) changed = 1; - if (za->entry[i].state != ZIP_ST_DELETED) + if (!za->entry[i].deleted) survivors++; } - *survivorsp = survivors; + if (survivorsp) + *survivorsp = survivors; return changed; } - - - -static char * -_zip_create_temp_output(struct zip *za, FILE **outp) -{ - char *temp; - int tfd; - FILE *tfp; - - if ((temp=(char *)malloc(strlen(za->zn)+8)) == NULL) { - _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); - return NULL; - } - - sprintf(temp, "%s.XXXXXX", za->zn); - - if ((tfd=mkstemp(temp)) == -1) { - _zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno); - free(temp); - return NULL; - } - - if ((tfp=fdopen(tfd, "r+b")) == NULL) { - _zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno); - close(tfd); - remove(temp); - free(temp); - return NULL; - } - - *outp = tfp; - return temp; -} - - - -static int -_zip_torrentzip_cmp(const void *a, const void *b) -{ - return strcasecmp(((const struct filelist *)a)->name, - ((const struct filelist *)b)->name); -} diff --git a/ePub3/ThirdParty/libzip/zip_delete.c b/ePub3/ThirdParty/libzip/zip_delete.c index a0545e4b9..b3e7abb84 100644 --- a/ePub3/ThirdParty/libzip/zip_delete.c +++ b/ePub3/ThirdParty/libzip/zip_delete.c @@ -1,6 +1,6 @@ /* zip_delete.c -- delete file from zip archive - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,17 +31,20 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "zipint.h" - ZIP_EXTERN int -zip_delete(struct zip *za, int idx) +zip_delete(zip_t *za, zip_uint64_t idx) { - if (idx < 0 || idx >= za->nentry) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); + if (idx >= za->nentry) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (ZIP_IS_RDONLY(za)) { + zip_error_set(&za->error, ZIP_ER_RDONLY, 0); return -1; } @@ -50,9 +53,8 @@ zip_delete(struct zip *za, int idx) if (_zip_unchange(za, idx, 1) != 0) return -1; - za->entry[idx].state = ZIP_ST_DELETED; + za->entry[idx].deleted = 1; return 0; } - diff --git a/ePub3/ThirdParty/libzip/zip_dir_add.c b/ePub3/ThirdParty/libzip/zip_dir_add.c new file mode 100644 index 000000000..f535b21f2 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_dir_add.c @@ -0,0 +1,93 @@ +/* + zip_dir_add.c -- add directory + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include +#include + +#include "zipint.h" + + +/* NOTE: Signed due to -1 on error. See zip_add.c for more details. */ + +ZIP_EXTERN zip_int64_t +zip_dir_add(zip_t *za, const char *name, zip_flags_t flags) +{ + size_t len; + zip_int64_t idx; + char *s; + zip_source_t *source; + + if (ZIP_IS_RDONLY(za)) { + zip_error_set(&za->error, ZIP_ER_RDONLY, 0); + return -1; + } + + if (name == NULL) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + s = NULL; + len = strlen(name); + + if (name[len-1] != '/') { + if ((s=(char *)malloc(len+2)) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return -1; + } + strcpy(s, name); + s[len] = '/'; + s[len+1] = '\0'; + } + + if ((source=zip_source_buffer(za, NULL, 0, 0)) == NULL) { + free(s); + return -1; + } + + idx = _zip_file_replace(za, ZIP_UINT64_MAX, s ? s : name, source, flags); + + free(s); + + if (idx < 0) + zip_source_free(source); + else { + if (zip_file_set_external_attributes(za, (zip_uint64_t)idx, 0, ZIP_OPSYS_DEFAULT, ZIP_EXT_ATTRIB_DEFAULT_DIR) < 0) { + zip_delete(za, (zip_uint64_t)idx); + return -1; + } + } + + return idx; +} diff --git a/ePub3/ThirdParty/libzip/zip_dirent.c b/ePub3/ThirdParty/libzip/zip_dirent.c index 418f671bb..aa55a6862 100644 --- a/ePub3/ThirdParty/libzip/zip_dirent.c +++ b/ePub3/ThirdParty/libzip/zip_dirent.c @@ -1,6 +1,6 @@ /* zip_dirent.c -- read directory entry (local or central), clean dirent - Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,7 +31,6 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include @@ -42,447 +41,773 @@ #include "zipint.h" -#if defined(_MSC_VER) -# define strdup _strdup -# define fseeko fseek -# define ftello ftell -# define fileno _fileno -#endif +static time_t _zip_d2u_time(zip_uint16_t, zip_uint16_t); +static zip_string_t *_zip_dirent_process_ef_utf_8(const zip_dirent_t *de, zip_uint16_t id, zip_string_t *str); +static zip_extra_field_t *_zip_ef_utf8(zip_uint16_t, zip_string_t *, zip_error_t *); -static time_t _zip_d2u_time(int, int); -static char *_zip_readfpstr(FILE *, unsigned int, int, struct zip_error *); -static char *_zip_readstr(unsigned char **, int, int, struct zip_error *); -static void _zip_u2d_time(time_t, unsigned short *, unsigned short *); -static void _zip_write2(unsigned short, FILE *); -static void _zip_write4(unsigned int, FILE *); - - void -_zip_cdir_free(struct zip_cdir *cd) +_zip_cdir_free(zip_cdir_t *cd) { - int i; + zip_uint64_t i; if (!cd) return; for (i=0; inentry; i++) - _zip_dirent_finalize(cd->entry+i); - free(cd->comment); + _zip_entry_finalize(cd->entry+i); free(cd->entry); + _zip_string_free(cd->comment); free(cd); } - -int -_zip_cdir_grow(struct zip_cdir *cd, int nentry, struct zip_error *error) +zip_cdir_t * +_zip_cdir_new(zip_uint64_t nentry, zip_error_t *error) { - struct zip_dirent *entry; - - if (nentry < cd->nentry) { - _zip_error_set(error, ZIP_ER_INTERNAL, 0); - return -1; - } - - if ((entry=((struct zip_dirent *) - realloc(cd->entry, sizeof(*(cd->entry))*nentry))) == NULL) { - _zip_error_set(error, ZIP_ER_MEMORY, 0); - return -1; - } - - cd->nentry = nentry; - cd->entry = entry; - - return 0; -} - - - -struct zip_cdir * -_zip_cdir_new(int nentry, struct zip_error *error) -{ - struct zip_cdir *cd; + zip_cdir_t *cd; + zip_uint64_t i; - if ((cd=(struct zip_cdir *)malloc(sizeof(*cd))) == NULL) { - _zip_error_set(error, ZIP_ER_MEMORY, 0); + if ((cd=(zip_cdir_t *)malloc(sizeof(*cd))) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); return NULL; } - if ((cd->entry=(struct zip_dirent *)malloc(sizeof(*(cd->entry))*nentry)) - == NULL) { - _zip_error_set(error, ZIP_ER_MEMORY, 0); + if (nentry == 0) + cd->entry = NULL; + else if ((nentry > SIZE_MAX/sizeof(*(cd->entry))) || (cd->entry=(zip_entry_t *)malloc(sizeof(*(cd->entry))*(size_t)nentry)) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); free(cd); return NULL; } - /* entries must be initialized by caller */ + for (i=0; ientry+i); - cd->nentry = nentry; + cd->nentry = cd->nentry_alloc = nentry; cd->size = cd->offset = 0; cd->comment = NULL; - cd->comment_len = 0; return cd; } - -int -_zip_cdir_write(struct zip_cdir *cd, FILE *fp, struct zip_error *error) +zip_int64_t +_zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivors) { - int i; + zip_uint64_t offset, size; + zip_string_t *comment; + zip_uint8_t buf[EOCDLEN + EOCD64LEN + EOCD64LOCLEN]; + zip_buffer_t *buffer; + zip_int64_t off; + zip_uint64_t i; + bool is_zip64; + int ret; + + if ((off = zip_source_tell_write(za->src)) < 0) { + _zip_error_set_from_source(&za->error, za->src); + return -1; + } + offset = (zip_uint64_t)off; - cd->offset = (unsigned int)ftello(fp); + is_zip64 = 0; - for (i=0; inentry; i++) { - if (_zip_dirent_write(cd->entry+i, fp, 0, error) != 0) + for (i=0; ientry+filelist[i].idx; + + if ((ret=_zip_dirent_write(za, entry->changes ? entry->changes : entry->orig, ZIP_FL_CENTRAL)) < 0) return -1; + if (ret) + is_zip64 = true; + } + + if ((off = zip_source_tell_write(za->src)) < 0) { + _zip_error_set_from_source(&za->error, za->src); + return -1; + } + size = (zip_uint64_t)off - offset; + + if (offset > ZIP_UINT32_MAX || survivors > ZIP_UINT16_MAX) + is_zip64 = true; + + + if ((buffer = _zip_buffer_new(buf, sizeof(buf))) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return -1; + } + + if (is_zip64) { + _zip_buffer_put(buffer, EOCD64_MAGIC, 4); + _zip_buffer_put_64(buffer, EOCD64LEN-12); + _zip_buffer_put_16(buffer, 45); + _zip_buffer_put_16(buffer, 45); + _zip_buffer_put_32(buffer, 0); + _zip_buffer_put_32(buffer, 0); + _zip_buffer_put_64(buffer, survivors); + _zip_buffer_put_64(buffer, survivors); + _zip_buffer_put_64(buffer, size); + _zip_buffer_put_64(buffer, offset); + _zip_buffer_put(buffer, EOCD64LOC_MAGIC, 4); + _zip_buffer_put_32(buffer, 0); + _zip_buffer_put_64(buffer, offset+size); + _zip_buffer_put_32(buffer, 1); } + + _zip_buffer_put(buffer, EOCD_MAGIC, 4); + _zip_buffer_put_32(buffer, 0); + _zip_buffer_put_16(buffer, (zip_uint16_t)(survivors >= ZIP_UINT16_MAX ? ZIP_UINT16_MAX : survivors)); + _zip_buffer_put_16(buffer, (zip_uint16_t)(survivors >= ZIP_UINT16_MAX ? ZIP_UINT16_MAX : survivors)); + _zip_buffer_put_32(buffer, size >= ZIP_UINT32_MAX ? ZIP_UINT32_MAX : (zip_uint32_t)size); + _zip_buffer_put_32(buffer, offset >= ZIP_UINT32_MAX ? ZIP_UINT32_MAX : (zip_uint32_t)offset); + + comment = za->comment_changed ? za->comment_changes : za->comment_orig; - cd->size = (unsigned int)ftello(fp) - cd->offset; + _zip_buffer_put_16(buffer, (zip_uint16_t)(comment ? comment->length : 0)); - /* clearerr(fp); */ - fwrite(EOCD_MAGIC, 1, 4, fp); - _zip_write4(0, fp); - _zip_write2((unsigned short)cd->nentry, fp); - _zip_write2((unsigned short)cd->nentry, fp); - _zip_write4(cd->size, fp); - _zip_write4(cd->offset, fp); - _zip_write2(cd->comment_len, fp); - fwrite(cd->comment, 1, cd->comment_len, fp); + if (!_zip_buffer_ok(buffer)) { + zip_error_set(&za->error, ZIP_ER_INTERNAL, 0); + _zip_buffer_free(buffer); + return -1; + } - if (ferror(fp)) { - _zip_error_set(error, ZIP_ER_WRITE, errno); + if (_zip_write(za, _zip_buffer_data(buffer), _zip_buffer_offset(buffer)) < 0) { + _zip_buffer_free(buffer); return -1; } - return 0; + _zip_buffer_free(buffer); + + if (comment) { + if (_zip_write(za, comment->raw, comment->length) < 0) { + return -1; + } + } + + return (zip_int64_t)size; +} + + +zip_dirent_t * +_zip_dirent_clone(const zip_dirent_t *sde) +{ + zip_dirent_t *tde; + + if ((tde=(zip_dirent_t *)malloc(sizeof(*tde))) == NULL) + return NULL; + + if (sde) + memcpy(tde, sde, sizeof(*sde)); + else + _zip_dirent_init(tde); + + tde->changed = 0; + tde->cloned = 1; + + return tde; } - void -_zip_dirent_finalize(struct zip_dirent *zde) +_zip_dirent_finalize(zip_dirent_t *zde) { - free(zde->filename); - zde->filename = NULL; - free(zde->extrafield); - zde->extrafield = NULL; - free(zde->comment); - zde->comment = NULL; + if (!zde->cloned || zde->changed & ZIP_DIRENT_FILENAME) { + _zip_string_free(zde->filename); + zde->filename = NULL; + } + if (!zde->cloned || zde->changed & ZIP_DIRENT_EXTRA_FIELD) { + _zip_ef_free(zde->extra_fields); + zde->extra_fields = NULL; + } + if (!zde->cloned || zde->changed & ZIP_DIRENT_COMMENT) { + _zip_string_free(zde->comment); + zde->comment = NULL; + } } - void -_zip_dirent_init(struct zip_dirent *de) +_zip_dirent_free(zip_dirent_t *zde) { - de->version_madeby = 0; + if (zde == NULL) + return; + + _zip_dirent_finalize(zde); + free(zde); +} + + +void +_zip_dirent_init(zip_dirent_t *de) +{ + de->changed = 0; + de->local_extra_fields_read = 0; + de->cloned = 0; + + de->version_madeby = 20 | (ZIP_OPSYS_DEFAULT << 8); de->version_needed = 20; /* 2.0 */ de->bitflags = 0; - de->comp_method = 0; + de->comp_method = ZIP_CM_DEFAULT; de->last_mod = 0; de->crc = 0; de->comp_size = 0; de->uncomp_size = 0; de->filename = NULL; - de->filename_len = 0; - de->extrafield = NULL; - de->extrafield_len = 0; + de->extra_fields = NULL; de->comment = NULL; - de->comment_len = 0; de->disk_number = 0; de->int_attrib = 0; - de->ext_attrib = 0; + de->ext_attrib = ZIP_EXT_ATTRIB_DEFAULT; de->offset = 0; } - + +bool +_zip_dirent_needs_zip64(const zip_dirent_t *de, zip_flags_t flags) +{ + if (de->uncomp_size >= ZIP_UINT32_MAX || de->comp_size >= ZIP_UINT32_MAX + || ((flags & ZIP_FL_CENTRAL) && de->offset >= ZIP_UINT32_MAX)) + return true; + + return false; +} + + +zip_dirent_t * +_zip_dirent_new(void) +{ + zip_dirent_t *de; + + if ((de=(zip_dirent_t *)malloc(sizeof(*de))) == NULL) + return NULL; + + _zip_dirent_init(de); + return de; +} + /* _zip_dirent_read(zde, fp, bufp, left, localp, error): Fills the zip directory entry zde. - If bufp is non-NULL, data is taken from there and bufp is advanced - by the amount of data used; otherwise data is read from fp as needed. + If buffer is non-NULL, data is taken from there; otherwise data is read from fp as needed. - if leftp is non-NULL, no more bytes than specified by it are used, - and *leftp is reduced by the number of bytes used. + If local is true, it reads a local header instead of a central directory entry. - If local != 0, it reads a local header instead of a central - directory entry. - - Returns 0 if successful. On error, error is filled in and -1 is - returned. - - XXX: leftp and file position undefined on error. + Returns size of dirent read if successful. On error, error is filled in and -1 is returned. */ -int -_zip_dirent_read(struct zip_dirent *zde, FILE *fp, - unsigned char **bufp, unsigned int *leftp, int local, - struct zip_error *error) +zip_int64_t +_zip_dirent_read(zip_dirent_t *zde, zip_source_t *src, zip_buffer_t *buffer, bool local, zip_error_t *error) { - unsigned char buf[CDENTRYSIZE]; - unsigned char *cur; - unsigned short dostime, dosdate; - unsigned int size; + zip_uint8_t buf[CDENTRYSIZE]; + zip_uint16_t dostime, dosdate; + zip_uint32_t size, variable_size; + zip_uint16_t filename_len, comment_len, ef_len; - if (local) - size = LENTRYSIZE; - else - size = CDENTRYSIZE; - - if (leftp && (*leftp < size)) { - _zip_error_set(error, ZIP_ER_NOZIP, 0); - return -1; - } + bool from_buffer = (buffer != NULL); + + size = local ? LENTRYSIZE : CDENTRYSIZE; - if (bufp) { - /* use data from buffer */ - cur = *bufp; + if (buffer) { + if (_zip_buffer_left(buffer) < size) { + zip_error_set(error, ZIP_ER_NOZIP, 0); + return -1; + } } else { - /* read entry from disk */ - if ((fread(buf, 1, size, fp)version_madeby = _zip_read2(&cur); + zde->version_madeby = _zip_buffer_get_16(buffer); else zde->version_madeby = 0; - zde->version_needed = _zip_read2(&cur); - zde->bitflags = _zip_read2(&cur); - zde->comp_method = _zip_read2(&cur); + zde->version_needed = _zip_buffer_get_16(buffer); + zde->bitflags = _zip_buffer_get_16(buffer); + zde->comp_method = _zip_buffer_get_16(buffer); /* convert to time_t */ - dostime = _zip_read2(&cur); - dosdate = _zip_read2(&cur); + dostime = _zip_buffer_get_16(buffer); + dosdate = _zip_buffer_get_16(buffer); zde->last_mod = _zip_d2u_time(dostime, dosdate); - zde->crc = _zip_read4(&cur); - zde->comp_size = _zip_read4(&cur); - zde->uncomp_size = _zip_read4(&cur); + zde->crc = _zip_buffer_get_32(buffer); + zde->comp_size = _zip_buffer_get_32(buffer); + zde->uncomp_size = _zip_buffer_get_32(buffer); - zde->filename_len = _zip_read2(&cur); - zde->extrafield_len = _zip_read2(&cur); + filename_len = _zip_buffer_get_16(buffer); + ef_len = _zip_buffer_get_16(buffer); if (local) { - zde->comment_len = 0; + comment_len = 0; zde->disk_number = 0; zde->int_attrib = 0; zde->ext_attrib = 0; zde->offset = 0; } else { - zde->comment_len = _zip_read2(&cur); - zde->disk_number = _zip_read2(&cur); - zde->int_attrib = _zip_read2(&cur); - zde->ext_attrib = _zip_read4(&cur); - zde->offset = _zip_read4(&cur); + comment_len = _zip_buffer_get_16(buffer); + zde->disk_number = _zip_buffer_get_16(buffer); + zde->int_attrib = _zip_buffer_get_16(buffer); + zde->ext_attrib = _zip_buffer_get_32(buffer); + zde->offset = _zip_buffer_get_32(buffer); + } + + if (!_zip_buffer_ok(buffer)) { + zip_error_set(error, ZIP_ER_INTERNAL, 0); + if (!from_buffer) { + _zip_buffer_free(buffer); + } + return -1; } zde->filename = NULL; - zde->extrafield = NULL; + zde->extra_fields = NULL; zde->comment = NULL; - size += zde->filename_len+zde->extrafield_len+zde->comment_len; + variable_size = (zip_uint32_t)filename_len+(zip_uint32_t)ef_len+(zip_uint32_t)comment_len; - if (leftp && (*leftp < size)) { - _zip_error_set(error, ZIP_ER_NOZIP, 0); - return -1; + if (from_buffer) { + if (_zip_buffer_left(buffer) < variable_size) { + zip_error_set(error, ZIP_ER_INCONS, 0); + return -1; + } + } + else { + _zip_buffer_free(buffer); + + if ((buffer = _zip_buffer_new_from_source(src, variable_size, NULL, error)) == NULL) { + return -1; + } } - if (bufp) { - if (zde->filename_len) { - zde->filename = _zip_readstr(&cur, zde->filename_len, 1, error); - if (!zde->filename) - return -1; - } - - if (zde->extrafield_len) { - zde->extrafield = _zip_readstr(&cur, zde->extrafield_len, 0, - error); - if (!zde->extrafield) + if (filename_len) { + zde->filename = _zip_read_string(buffer, src, filename_len, 1, error); + if (!zde->filename) { + if (zip_error_code_zip(error) == ZIP_ER_EOF) { + zip_error_set(error, ZIP_ER_INCONS, 0); + } + if (!from_buffer) { + _zip_buffer_free(buffer); + } + return -1; + } + + if (zde->bitflags & ZIP_GPBF_ENCODING_UTF_8) { + if (_zip_guess_encoding(zde->filename, ZIP_ENCODING_UTF8_KNOWN) == ZIP_ENCODING_ERROR) { + zip_error_set(error, ZIP_ER_INCONS, 0); + if (!from_buffer) { + _zip_buffer_free(buffer); + } return -1; + } } + } - if (zde->comment_len) { - zde->comment = _zip_readstr(&cur, zde->comment_len, 0, error); - if (!zde->comment) - return -1; + if (ef_len) { + zip_uint8_t *ef = _zip_read_data(buffer, src, ef_len, 0, error); + + if (ef == NULL) { + if (!from_buffer) { + _zip_buffer_free(buffer); + } + return -1; + } + if ((zde->extra_fields=_zip_ef_parse(ef, ef_len, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, error)) == NULL) { + free(ef); + if (!from_buffer) { + _zip_buffer_free(buffer); + } + return -1; } + free(ef); + if (local) + zde->local_extra_fields_read = 1; } - else { - if (zde->filename_len) { - zde->filename = _zip_readfpstr(fp, zde->filename_len, 1, error); - if (!zde->filename) - return -1; - } - if (zde->extrafield_len) { - zde->extrafield = _zip_readfpstr(fp, zde->extrafield_len, 0, - error); - if (!zde->extrafield) + if (comment_len) { + zde->comment = _zip_read_string(buffer, src, comment_len, 0, error); + if (!zde->comment) { + if (!from_buffer) { + _zip_buffer_free(buffer); + } + return -1; + } + if (zde->bitflags & ZIP_GPBF_ENCODING_UTF_8) { + if (_zip_guess_encoding(zde->comment, ZIP_ENCODING_UTF8_KNOWN) == ZIP_ENCODING_ERROR) { + zip_error_set(error, ZIP_ER_INCONS, 0); + if (!from_buffer) { + _zip_buffer_free(buffer); + } return -1; + } } + } - if (zde->comment_len) { - zde->comment = _zip_readfpstr(fp, zde->comment_len, 0, error); - if (!zde->comment) - return -1; + zde->filename = _zip_dirent_process_ef_utf_8(zde, ZIP_EF_UTF_8_NAME, zde->filename); + zde->comment = _zip_dirent_process_ef_utf_8(zde, ZIP_EF_UTF_8_COMMENT, zde->comment); + + /* Zip64 */ + + if (zde->uncomp_size == ZIP_UINT32_MAX || zde->comp_size == ZIP_UINT32_MAX || zde->offset == ZIP_UINT32_MAX) { + zip_uint16_t got_len; + zip_buffer_t *ef_buffer; + const zip_uint8_t *ef = _zip_ef_get_by_id(zde->extra_fields, &got_len, ZIP_EF_ZIP64, 0, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, error); + /* TODO: if got_len == 0 && !ZIP64_EOCD: no error, 0xffffffff is valid value */ + if (ef == NULL) { + if (!from_buffer) { + _zip_buffer_free(buffer); + } + return -1; + } + + if ((ef_buffer = _zip_buffer_new((zip_uint8_t *)ef, got_len)) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + if (!from_buffer) { + _zip_buffer_free(buffer); + } + return -1; + } + + if (zde->uncomp_size == ZIP_UINT32_MAX) + zde->uncomp_size = _zip_buffer_get_64(ef_buffer); + else if (local) + ef += 8; + if (zde->comp_size == ZIP_UINT32_MAX) + zde->comp_size = _zip_buffer_get_64(ef_buffer); + if (!local) { + if (zde->offset == ZIP_UINT32_MAX) + zde->offset = _zip_buffer_get_64(ef_buffer); + if (zde->disk_number == ZIP_UINT16_MAX) + zde->disk_number = _zip_buffer_get_32(buffer); } + + if (!_zip_buffer_eof(ef_buffer)) { + zip_error_set(error, ZIP_ER_INCONS, 0); + _zip_buffer_free(ef_buffer); + if (!from_buffer) { + _zip_buffer_free(buffer); + } + return -1; + } + _zip_buffer_free(ef_buffer); + } + + if (!_zip_buffer_ok(buffer)) { + zip_error_set(error, ZIP_ER_INTERNAL, 0); + if (!from_buffer) { + _zip_buffer_free(buffer); + } + return -1; + } + if (!from_buffer) { + _zip_buffer_free(buffer); } - if (bufp) - *bufp = cur; - if (leftp) - *leftp -= size; + /* zip_source_seek / zip_source_tell don't support values > ZIP_INT64_MAX */ + if (zde->offset > ZIP_INT64_MAX) { + zip_error_set(error, ZIP_ER_SEEK, EFBIG); + return -1; + } + + zde->extra_fields = _zip_ef_remove_internal(zde->extra_fields); - return 0; + return (zip_int64_t)(size + variable_size); } - -/* _zip_dirent_torrent_normalize(de); - Set values suitable for torrentzip. -*/ +static zip_string_t * +_zip_dirent_process_ef_utf_8(const zip_dirent_t *de, zip_uint16_t id, zip_string_t *str) +{ + zip_uint16_t ef_len; + zip_uint32_t ef_crc; + zip_buffer_t *buffer; -void -_zip_dirent_torrent_normalize(struct zip_dirent *de) + const zip_uint8_t *ef = _zip_ef_get_by_id(de->extra_fields, &ef_len, id, 0, ZIP_EF_BOTH, NULL); + + if (ef == NULL || ef_len < 5 || ef[0] != 1) { + return str; + } + + if ((buffer = _zip_buffer_new((zip_uint8_t *)ef, ef_len)) == NULL) { + return str; + } + + _zip_buffer_get_8(buffer); + ef_crc = _zip_buffer_get_32(buffer); + + if (_zip_string_crc32(str) == ef_crc) { + zip_uint16_t len = (zip_uint16_t)_zip_buffer_left(buffer); + zip_string_t *ef_str = _zip_string_new(_zip_buffer_get(buffer, len), len, ZIP_FL_ENC_UTF_8, NULL); + + if (ef_str != NULL) { + _zip_string_free(str); + str = ef_str; + } + } + + _zip_buffer_free(buffer); + + return str; +} + + +zip_int32_t +_zip_dirent_size(zip_source_t *src, zip_uint16_t flags, zip_error_t *error) { - static struct tm torrenttime; - static time_t last_mod = 0; - - if (last_mod == 0) { -#ifdef HAVE_STRUCT_TM_TM_ZONE - time_t now; - struct tm *l; -#endif - - torrenttime.tm_sec = 0; - torrenttime.tm_min = 32; - torrenttime.tm_hour = 23; - torrenttime.tm_mday = 24; - torrenttime.tm_mon = 11; - torrenttime.tm_year = 96; - torrenttime.tm_wday = 0; - torrenttime.tm_yday = 0; - torrenttime.tm_isdst = 0; - -#ifdef HAVE_STRUCT_TM_TM_ZONE - time(&now); - l = localtime(&now); - torrenttime.tm_gmtoff = l->tm_gmtoff; - torrenttime.tm_zone = l->tm_zone; -#endif - - last_mod = mktime(&torrenttime); - } - - de->version_madeby = 0; - de->version_needed = 20; /* 2.0 */ - de->bitflags = 2; /* maximum compression */ - de->comp_method = ZIP_CM_DEFLATE; - de->last_mod = last_mod; + zip_int32_t size; + bool local = (flags & ZIP_EF_LOCAL) != 0; + int i; + zip_uint8_t b[6]; + zip_buffer_t *buffer; - de->disk_number = 0; - de->int_attrib = 0; - de->ext_attrib = 0; - de->offset = 0; + size = local ? LENTRYSIZE : CDENTRYSIZE; - free(de->extrafield); - de->extrafield = NULL; - de->extrafield_len = 0; - free(de->comment); - de->comment = NULL; - de->comment_len = 0; + if (zip_source_seek(src, local ? 26 : 28, SEEK_CUR) < 0) { + _zip_error_set_from_source(error, src); + return -1; + } + + if ((buffer = _zip_buffer_new_from_source(src, local ? 4 : 6, b, error)) == NULL) { + return -1; + } + + for (i=0; i<(local ? 2 : 3); i++) { + size += _zip_buffer_get_16(buffer); + } + + if (!_zip_buffer_eof(buffer)) { + zip_error_set(error, ZIP_ER_INTERNAL, 0); + _zip_buffer_free(buffer); + return -1; + } + + _zip_buffer_free(buffer); + return size; } - -/* _zip_dirent_write(zde, fp, localp, error): - Writes zip directory entry zde to file fp. +/* _zip_dirent_write + Writes zip directory entry. - If localp != 0, it writes a local header instead of a central - directory entry. + If flags & ZIP_EF_LOCAL, it writes a local header instead of a central + directory entry. If flags & ZIP_EF_FORCE_ZIP64, a ZIP64 extra field is written, even if not needed. - Returns 0 if successful. On error, error is filled in and -1 is + Returns 0 if successful, 1 if successful and wrote ZIP64 extra field. On error, error is filled in and -1 is returned. */ int -_zip_dirent_write(struct zip_dirent *zde, FILE *fp, int localp, - struct zip_error *error) +_zip_dirent_write(zip_t *za, zip_dirent_t *de, zip_flags_t flags) { - unsigned short dostime, dosdate; + zip_uint16_t dostime, dosdate; + zip_encoding_type_t com_enc, name_enc; + zip_extra_field_t *ef; + bool is_zip64; + bool is_really_zip64; + zip_uint8_t buf[CDENTRYSIZE]; + zip_buffer_t *buffer; + + ef = NULL; - fwrite(localp ? LOCAL_MAGIC : CENTRAL_MAGIC, 1, 4, fp); + is_zip64 = false; - if (!localp) - _zip_write2(zde->version_madeby, fp); - _zip_write2(zde->version_needed, fp); - _zip_write2(zde->bitflags, fp); - _zip_write2(zde->comp_method, fp); + name_enc = _zip_guess_encoding(de->filename, ZIP_ENCODING_UNKNOWN); + com_enc = _zip_guess_encoding(de->comment, ZIP_ENCODING_UNKNOWN); - _zip_u2d_time(zde->last_mod, &dostime, &dosdate); - _zip_write2(dostime, fp); - _zip_write2(dosdate, fp); + if ((name_enc == ZIP_ENCODING_UTF8_KNOWN && com_enc == ZIP_ENCODING_ASCII) || + (name_enc == ZIP_ENCODING_ASCII && com_enc == ZIP_ENCODING_UTF8_KNOWN) || + (name_enc == ZIP_ENCODING_UTF8_KNOWN && com_enc == ZIP_ENCODING_UTF8_KNOWN)) + de->bitflags |= ZIP_GPBF_ENCODING_UTF_8; + else { + de->bitflags &= (zip_uint16_t)~ZIP_GPBF_ENCODING_UTF_8; + if (name_enc == ZIP_ENCODING_UTF8_KNOWN) { + ef = _zip_ef_utf8(ZIP_EF_UTF_8_NAME, de->filename, &za->error); + if (ef == NULL) + return -1; + } + if ((flags & ZIP_FL_LOCAL) == 0 && com_enc == ZIP_ENCODING_UTF8_KNOWN){ + zip_extra_field_t *ef2 = _zip_ef_utf8(ZIP_EF_UTF_8_COMMENT, de->comment, &za->error); + if (ef2 == NULL) { + _zip_ef_free(ef); + return -1; + } + ef2->next = ef; + ef = ef2; + } + } + + is_really_zip64 = _zip_dirent_needs_zip64(de, flags); + is_zip64 = (flags & (ZIP_FL_LOCAL|ZIP_FL_FORCE_ZIP64)) == (ZIP_FL_LOCAL|ZIP_FL_FORCE_ZIP64) || is_really_zip64; - _zip_write4(zde->crc, fp); - _zip_write4(zde->comp_size, fp); - _zip_write4(zde->uncomp_size, fp); + if (is_zip64) { + zip_uint8_t ef_zip64[EFZIP64SIZE]; + zip_buffer_t *ef_buffer = _zip_buffer_new(ef_zip64, sizeof(ef_zip64)); + if (ef_buffer == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + _zip_ef_free(ef); + return -1; + } + + if (flags & ZIP_FL_LOCAL) { + if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX) { + _zip_buffer_put_64(ef_buffer, de->uncomp_size); + _zip_buffer_put_64(ef_buffer, de->comp_size); + } + } + else { + if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX || de->offset > ZIP_UINT32_MAX) { + if (de->uncomp_size >= ZIP_UINT32_MAX) { + _zip_buffer_put_64(ef_buffer, de->uncomp_size); + } + if (de->comp_size >= ZIP_UINT32_MAX) { + _zip_buffer_put_64(ef_buffer, de->comp_size); + } + if (de->offset >= ZIP_UINT32_MAX) { + _zip_buffer_put_64(ef_buffer, de->offset); + } + } + } + + if (!_zip_buffer_ok(ef_buffer)) { + zip_error_set(&za->error, ZIP_ER_INTERNAL, 0); + _zip_buffer_free(ef_buffer); + _zip_ef_free(ef); + return -1; + } + + zip_extra_field_t *ef64 = _zip_ef_new(ZIP_EF_ZIP64, (zip_uint16_t)(_zip_buffer_offset(ef_buffer)), ef_zip64, ZIP_EF_BOTH); + _zip_buffer_free(ef_buffer); + ef64->next = ef; + ef = ef64; + } + + if ((buffer = _zip_buffer_new(buf, sizeof(buf))) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + _zip_ef_free(ef); + return -1; + } - _zip_write2(zde->filename_len, fp); - _zip_write2(zde->extrafield_len, fp); + _zip_buffer_put(buffer, (flags & ZIP_FL_LOCAL) ? LOCAL_MAGIC : CENTRAL_MAGIC, 4); - if (!localp) { - _zip_write2(zde->comment_len, fp); - _zip_write2(zde->disk_number, fp); - _zip_write2(zde->int_attrib, fp); - _zip_write4(zde->ext_attrib, fp); - _zip_write4(zde->offset, fp); + if ((flags & ZIP_FL_LOCAL) == 0) { + _zip_buffer_put_16(buffer, (zip_uint16_t)(is_really_zip64 ? 45 : de->version_madeby)); } + _zip_buffer_put_16(buffer, (zip_uint16_t)(is_really_zip64 ? 45 : de->version_needed)); + _zip_buffer_put_16(buffer, de->bitflags&0xfff9); /* clear compression method specific flags */ + _zip_buffer_put_16(buffer, (zip_uint16_t)de->comp_method); - if (zde->filename_len) - fwrite(zde->filename, 1, zde->filename_len, fp); + _zip_u2d_time(de->last_mod, &dostime, &dosdate); + _zip_buffer_put_16(buffer, dostime); + _zip_buffer_put_16(buffer, dosdate); - if (zde->extrafield_len) - fwrite(zde->extrafield, 1, zde->extrafield_len, fp); + _zip_buffer_put_32(buffer, de->crc); + + if (((flags & ZIP_FL_LOCAL) == ZIP_FL_LOCAL) && ((de->comp_size >= ZIP_UINT32_MAX) || (de->uncomp_size >= ZIP_UINT32_MAX))) { + /* In local headers, if a ZIP64 EF is written, it MUST contain + * both compressed and uncompressed sizes (even if one of the + * two is smaller than 0xFFFFFFFF); on the other hand, those + * may only appear when the corresponding standard entry is + * 0xFFFFFFFF. (appnote.txt 4.5.3) */ + _zip_buffer_put_32(buffer, ZIP_UINT32_MAX); + _zip_buffer_put_32(buffer, ZIP_UINT32_MAX); + } + else { + if (de->comp_size < ZIP_UINT32_MAX) { + _zip_buffer_put_32(buffer, (zip_uint32_t)de->comp_size); + } + else { + _zip_buffer_put_32(buffer, ZIP_UINT32_MAX); + } + if (de->uncomp_size < ZIP_UINT32_MAX) { + _zip_buffer_put_32(buffer, (zip_uint32_t)de->uncomp_size); + } + else { + _zip_buffer_put_32(buffer, ZIP_UINT32_MAX); + } + } - if (!localp) { - if (zde->comment_len) - fwrite(zde->comment, 1, zde->comment_len, fp); + _zip_buffer_put_16(buffer, _zip_string_length(de->filename)); + /* TODO: check for overflow */ + zip_uint32_t ef_total_size = (zip_uint32_t)_zip_ef_size(de->extra_fields, flags) + (zip_uint32_t)_zip_ef_size(ef, ZIP_EF_BOTH); + _zip_buffer_put_16(buffer, (zip_uint16_t)ef_total_size); + + if ((flags & ZIP_FL_LOCAL) == 0) { + _zip_buffer_put_16(buffer, _zip_string_length(de->comment)); + _zip_buffer_put_16(buffer, (zip_uint16_t)de->disk_number); + _zip_buffer_put_16(buffer, de->int_attrib); + _zip_buffer_put_32(buffer, de->ext_attrib); + if (de->offset < ZIP_UINT32_MAX) + _zip_buffer_put_32(buffer, (zip_uint32_t)de->offset); + else + _zip_buffer_put_32(buffer, ZIP_UINT32_MAX); + } + + if (!_zip_buffer_ok(buffer)) { + zip_error_set(&za->error, ZIP_ER_INTERNAL, 0); + _zip_buffer_free(buffer); + _zip_ef_free(ef); + return -1; } - if (ferror(fp)) { - _zip_error_set(error, ZIP_ER_WRITE, errno); - return -1; + if (_zip_write(za, buf, _zip_buffer_offset(buffer)) < 0) { + _zip_buffer_free(buffer); + _zip_ef_free(ef); + return -1; + } + + _zip_buffer_free(buffer); + + if (de->filename) { + if (_zip_string_write(za, de->filename) < 0) { + _zip_ef_free(ef); + return -1; + } + } + + if (ef) { + if (_zip_ef_write(za, ef, ZIP_EF_BOTH) < 0) { + _zip_ef_free(ef); + return -1; + } + } + _zip_ef_free(ef); + if (de->extra_fields) { + if (_zip_ef_write(za, de->extra_fields, flags) < 0) { + return -1; + } } - return 0; + if ((flags & ZIP_FL_LOCAL) == 0) { + if (de->comment) { + if (_zip_string_write(za, de->comment) < 0) { + return -1; + } + } + } + + + return is_zip64; } - static time_t -_zip_d2u_time(int dtime, int ddate) +_zip_d2u_time(zip_uint16_t dtime, zip_uint16_t ddate) { struct tm tm; - memset(&tm, sizeof(tm), 0); + memset(&tm, 0, sizeof(tm)); /* let mktime decide if DST is in effect */ tm.tm_isdst = -1; @@ -498,125 +823,85 @@ _zip_d2u_time(int dtime, int ddate) return mktime(&tm); } - -unsigned short -_zip_read2(unsigned char **a) +static zip_extra_field_t * +_zip_ef_utf8(zip_uint16_t id, zip_string_t *str, zip_error_t *error) { - unsigned short ret; - - ret = (*a)[0]+((*a)[1]<<8); - *a += 2; + const zip_uint8_t *raw; + zip_uint32_t len; + zip_buffer_t *buffer; + zip_extra_field_t *ef; - return ret; -} - - - -unsigned int -_zip_read4(unsigned char **a) -{ - unsigned int ret; - - ret = ((((((*a)[3]<<8)+(*a)[2])<<8)+(*a)[1])<<8)+(*a)[0]; - *a += 4; - - return ret; -} + raw = _zip_string_get(str, &len, ZIP_FL_ENC_RAW, NULL); - - -static char * -_zip_readfpstr(FILE *fp, unsigned int len, int nulp, struct zip_error *error) -{ - char *r, *o; - - r = (char *)malloc(nulp ? len+1 : len); - if (!r) { - _zip_error_set(error, ZIP_ER_MEMORY, 0); - return NULL; + if (len+5 > ZIP_UINT16_MAX) { + zip_error_set(error, ZIP_ER_INVAL, 0); /* TODO: better error code? */ + return NULL; } - - if (fread(r, 1, len, fp)error; - r = (char *)malloc(nulp ? len+1 : len); - if (!r) { - _zip_error_set(error, ZIP_ER_MEMORY, 0); + if (idx >= za->nentry) { + zip_error_set(error, ZIP_ER_INVAL, 0); return NULL; } - - memcpy(r, *buf, len); - *buf += len; - if (nulp) { - /* replace any in-string NUL characters with spaces */ - r[len] = 0; - for (o=r; oentry[idx].changes == NULL) { + if (za->entry[idx].orig == NULL) { + zip_error_set(error, ZIP_ER_INVAL, 0); + return NULL; + } + if (za->entry[idx].deleted && (flags & ZIP_FL_UNCHANGED) == 0) { + zip_error_set(error, ZIP_ER_DELETED, 0); + return NULL; + } + return za->entry[idx].orig; } - - return r; -} - - - -static void -_zip_write2(unsigned short i, FILE *fp) -{ - putc(i&0xff, fp); - putc((i>>8)&0xff, fp); - - return; + else + return za->entry[idx].changes; } - -static void -_zip_write4(unsigned int i, FILE *fp) -{ - putc(i&0xff, fp); - putc((i>>8)&0xff, fp); - putc((i>>16)&0xff, fp); - putc((i>>24)&0xff, fp); - - return; -} - -static void -_zip_u2d_time(time_t time, unsigned short *dtime, unsigned short *ddate) +void +_zip_u2d_time(time_t intime, zip_uint16_t *dtime, zip_uint16_t *ddate) { struct tm *tm; - tm = localtime(&time); - *ddate = ((tm->tm_year+1900-1980)<<9) + ((tm->tm_mon+1)<<5) - + tm->tm_mday; - *dtime = ((tm->tm_hour)<<11) + ((tm->tm_min)<<5) - + ((tm->tm_sec)>>1); + tm = localtime(&intime); + if (tm->tm_year < 80) { + tm->tm_year = 80; + } + + *ddate = (zip_uint16_t)(((tm->tm_year+1900-1980)<<9) + ((tm->tm_mon+1)<<5) + tm->tm_mday); + *dtime = (zip_uint16_t)(((tm->tm_hour)<<11) + ((tm->tm_min)<<5) + ((tm->tm_sec)>>1)); return; } diff --git a/ePub3/ThirdParty/libzip/zip_free.c b/ePub3/ThirdParty/libzip/zip_discard.c similarity index 75% rename from ePub3/ThirdParty/libzip/zip_free.c rename to ePub3/ThirdParty/libzip/zip_discard.c index 76c3a9673..db2237084 100644 --- a/ePub3/ThirdParty/libzip/zip_free.c +++ b/ePub3/ThirdParty/libzip/zip_discard.c @@ -1,6 +1,6 @@ /* - zip_free.c -- free struct zip - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + zip_discard.c -- discard and free struct zip + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,49 +31,45 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include "zipint.h" - -/* _zip_free: +/* zip_discard: frees the space allocated to a zipfile struct, and closes the corresponding file. */ void -_zip_free(struct zip *za) +zip_discard(zip_t *za) { - int i; + zip_uint64_t i; if (za == NULL) return; - if (za->zn) - free(za->zn); - - if (za->zp) - fclose(za->zp); + if (za->src) { + zip_source_close(za->src); + zip_source_free(za->src); + } - _zip_cdir_free(za->cdir); + free(za->default_password); + _zip_string_free(za->comment_orig); + _zip_string_free(za->comment_changes); if (za->entry) { - for (i=0; inentry; i++) { - _zip_entry_free(za->entry+i); - } + for (i=0; inentry; i++) + _zip_entry_finalize(za->entry+i); free(za->entry); } - for (i=0; infile; i++) { - if (za->file[i]->error.zip_err == ZIP_ER_OK) { - _zip_error_set(&za->file[i]->error, ZIP_ER_ZIPCLOSED, 0); - za->file[i]->za = NULL; - } + for (i=0; inopen_source; i++) { + _zip_source_invalidate(za->open_source[i]); } + free(za->open_source); - free(za->file); + zip_error_fini(&za->error); free(za); diff --git a/ePub3/ThirdParty/libzip/zip_entry.c b/ePub3/ThirdParty/libzip/zip_entry.c new file mode 100644 index 000000000..6f8900686 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_entry.c @@ -0,0 +1,53 @@ +/* + zip_entry.c -- struct zip_entry helper functions + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + +void +_zip_entry_finalize(zip_entry_t *e) +{ + _zip_unchange_data(e); + _zip_dirent_free(e->orig); + _zip_dirent_free(e->changes); +} + + +void +_zip_entry_init(zip_entry_t *e) +{ + e->orig = NULL; + e->changes = NULL; + e->source = NULL; + e->deleted = 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_err_str.c b/ePub3/ThirdParty/libzip/zip_err_str.c index 3fcdf1738..65698be00 100644 --- a/ePub3/ThirdParty/libzip/zip_err_str.c +++ b/ePub3/ThirdParty/libzip/zip_err_str.c @@ -5,8 +5,6 @@ #include "zipint.h" - - const char * const _zip_err_str[] = { "No error", "Multi-disk zip archives not supported", @@ -25,13 +23,20 @@ const char * const _zip_err_str[] = { "Malloc failure", "Entry has been changed", "Compression method not supported", - "Premature EOF", + "Premature end of file", "Invalid argument", "Not a zip archive", "Internal error", "Zip archive inconsistent", "Can't remove file", "Entry has been deleted", + "Encryption method not supported", + "Read-only archive", + "No password provided", + "Wrong password provided", + "Operation not supported", + "Resource still in use", + "Tell error", }; const int _zip_nerr_str = sizeof(_zip_err_str)/sizeof(_zip_err_str[0]); @@ -65,4 +70,11 @@ const int _zip_err_type[] = { N, S, N, + N, + N, + N, + N, + N, + N, + S, }; diff --git a/ePub3/ThirdParty/libzip/zip_error.c b/ePub3/ThirdParty/libzip/zip_error.c index aab707945..a21a00bc2 100644 --- a/ePub3/ThirdParty/libzip/zip_error.c +++ b/ePub3/ThirdParty/libzip/zip_error.c @@ -1,6 +1,6 @@ /* - zip_error.c -- struct zip_error helper functions - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + zip_error.c -- zip_error_t helper functions + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,71 +31,126 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - - +#include #include #include "zipint.h" - -void -_zip_error_clear(struct zip_error *err) +ZIP_EXTERN int +zip_error_code_system(const zip_error_t *error) { + return error->sys_err; +} + + +ZIP_EXTERN int +zip_error_code_zip(const zip_error_t *error) { + return error->zip_err; +} + + +ZIP_EXTERN void +zip_error_fini(zip_error_t *err) +{ + free(err->str); + err->str = NULL; +} + + +ZIP_EXTERN void +zip_error_init(zip_error_t *err) { err->zip_err = ZIP_ER_OK; err->sys_err = 0; + err->str = NULL; +} + +ZIP_EXTERN void +zip_error_init_with_code(zip_error_t *error, int ze) +{ + zip_error_init(error); + error->zip_err = ze; + switch (zip_error_system_type(error)) { + case ZIP_ET_SYS: + error->sys_err = errno; + break; + + default: + error->sys_err = 0; + break; + } +} + + +ZIP_EXTERN int +zip_error_system_type(const zip_error_t *error) { + if (error->zip_err < 0 || error->zip_err >= _zip_nerr_str) + return ZIP_ET_NONE; + + return _zip_err_type[error->zip_err]; } - void -_zip_error_copy(struct zip_error *dst, struct zip_error *src) +_zip_error_clear(zip_error_t *err) { - dst->zip_err = src->zip_err; - dst->sys_err = src->sys_err; + if (err == NULL) + return; + + err->zip_err = ZIP_ER_OK; + err->sys_err = 0; } - void -_zip_error_fini(struct zip_error *err) +_zip_error_copy(zip_error_t *dst, const zip_error_t *src) { - free(err->str); - err->str = NULL; + dst->zip_err = src->zip_err; + dst->sys_err = src->sys_err; } - void -_zip_error_get(struct zip_error *err, int *zep, int *sep) +_zip_error_get(const zip_error_t *err, int *zep, int *sep) { if (zep) *zep = err->zip_err; if (sep) { - if (zip_error_get_sys_type(err->zip_err) != ZIP_ET_NONE) + if (zip_error_system_type(err) != ZIP_ET_NONE) *sep = err->sys_err; else *sep = 0; } } - void -_zip_error_init(struct zip_error *err) +zip_error_set(zip_error_t *err, int ze, int se) { - err->zip_err = ZIP_ER_OK; - err->sys_err = 0; - err->str = NULL; + if (err) { + err->zip_err = ze; + err->sys_err = se; + } } - void -_zip_error_set(struct zip_error *err, int ze, int se) +_zip_error_set_from_source(zip_error_t *err, zip_source_t *src) { - if (err) { - err->zip_err = ze; - err->sys_err = se; + _zip_error_copy(err, zip_source_error(src)); +} + + +zip_int64_t +zip_error_to_data(const zip_error_t *error, void *data, zip_uint64_t length) +{ + int *e = (int *)data; + + if (length < sizeof(int)*2) { + return -1; } + + e[0] = zip_error_code_zip(error); + e[1] = zip_error_code_system(error); + return sizeof(int)*2; } diff --git a/ePub3/ThirdParty/libzip/zip_error_clear.c b/ePub3/ThirdParty/libzip/zip_error_clear.c index 364383ebe..ec45e688e 100644 --- a/ePub3/ThirdParty/libzip/zip_error_clear.c +++ b/ePub3/ThirdParty/libzip/zip_error_clear.c @@ -1,6 +1,6 @@ /* zip_error_clear.c -- clear zip error - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,14 +31,15 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "zipint.h" - ZIP_EXTERN void -zip_error_clear(struct zip *za) +zip_error_clear(zip_t *za) { + if (za == NULL) + return; + _zip_error_clear(&za->error); } diff --git a/ePub3/ThirdParty/libzip/zip_error_get.c b/ePub3/ThirdParty/libzip/zip_error_get.c index 6d1c958c1..c22201899 100644 --- a/ePub3/ThirdParty/libzip/zip_error_get.c +++ b/ePub3/ThirdParty/libzip/zip_error_get.c @@ -1,6 +1,6 @@ /* zip_error_get.c -- get zip error - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,14 +31,27 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - +#define _ZIP_COMPILING_DEPRECATED #include "zipint.h" - ZIP_EXTERN void -zip_error_get(struct zip *za, int *zep, int *sep) +zip_error_get(zip_t *za, int *zep, int *sep) { _zip_error_get(&za->error, zep, sep); } + + +ZIP_EXTERN zip_error_t * +zip_get_error(zip_t *za) +{ + return &za->error; +} + + +ZIP_EXTERN zip_error_t * +zip_file_get_error(zip_file_t *f) +{ + return &f->error; +} diff --git a/ePub3/ThirdParty/libzip/zip_error_get_sys_type.c b/ePub3/ThirdParty/libzip/zip_error_get_sys_type.c index 6c6f38074..7e27bbf33 100644 --- a/ePub3/ThirdParty/libzip/zip_error_get_sys_type.c +++ b/ePub3/ThirdParty/libzip/zip_error_get_sys_type.c @@ -1,6 +1,6 @@ /* zip_error_get_sys_type.c -- return type of system error code - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,11 +31,9 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - - +#define _ZIP_COMPILING_DEPRECATED #include "zipint.h" - ZIP_EXTERN int zip_error_get_sys_type(int ze) diff --git a/ePub3/ThirdParty/libzip/zip_error_strerror.c b/ePub3/ThirdParty/libzip/zip_error_strerror.c index 3d0951cfb..2f124ccd4 100644 --- a/ePub3/ThirdParty/libzip/zip_error_strerror.c +++ b/ePub3/ThirdParty/libzip/zip_error_strerror.c @@ -1,6 +1,6 @@ /* zip_error_sterror.c -- get string representation of struct zip_error - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,7 +31,6 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include @@ -40,15 +39,14 @@ #include "zipint.h" - -const char * -_zip_error_strerror(struct zip_error *err) +ZIP_EXTERN const char * +zip_error_strerror(zip_error_t *err) { const char *zs, *ss; char buf[128], *s; - _zip_error_fini(err); + zip_error_fini(err); if (err->zip_err < 0 || err->zip_err >= _zip_nerr_str) { sprintf(buf, "Unknown error %d", err->zip_err); diff --git a/ePub3/ThirdParty/libzip/zip_error_to_str.c b/ePub3/ThirdParty/libzip/zip_error_to_str.c index bdba41a6c..d4119253f 100644 --- a/ePub3/ThirdParty/libzip/zip_error_to_str.c +++ b/ePub3/ThirdParty/libzip/zip_error_to_str.c @@ -1,6 +1,6 @@ /* zip_error_to_str.c -- get string representation of zip error code - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,19 +31,18 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include #include #include +#define _ZIP_COMPILING_DEPRECATED #include "zipint.h" - ZIP_EXTERN int -zip_error_to_str(char *buf, size_t len, int ze, int se) +zip_error_to_str(char *buf, zip_uint64_t len, int ze, int se) { const char *zs, *ss; diff --git a/ePub3/ThirdParty/libzip/zip_extra_field.c b/ePub3/ThirdParty/libzip/zip_extra_field.c new file mode 100644 index 000000000..b2566c688 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_extra_field.c @@ -0,0 +1,421 @@ +/* + zip_extra_field.c -- manipulate extra fields + Copyright (C) 2012-2015 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + +#include +#include +#include + + +zip_extra_field_t * +_zip_ef_clone(const zip_extra_field_t *ef, zip_error_t *error) +{ + zip_extra_field_t *head, *prev, *def; + + head = prev = NULL; + + while (ef) { + if ((def=_zip_ef_new(ef->id, ef->size, ef->data, ef->flags)) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + _zip_ef_free(head); + return NULL; + } + + if (head == NULL) + head = def; + if (prev) + prev->next = def; + prev = def; + + ef = ef->next; + } + + return head; +} + + +zip_extra_field_t * +_zip_ef_delete_by_id(zip_extra_field_t *ef, zip_uint16_t id, zip_uint16_t id_idx, zip_flags_t flags) +{ + zip_extra_field_t *head, *prev; + int i; + + i = 0; + head = ef; + prev = NULL; + for (; ef; ef=(prev ? prev->next : head)) { + if ((ef->flags & flags & ZIP_EF_BOTH) && ((ef->id == id) || (id == ZIP_EXTRA_FIELD_ALL))) { + if (id_idx == ZIP_EXTRA_FIELD_ALL || i == id_idx) { + ef->flags &= ~(flags & ZIP_EF_BOTH); + if ((ef->flags & ZIP_EF_BOTH) == 0) { + if (prev) + prev->next = ef->next; + else + head = ef->next; + ef->next = NULL; + _zip_ef_free(ef); + + if (id_idx == ZIP_EXTRA_FIELD_ALL) + continue; + } + } + + i++; + if (i > id_idx) + break; + } + prev = ef; + } + + return head; +} + + + +void +_zip_ef_free(zip_extra_field_t *ef) +{ + zip_extra_field_t *ef2; + + while (ef) { + ef2 = ef->next; + free(ef->data); + free(ef); + ef = ef2; + } +} + + +const zip_uint8_t * +_zip_ef_get_by_id(const zip_extra_field_t *ef, zip_uint16_t *lenp, zip_uint16_t id, zip_uint16_t id_idx, zip_flags_t flags, zip_error_t *error) +{ + static const zip_uint8_t empty[1] = { '\0' }; + + int i; + + i = 0; + for (; ef; ef=ef->next) { + if (ef->id == id && (ef->flags & flags & ZIP_EF_BOTH)) { + if (i < id_idx) { + i++; + continue; + } + + if (lenp) + *lenp = ef->size; + if (ef->size > 0) + return ef->data; + else + return empty; + } + } + + zip_error_set(error, ZIP_ER_NOENT, 0); + return NULL; +} + + +zip_extra_field_t * +_zip_ef_merge(zip_extra_field_t *to, zip_extra_field_t *from) +{ + zip_extra_field_t *ef2, *tt, *tail; + int duplicate; + + if (to == NULL) + return from; + + for (tail=to; tail->next; tail=tail->next) + ; + + for (; from; from=ef2) { + ef2 = from->next; + + duplicate = 0; + for (tt=to; tt; tt=tt->next) { + if (tt->id == from->id && tt->size == from->size && memcmp(tt->data, from->data, tt->size) == 0) { + tt->flags |= (from->flags & ZIP_EF_BOTH); + duplicate = 1; + break; + } + } + + from->next = NULL; + if (duplicate) + _zip_ef_free(from); + else + tail = tail->next = from; + } + + return to; +} + + +zip_extra_field_t * +_zip_ef_new(zip_uint16_t id, zip_uint16_t size, const zip_uint8_t *data, zip_flags_t flags) +{ + zip_extra_field_t *ef; + + if ((ef=(zip_extra_field_t *)malloc(sizeof(*ef))) == NULL) + return NULL; + + ef->next = NULL; + ef->flags = flags; + ef->id = id; + ef->size = size; + if (size > 0) { + if ((ef->data=(zip_uint8_t *)_zip_memdup(data, size, NULL)) == NULL) { + free(ef); + return NULL; + } + } + else + ef->data = NULL; + + return ef; +} + + +zip_extra_field_t * +_zip_ef_parse(const zip_uint8_t *data, zip_uint16_t len, zip_flags_t flags, zip_error_t *error) +{ + zip_buffer_t *buffer; + zip_extra_field_t *ef, *ef2, *ef_head; + + if ((buffer = _zip_buffer_new((zip_uint8_t *)data, len)) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + return NULL; + } + + ef_head = ef = NULL; + + while (_zip_buffer_ok(buffer) && !_zip_buffer_eof(buffer)) { + zip_uint16_t fid, flen; + zip_uint8_t *ef_data; + + fid = _zip_buffer_get_16(buffer); + flen = _zip_buffer_get_16(buffer); + ef_data = _zip_buffer_get(buffer, flen); + + if (ef_data == NULL) { + break; + } + + if ((ef2=_zip_ef_new(fid, flen, ef_data, flags)) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + _zip_buffer_free(buffer); + _zip_ef_free(ef_head); + return NULL; + } + + if (ef_head) { + ef->next = ef2; + ef = ef2; + } + else + ef_head = ef = ef2; + } + + if (!_zip_buffer_eof(buffer)) { + zip_error_set(error, ZIP_ER_INCONS, 0); + _zip_buffer_free(buffer); + _zip_ef_free(ef_head); + return NULL; + } + + _zip_buffer_free(buffer); + + return ef_head; +} + + +zip_extra_field_t * +_zip_ef_remove_internal(zip_extra_field_t *ef) +{ + zip_extra_field_t *ef_head; + zip_extra_field_t *prev, *next; + + ef_head = ef; + prev = NULL; + + while (ef) { + if (ZIP_EF_IS_INTERNAL(ef->id)) { + next = ef->next; + if (ef_head == ef) + ef_head = next; + ef->next = NULL; + _zip_ef_free(ef); + if (prev) + prev->next = next; + ef = next; + } + else { + prev = ef; + ef = ef->next; + } + } + + return ef_head; +} + + +zip_uint16_t +_zip_ef_size(const zip_extra_field_t *ef, zip_flags_t flags) +{ + zip_uint16_t size; + + size = 0; + for (; ef; ef=ef->next) { + if (ef->flags & flags & ZIP_EF_BOTH) + size = (zip_uint16_t)(size+4+ef->size); + } + + return size; +} + + +int +_zip_ef_write(zip_t *za, const zip_extra_field_t *ef, zip_flags_t flags) +{ + zip_uint8_t b[4]; + zip_buffer_t *buffer = _zip_buffer_new(b, sizeof(b)); + + if (buffer == NULL) { + return -1; + } + + for (; ef; ef=ef->next) { + if (ef->flags & flags & ZIP_EF_BOTH) { + _zip_buffer_set_offset(buffer, 0); + _zip_buffer_put_16(buffer, ef->id); + _zip_buffer_put_16(buffer, ef->size); + if (!_zip_buffer_ok(buffer)) { + zip_error_set(&za->error, ZIP_ER_INTERNAL, 0); + _zip_buffer_free(buffer); + return -1; + } + if (_zip_write(za, b, 4) < 0) { + _zip_buffer_free(buffer); + return -1; + } + if (ef->size > 0) { + if (_zip_write(za, ef->data, ef->size) < 0) { + _zip_buffer_free(buffer); + return -1; + } + } + } + } + + _zip_buffer_free(buffer); + return 0; +} + + +int +_zip_read_local_ef(zip_t *za, zip_uint64_t idx) +{ + zip_entry_t *e; + unsigned char b[4]; + zip_buffer_t *buffer; + zip_uint16_t fname_len, ef_len; + + if (idx >= za->nentry) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + e = za->entry+idx; + + if (e->orig == NULL || e->orig->local_extra_fields_read) + return 0; + + if (e->orig->offset + 26 > ZIP_INT64_MAX) { + zip_error_set(&za->error, ZIP_ER_SEEK, EFBIG); + return -1; + } + + if (zip_source_seek(za->src, (zip_int64_t)(e->orig->offset + 26), SEEK_SET) < 0) { + _zip_error_set_from_source(&za->error, za->src); + return -1; + } + + if ((buffer = _zip_buffer_new_from_source(za->src, sizeof(b), b, &za->error)) == NULL) { + return -1; + } + + fname_len = _zip_buffer_get_16(buffer); + ef_len = _zip_buffer_get_16(buffer); + + if (!_zip_buffer_eof(buffer)) { + _zip_buffer_free(buffer); + zip_error_set(&za->error, ZIP_ER_INTERNAL, 0); + return -1; + } + + _zip_buffer_free(buffer); + + if (ef_len > 0) { + zip_extra_field_t *ef; + zip_uint8_t *ef_raw; + + if (zip_source_seek(za->src, fname_len, SEEK_CUR) < 0) { + zip_error_set(&za->error, ZIP_ER_SEEK, errno); + return -1; + } + + ef_raw = _zip_read_data(NULL, za->src, ef_len, 0, &za->error); + + if (ef_raw == NULL) + return -1; + + if ((ef=_zip_ef_parse(ef_raw, ef_len, ZIP_EF_LOCAL, &za->error)) == NULL) { + free(ef_raw); + return -1; + } + free(ef_raw); + + ef = _zip_ef_remove_internal(ef); + e->orig->extra_fields = _zip_ef_merge(e->orig->extra_fields, ef); + } + + e->orig->local_extra_fields_read = 1; + + if (e->changes && e->changes->local_extra_fields_read == 0) { + e->changes->extra_fields = e->orig->extra_fields; + e->changes->local_extra_fields_read = 1; + } + + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_extra_field_api.c b/ePub3/ThirdParty/libzip/zip_extra_field_api.c new file mode 100644 index 000000000..ed93944ac --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_extra_field_api.c @@ -0,0 +1,366 @@ +/* + zip_extra_field_api.c -- public extra fields API functions + Copyright (C) 2012-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +ZIP_EXTERN int +zip_file_extra_field_delete(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_flags_t flags) +{ + zip_dirent_t *de; + + if ((flags & ZIP_EF_BOTH) == 0) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (((flags & ZIP_EF_BOTH) == ZIP_EF_BOTH) && (ef_idx != ZIP_EXTRA_FIELD_ALL)) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (_zip_get_dirent(za, idx, 0, NULL) == NULL) + return -1; + + if (ZIP_IS_RDONLY(za)) { + zip_error_set(&za->error, ZIP_ER_RDONLY, 0); + return -1; + } + + if (_zip_file_extra_field_prepare_for_change(za, idx) < 0) + return -1; + + de = za->entry[idx].changes; + + de->extra_fields = _zip_ef_delete_by_id(de->extra_fields, ZIP_EXTRA_FIELD_ALL, ef_idx, flags); + return 0; +} + + +ZIP_EXTERN int +zip_file_extra_field_delete_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, zip_flags_t flags) +{ + zip_dirent_t *de; + + if ((flags & ZIP_EF_BOTH) == 0) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (((flags & ZIP_EF_BOTH) == ZIP_EF_BOTH) && (ef_idx != ZIP_EXTRA_FIELD_ALL)) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (_zip_get_dirent(za, idx, 0, NULL) == NULL) + return -1; + + if (ZIP_IS_RDONLY(za)) { + zip_error_set(&za->error, ZIP_ER_RDONLY, 0); + return -1; + } + + if (_zip_file_extra_field_prepare_for_change(za, idx) < 0) + return -1; + + de = za->entry[idx].changes; + + de->extra_fields = _zip_ef_delete_by_id(de->extra_fields, ef_id, ef_idx, flags); + return 0; +} + + +ZIP_EXTERN const zip_uint8_t * +zip_file_extra_field_get(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_uint16_t *idp, zip_uint16_t *lenp, zip_flags_t flags) +{ + static const zip_uint8_t empty[1] = { '\0' }; + + zip_dirent_t *de; + zip_extra_field_t *ef; + int i; + + if ((flags & ZIP_EF_BOTH) == 0) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return NULL; + } + + if ((de=_zip_get_dirent(za, idx, flags, &za->error)) == NULL) + return NULL; + + if (flags & ZIP_FL_LOCAL) + if (_zip_read_local_ef(za, idx) < 0) + return NULL; + + i = 0; + for (ef=de->extra_fields; ef; ef=ef->next) { + if (ef->flags & flags & ZIP_EF_BOTH) { + if (i < ef_idx) { + i++; + continue; + } + + if (idp) + *idp = ef->id; + if (lenp) + *lenp = ef->size; + if (ef->size > 0) + return ef->data; + else + return empty; + } + } + + zip_error_set(&za->error, ZIP_ER_NOENT, 0); + return NULL; + +} + + +ZIP_EXTERN const zip_uint8_t * +zip_file_extra_field_get_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, zip_uint16_t *lenp, zip_flags_t flags) +{ + zip_dirent_t *de; + + if ((flags & ZIP_EF_BOTH) == 0) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return NULL; + } + + if ((de=_zip_get_dirent(za, idx, flags, &za->error)) == NULL) + return NULL; + + if (flags & ZIP_FL_LOCAL) + if (_zip_read_local_ef(za, idx) < 0) + return NULL; + + return _zip_ef_get_by_id(de->extra_fields, lenp, ef_id, ef_idx, flags, &za->error); +} + + +ZIP_EXTERN zip_int16_t +zip_file_extra_fields_count(zip_t *za, zip_uint64_t idx, zip_flags_t flags) +{ + zip_dirent_t *de; + zip_extra_field_t *ef; + zip_uint16_t n; + + if ((flags & ZIP_EF_BOTH) == 0) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if ((de=_zip_get_dirent(za, idx, flags, &za->error)) == NULL) + return -1; + + if (flags & ZIP_FL_LOCAL) + if (_zip_read_local_ef(za, idx) < 0) + return -1; + + n = 0; + for (ef=de->extra_fields; ef; ef=ef->next) + if (ef->flags & flags & ZIP_EF_BOTH) + n++; + + return (zip_int16_t)n; +} + + +ZIP_EXTERN zip_int16_t +zip_file_extra_fields_count_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_flags_t flags) +{ + zip_dirent_t *de; + zip_extra_field_t *ef; + zip_uint16_t n; + + if ((flags & ZIP_EF_BOTH) == 0) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if ((de=_zip_get_dirent(za, idx, flags, &za->error)) == NULL) + return -1; + + if (flags & ZIP_FL_LOCAL) + if (_zip_read_local_ef(za, idx) < 0) + return -1; + + n = 0; + for (ef=de->extra_fields; ef; ef=ef->next) + if (ef->id == ef_id && (ef->flags & flags & ZIP_EF_BOTH)) + n++; + + return (zip_int16_t)n; +} + + +ZIP_EXTERN int +zip_file_extra_field_set(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, const zip_uint8_t *data, zip_uint16_t len, zip_flags_t flags) +{ + zip_dirent_t *de; + zip_uint16_t ls, cs; + zip_extra_field_t *ef, *ef_prev, *ef_new; + int i, found, new_len; + + if ((flags & ZIP_EF_BOTH) == 0) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (_zip_get_dirent(za, idx, 0, NULL) == NULL) + return -1; + + if (ZIP_IS_RDONLY(za)) { + zip_error_set(&za->error, ZIP_ER_RDONLY, 0); + return -1; + } + + if (ZIP_EF_IS_INTERNAL(ef_id)) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (_zip_file_extra_field_prepare_for_change(za, idx) < 0) + return -1; + + de = za->entry[idx].changes; + + ef = de->extra_fields; + ef_prev = NULL; + i = 0; + found = 0; + + for (; ef; ef=ef->next) { + if (ef->id == ef_id && (ef->flags & flags & ZIP_EF_BOTH)) { + if (i == ef_idx) { + found = 1; + break; + } + i++; + } + ef_prev = ef; + } + + if (i < ef_idx && ef_idx != ZIP_EXTRA_FIELD_NEW) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (flags & ZIP_EF_LOCAL) + ls = _zip_ef_size(de->extra_fields, ZIP_EF_LOCAL); + else + ls = 0; + if (flags & ZIP_EF_CENTRAL) + cs = _zip_ef_size(de->extra_fields, ZIP_EF_CENTRAL); + else + cs = 0; + + new_len = ls > cs ? ls : cs; + if (found) + new_len -= ef->size + 4; + new_len += len + 4; + + if (new_len > ZIP_UINT16_MAX) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if ((ef_new=_zip_ef_new(ef_id, len, data, flags)) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return -1; + } + + if (found) { + if ((ef->flags & ZIP_EF_BOTH) == (flags & ZIP_EF_BOTH)) { + ef_new->next = ef->next; + ef->next = NULL; + _zip_ef_free(ef); + if (ef_prev) + ef_prev->next = ef_new; + else + de->extra_fields = ef_new; + } + else { + ef->flags &= ~(flags & ZIP_EF_BOTH); + ef_new->next = ef->next; + ef->next = ef_new; + } + } + else if (ef_prev) { + ef_new->next = ef_prev->next; + ef_prev->next = ef_new; + } + else + de->extra_fields = ef_new; + + return 0; +} + + + +int +_zip_file_extra_field_prepare_for_change(zip_t *za, zip_uint64_t idx) +{ + zip_entry_t *e; + + if (idx >= za->nentry) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + e = za->entry+idx; + + if (e->changes && (e->changes->changed & ZIP_DIRENT_EXTRA_FIELD)) + return 0; + + if (e->orig) { + if (_zip_read_local_ef(za, idx) < 0) + return -1; + } + + if (e->changes == NULL) { + if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return -1; + } + } + + if (e->orig && e->orig->extra_fields) { + if ((e->changes->extra_fields=_zip_ef_clone(e->orig->extra_fields, &za->error)) == NULL) + return -1; + } + e->changes->changed |= ZIP_DIRENT_EXTRA_FIELD; + + return 0; +} + diff --git a/ePub3/ThirdParty/libzip/zip_fclose.c b/ePub3/ThirdParty/libzip/zip_fclose.c index 8709362d6..25a201b18 100644 --- a/ePub3/ThirdParty/libzip/zip_fclose.c +++ b/ePub3/ThirdParty/libzip/zip_fclose.c @@ -1,6 +1,6 @@ /* zip_fclose.c -- close file in zip archive - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,41 +31,25 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include "zipint.h" - ZIP_EXTERN int -zip_fclose(struct zip_file *zf) +zip_fclose(zip_file_t *zf) { - int i, ret; + int ret; - if (zf->zstr) - inflateEnd(zf->zstr); - free(zf->buffer); - free(zf->zstr); - - for (i=0; iza->nfile; i++) { - if (zf->za->file[i] == zf) { - zf->za->file[i] = zf->za->file[zf->za->nfile-1]; - zf->za->nfile--; - break; - } - } + if (zf->src) + zip_source_free(zf->src); ret = 0; if (zf->error.zip_err) ret = zf->error.zip_err; - else if ((zf->flags & ZIP_ZF_CRC) && (zf->flags & ZIP_ZF_EOF)) { - /* if EOF, compare CRC */ - if (zf->crc_orig != zf->crc) - ret = ZIP_ER_CRC; - } + zip_error_fini(&zf->error); free(zf); return ret; } diff --git a/ePub3/ThirdParty/libzip/zip_fdopen.c b/ePub3/ThirdParty/libzip/zip_fdopen.c new file mode 100644 index 000000000..c5b55311d --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_fdopen.c @@ -0,0 +1,82 @@ +/* + zip_fdopen.c -- open read-only archive from file descriptor + Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +ZIP_EXTERN zip_t * +zip_fdopen(int fd_orig, int _flags, int *zep) +{ + int fd; + FILE *fp; + zip_t *za; + zip_source_t *src; + struct zip_error error; + + if (_flags < 0 || (_flags & ZIP_TRUNCATE)) { + _zip_set_open_error(zep, NULL, ZIP_ER_INVAL); + return NULL; + } + + /* We dup() here to avoid messing with the passed in fd. + We could not restore it to the original state in case of error. */ + + if ((fd=dup(fd_orig)) < 0) { + _zip_set_open_error(zep, NULL, ZIP_ER_OPEN); + return NULL; + } + + if ((fp=fdopen(fd, "rb")) == NULL) { + close(fd); + _zip_set_open_error(zep, NULL, ZIP_ER_OPEN); + return NULL; + } + + zip_error_init(&error); + if ((src = zip_source_filep_create(fp, 0, -1, &error)) == NULL) { + _zip_set_open_error(zep, &error, 0); + zip_error_fini(&error); + return NULL; + } + + if ((za = zip_open_from_source(src, _flags, &error)) == NULL) { + _zip_set_open_error(zep, &error, 0); + zip_error_fini(&error); + return NULL; + } + + zip_error_fini(&error); + close(fd_orig); + return za; +} diff --git a/ePub3/ThirdParty/libzip/zip_file_add.c b/ePub3/ThirdParty/libzip/zip_file_add.c new file mode 100644 index 000000000..9944c0f12 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_file_add.c @@ -0,0 +1,53 @@ +/* + zip_file_add.c -- add file via callback function + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + +/* + NOTE: Return type is signed so we can return -1 on error. + The index can not be larger than ZIP_INT64_MAX since the size + of the central directory cannot be larger than + ZIP_UINT64_MAX, and each entry is larger than 2 bytes. +*/ + +ZIP_EXTERN zip_int64_t +zip_file_add(zip_t *za, const char *name, zip_source_t *source, zip_flags_t flags) +{ + if (name == NULL || source == NULL) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + return _zip_file_replace(za, ZIP_UINT64_MAX, name, source, flags); +} diff --git a/ePub3/ThirdParty/libzip/zip_file_error_clear.c b/ePub3/ThirdParty/libzip/zip_file_error_clear.c index ef6fa10e4..be454982a 100644 --- a/ePub3/ThirdParty/libzip/zip_file_error_clear.c +++ b/ePub3/ThirdParty/libzip/zip_file_error_clear.c @@ -1,6 +1,6 @@ /* zip_file_error_clear.c -- clear zip file error - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,14 +31,15 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "zipint.h" - ZIP_EXTERN void -zip_file_error_clear(struct zip_file *zf) +zip_file_error_clear(zip_file_t *zf) { + if (zf == NULL) + return; + _zip_error_clear(&zf->error); } diff --git a/ePub3/ThirdParty/libzip/zip_file_error_get.c b/ePub3/ThirdParty/libzip/zip_file_error_get.c index f20e011fc..be764fd52 100644 --- a/ePub3/ThirdParty/libzip/zip_file_error_get.c +++ b/ePub3/ThirdParty/libzip/zip_file_error_get.c @@ -1,6 +1,6 @@ /* zip_file_error_get.c -- get zip file error - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,14 +31,12 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - - +#define _ZIP_COMPILING_DEPRECATED #include "zipint.h" - ZIP_EXTERN void -zip_file_error_get(struct zip_file *zf, int *zep, int *sep) +zip_file_error_get(zip_file_t *zf, int *zep, int *sep) { _zip_error_get(&zf->error, zep, sep); } diff --git a/ePub3/ThirdParty/libzip/zip_file_get_comment.c b/ePub3/ThirdParty/libzip/zip_file_get_comment.c new file mode 100644 index 000000000..55e7dc289 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_file_get_comment.c @@ -0,0 +1,56 @@ +/* + zip_file_get_comment.c -- get file comment + Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + +/* lenp is 32 bit because converted comment can be longer than ZIP_UINT16_MAX */ + +ZIP_EXTERN const char * +zip_file_get_comment(zip_t *za, zip_uint64_t idx, zip_uint32_t *lenp, zip_flags_t flags) +{ + zip_dirent_t *de; + zip_uint32_t len; + const zip_uint8_t *str; + + if ((de=_zip_get_dirent(za, idx, flags, NULL)) == NULL) + return NULL; + + if ((str=_zip_string_get(de->comment, &len, flags, &za->error)) == NULL) + return NULL; + + if (lenp) + *lenp = len; + + return (const char *)str; +} diff --git a/ePub3/ThirdParty/libzip/zip_file_get_external_attributes.c b/ePub3/ThirdParty/libzip/zip_file_get_external_attributes.c new file mode 100644 index 000000000..b6526cf23 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_file_get_external_attributes.c @@ -0,0 +1,51 @@ +/* + zip_file_get_external_attributes.c -- get opsys/external attributes + Copyright (C) 2013-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "zipint.h" + +int +zip_file_get_external_attributes(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_uint8_t *opsys, zip_uint32_t *attributes) +{ + zip_dirent_t *de; + + if ((de=_zip_get_dirent(za, idx, flags, NULL)) == NULL) + return -1; + + if (opsys) + *opsys = (zip_uint8_t)((de->version_madeby >> 8) & 0xff); + + if (attributes) + *attributes = de->ext_attrib; + + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_file_get_offset.c b/ePub3/ThirdParty/libzip/zip_file_get_offset.c index c35027ef0..1aaca712d 100644 --- a/ePub3/ThirdParty/libzip/zip_file_get_offset.c +++ b/ePub3/ThirdParty/libzip/zip_file_get_offset.c @@ -1,6 +1,6 @@ /* zip_file_get_offset.c -- get offset of file data in archive. - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,7 +31,6 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include @@ -42,14 +41,6 @@ #include "zipint.h" -#if defined(_MSC_VER) -# define strdup _strdup -# define fseeko fseek -# define ftello ftell -# define fileno _fileno -#endif - - /* _zip_file_get_offset(za, ze): Returns the offset of the file data for entry ze. @@ -57,39 +48,27 @@ On error, fills in za->error and returns 0. */ -unsigned int -_zip_file_get_offset(struct zip *za, int idx) +zip_uint64_t +_zip_file_get_offset(const zip_t *za, zip_uint64_t idx, zip_error_t *error) { - struct zip_dirent de; - unsigned int offset; + zip_uint64_t offset; + zip_int32_t size; - offset = za->cdir->entry[idx].offset; + offset = za->entry[idx].orig->offset; - if (fseeko(za->zp, offset, SEEK_SET) != 0) { - _zip_error_set(&za->error, ZIP_ER_SEEK, errno); + if (zip_source_seek(za->src, (zip_int64_t)offset, SEEK_SET) < 0) { + _zip_error_set_from_source(error, za->src); return 0; } - if (_zip_dirent_read(&de, za->zp, NULL, NULL, 1, &za->error) != 0) + /* TODO: cache? */ + if ((size=_zip_dirent_size(za->src, ZIP_EF_LOCAL, error)) < 0) return 0; - offset += LENTRYSIZE + de.filename_len + de.extrafield_len; - - _zip_dirent_finalize(&de); - - return offset; -} - -/* JCD added */ -unsigned int -_zip_file_get_offset_safe(struct zip* za, int idx) -{ - off_t curoff; - unsigned int offset; - - curoff = ftello(za->zp); - offset = _zip_file_get_offset(za, idx); - fseeko(za->zp, curoff, SEEK_SET); + if (offset+(zip_uint32_t)size > ZIP_INT64_MAX) { + zip_error_set(error, ZIP_ER_SEEK, EFBIG); + return 0; + } - return offset; + return offset + (zip_uint32_t)size; } diff --git a/ePub3/ThirdParty/libzip/zip_file_rename.c b/ePub3/ThirdParty/libzip/zip_file_rename.c new file mode 100644 index 000000000..4400938ab --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_file_rename.c @@ -0,0 +1,68 @@ +/* + zip_file_rename.c -- rename file in zip archive + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include + +#include "zipint.h" + + +ZIP_EXTERN int +zip_file_rename(zip_t *za, zip_uint64_t idx, const char *name, zip_flags_t flags) +{ + const char *old_name; + int old_is_dir, new_is_dir; + + if (idx >= za->nentry || (name != NULL && strlen(name) > ZIP_UINT16_MAX)) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (ZIP_IS_RDONLY(za)) { + zip_error_set(&za->error, ZIP_ER_RDONLY, 0); + return -1; + } + + if ((old_name=zip_get_name(za, idx, 0)) == NULL) + return -1; + + new_is_dir = (name != NULL && name[strlen(name)-1] == '/'); + old_is_dir = (old_name[strlen(old_name)-1] == '/'); + + if (new_is_dir != old_is_dir) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + return _zip_set_name(za, idx, name, flags); +} diff --git a/ePub3/ThirdParty/libzip/zip_file_replace.c b/ePub3/ThirdParty/libzip/zip_file_replace.c new file mode 100644 index 000000000..e430efae9 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_file_replace.c @@ -0,0 +1,108 @@ +/* + zip_file_replace.c -- replace file via callback function + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +ZIP_EXTERN int +zip_file_replace(zip_t *za, zip_uint64_t idx, zip_source_t *source, zip_flags_t flags) +{ + if (idx >= za->nentry || source == NULL) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (_zip_file_replace(za, idx, NULL, source, flags) == -1) + return -1; + + return 0; +} + + + +/* NOTE: Signed due to -1 on error. See zip_add.c for more details. */ + +zip_int64_t +_zip_file_replace(zip_t *za, zip_uint64_t idx, const char *name, zip_source_t *source, zip_flags_t flags) +{ + zip_uint64_t za_nentry_prev; + + if (ZIP_IS_RDONLY(za)) { + zip_error_set(&za->error, ZIP_ER_RDONLY, 0); + return -1; + } + + za_nentry_prev = za->nentry; + if (idx == ZIP_UINT64_MAX) { + zip_int64_t i = -1; + + if (flags & ZIP_FL_OVERWRITE) + i = _zip_name_locate(za, name, flags, NULL); + + if (i == -1) { + /* create and use new entry, used by zip_add */ + if ((i=_zip_add_entry(za)) < 0) + return -1; + } + idx = (zip_uint64_t)i; + } + + if (name && _zip_set_name(za, idx, name, flags) != 0) { + if (za->nentry != za_nentry_prev) { + _zip_entry_finalize(za->entry+idx); + za->nentry = za_nentry_prev; + } + return -1; + } + + /* does not change any name related data, so we can do it here; + * needed for a double add of the same file name */ + _zip_unchange_data(za->entry+idx); + + if (za->entry[idx].orig != NULL && (za->entry[idx].changes == NULL || (za->entry[idx].changes->changed & ZIP_DIRENT_COMP_METHOD) == 0)) { + if (za->entry[idx].changes == NULL) { + if ((za->entry[idx].changes=_zip_dirent_clone(za->entry[idx].orig)) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return -1; + } + } + + za->entry[idx].changes->comp_method = ZIP_CM_REPLACED_DEFAULT; + za->entry[idx].changes->changed |= ZIP_DIRENT_COMP_METHOD; + } + + za->entry[idx].source = source; + + return (zip_int64_t)idx; +} diff --git a/ePub3/ThirdParty/libzip/zip_file_set_comment.c b/ePub3/ThirdParty/libzip/zip_file_set_comment.c new file mode 100644 index 000000000..e455fbd28 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_file_set_comment.c @@ -0,0 +1,103 @@ +/* + zip_file_set_comment.c -- set comment for file in archive + Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include + +#include "zipint.h" + + +ZIP_EXTERN int +zip_file_set_comment(zip_t *za, zip_uint64_t idx, + const char *comment, zip_uint16_t len, zip_flags_t flags) +{ + zip_entry_t *e; + zip_string_t *cstr; + int changed; + + if (_zip_get_dirent(za, idx, 0, NULL) == NULL) + return -1; + + if (ZIP_IS_RDONLY(za)) { + zip_error_set(&za->error, ZIP_ER_RDONLY, 0); + return -1; + } + + if (len > 0 && comment == NULL) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (len > 0) { + if ((cstr=_zip_string_new((const zip_uint8_t *)comment, len, flags, &za->error)) == NULL) + return -1; + if ((flags & ZIP_FL_ENCODING_ALL) == ZIP_FL_ENC_GUESS && _zip_guess_encoding(cstr, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_UTF8_GUESSED) + cstr->encoding = ZIP_ENCODING_UTF8_KNOWN; + } + else + cstr = NULL; + + e = za->entry+idx; + + if (e->changes) { + _zip_string_free(e->changes->comment); + e->changes->comment = NULL; + e->changes->changed &= ~ZIP_DIRENT_COMMENT; + } + + if (e->orig && e->orig->comment) + changed = !_zip_string_equal(e->orig->comment, cstr); + else + changed = (cstr != NULL); + + if (changed) { + if (e->changes == NULL) { + if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + _zip_string_free(cstr); + return -1; + } + } + e->changes->comment = cstr; + e->changes->changed |= ZIP_DIRENT_COMMENT; + } + else { + _zip_string_free(cstr); + if (e->changes && e->changes->changed == 0) { + _zip_dirent_free(e->changes); + e->changes = NULL; + } + } + + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_file_set_external_attributes.c b/ePub3/ThirdParty/libzip/zip_file_set_external_attributes.c new file mode 100644 index 000000000..b772c31e0 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_file_set_external_attributes.c @@ -0,0 +1,83 @@ +/* + zip_file_set_external_attributes.c -- set external attributes for entry + Copyright (C) 2013-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "zipint.h" + +ZIP_EXTERN int +zip_file_set_external_attributes(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_uint8_t opsys, zip_uint32_t attributes) +{ + zip_entry_t *e; + int changed; + zip_uint8_t unchanged_opsys; + zip_uint32_t unchanged_attributes; + + if (_zip_get_dirent(za, idx, 0, NULL) == NULL) + return -1; + + if (ZIP_IS_RDONLY(za)) { + zip_error_set(&za->error, ZIP_ER_RDONLY, 0); + return -1; + } + + e = za->entry+idx; + + unchanged_opsys = (e->orig ? (zip_uint8_t)(e->orig->version_madeby>>8) : (zip_uint8_t)ZIP_OPSYS_DEFAULT); + unchanged_attributes = e->orig ? e->orig->ext_attrib : ZIP_EXT_ATTRIB_DEFAULT; + + changed = (opsys != unchanged_opsys || attributes != unchanged_attributes); + + if (changed) { + if (e->changes == NULL) { + if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return -1; + } + } + e->changes->version_madeby = (zip_uint16_t)((opsys << 8) | (e->changes->version_madeby & 0xff)); + e->changes->ext_attrib = attributes; + e->changes->changed |= ZIP_DIRENT_ATTRIBUTES; + } + else if (e->changes) { + e->changes->changed &= ~ZIP_DIRENT_ATTRIBUTES; + if (e->changes->changed == 0) { + _zip_dirent_free(e->changes); + e->changes = NULL; + } + else { + e->changes->version_madeby = (zip_uint16_t)((unchanged_opsys << 8) | (e->changes->version_madeby & 0xff)); + e->changes->ext_attrib = unchanged_attributes; + } + } + + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_file_set_mtime.c b/ePub3/ThirdParty/libzip/zip_file_set_mtime.c new file mode 100644 index 000000000..0cdd31a67 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_file_set_mtime.c @@ -0,0 +1,74 @@ +/* + zip_file_set_mtime.c -- set modification time of entry. + Copyright (C) 2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "zipint.h" + +ZIP_EXTERN int zip_file_set_mtime(zip_t *za, zip_uint64_t idx, time_t mtime, zip_flags_t flags) +{ + zip_entry_t *e; + int changed; + + if (_zip_get_dirent(za, idx, 0, NULL) == NULL) + return -1; + + if (ZIP_IS_RDONLY(za)) { + zip_error_set(&za->error, ZIP_ER_RDONLY, 0); + return -1; + } + + e = za->entry+idx; + + changed = e->orig == NULL || mtime != e->orig->last_mod; + + if (changed) { + if (e->changes == NULL) { + if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return -1; + } + } + e->changes->last_mod = mtime; + e->changes->changed |= ZIP_DIRENT_LAST_MOD; + } + else { + if (e->changes) { + e->changes->changed &= ~ZIP_DIRENT_LAST_MOD; + if (e->changes->changed == 0) { + _zip_dirent_free(e->changes); + e->changes = NULL; + } + } + } + + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_file_strerror.c b/ePub3/ThirdParty/libzip/zip_file_strerror.c index 9ba70f14f..8366f1ea9 100644 --- a/ePub3/ThirdParty/libzip/zip_file_strerror.c +++ b/ePub3/ThirdParty/libzip/zip_file_strerror.c @@ -1,6 +1,6 @@ /* zip_file_sterror.c -- get string representation of zip file error - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,14 +31,12 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "zipint.h" - ZIP_EXTERN const char * -zip_file_strerror(struct zip_file *zf) +zip_file_strerror(zip_file_t *zf) { - return _zip_error_strerror(&zf->error); + return zip_error_strerror(&zf->error); } diff --git a/ePub3/ThirdParty/libzip/zip_filerange_crc.c b/ePub3/ThirdParty/libzip/zip_filerange_crc.c index e00809cae..8e06e8fa8 100644 --- a/ePub3/ThirdParty/libzip/zip_filerange_crc.c +++ b/ePub3/ThirdParty/libzip/zip_filerange_crc.c @@ -1,6 +1,6 @@ /* zip_filerange_crc.c -- compute CRC32 for a range of a file - Copyright (C) 2008 Dieter Baron and Thomas Klausner + Copyright (C) 2008-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,46 +31,46 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include #include "zipint.h" -#if defined(_MSC_VER) -# define strdup _strdup -# define fseeko fseek -# define ftello ftell -# define fileno _fileno -#endif - int -_zip_filerange_crc(FILE *fp, off_t start, off_t len, uLong *crcp, - struct zip_error *errp) +_zip_filerange_crc(zip_source_t *src, zip_uint64_t start, zip_uint64_t len, uLong *crcp, zip_error_t *error) { Bytef buf[BUFSIZE]; - size_t n; + zip_int64_t n; *crcp = crc32(0L, Z_NULL, 0); - if (fseeko(fp, start, SEEK_SET) != 0) { - _zip_error_set(errp, ZIP_ER_SEEK, errno); + if (start > ZIP_INT64_MAX) { + zip_error_set(error, ZIP_ER_SEEK, EFBIG); + return -1; + } + + if (zip_source_seek(src, (zip_int64_t)start, SEEK_SET) != 0) { + _zip_error_set_from_source(error, src); return -1; } while (len > 0) { - n = len > BUFSIZE ? BUFSIZE : (size_t)len; - if ((n=fread(buf, 1, n, fp)) <= 0) { - _zip_error_set(errp, ZIP_ER_READ, errno); + n = (zip_int64_t)(len > BUFSIZE ? BUFSIZE : len); + if ((n = zip_source_read(src, buf, (zip_uint64_t)n)) < 0) { + _zip_error_set_from_source(error, src); + return -1; + } + if (n == 0) { + zip_error_set(error, ZIP_ER_EOF, 0); return -1; } - *crcp = crc32(*crcp, buf, (unsigned int)n); + *crcp = crc32(*crcp, buf, (uInt)n); - len-= (off_t)n; + len -= (zip_uint64_t)n; } return 0; diff --git a/ePub3/ThirdParty/libzip/zip_fopen.c b/ePub3/ThirdParty/libzip/zip_fopen.c index 6e2f72412..3adb5de65 100644 --- a/ePub3/ThirdParty/libzip/zip_fopen.c +++ b/ePub3/ThirdParty/libzip/zip_fopen.c @@ -1,6 +1,6 @@ /* zip_fopen.c -- open file in zip archive for reading - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,19 +31,17 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "zipint.h" - -ZIP_EXTERN struct zip_file * -zip_fopen(struct zip *za, const char *fname, int flags) +ZIP_EXTERN zip_file_t * +zip_fopen(zip_t *za, const char *fname, zip_flags_t flags) { - int idx; + zip_int64_t idx; if ((idx=zip_name_locate(za, fname, flags)) < 0) return NULL; - return zip_fopen_index(za, idx, flags); + return zip_fopen_index_encrypted(za, (zip_uint64_t)idx, flags, za->default_password); } diff --git a/ePub3/ThirdParty/libzip/zip_fopen_encrypted.c b/ePub3/ThirdParty/libzip/zip_fopen_encrypted.c new file mode 100644 index 000000000..5eaf2b04b --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_fopen_encrypted.c @@ -0,0 +1,47 @@ +/* + zip_fopen_encrypted.c -- open file for reading with password + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +ZIP_EXTERN zip_file_t * +zip_fopen_encrypted(zip_t *za, const char *fname, zip_flags_t flags, const char *password) +{ + zip_int64_t idx; + + if ((idx=zip_name_locate(za, fname, flags)) < 0) + return NULL; + + return zip_fopen_index_encrypted(za, (zip_uint64_t)idx, flags, password); +} diff --git a/ePub3/ThirdParty/libzip/zip_fopen_index.c b/ePub3/ThirdParty/libzip/zip_fopen_index.c index 291ac733c..e9a169a2e 100644 --- a/ePub3/ThirdParty/libzip/zip_fopen_index.c +++ b/ePub3/ThirdParty/libzip/zip_fopen_index.c @@ -1,6 +1,6 @@ /* zip_fopen_index.c -- open file in zip archive for reading by index - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,7 +31,6 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include @@ -39,200 +38,9 @@ #include "zipint.h" -#if defined(_MSC_VER) -# define strdup _strdup -# define fseeko fseek -# define ftello ftell -# define fileno _fileno -#endif -static struct zip_file *_zip_file_new(struct zip *za); - - - -ZIP_EXTERN struct zip_file * -zip_fopen_index(struct zip *za, int fileno, int flags) +ZIP_EXTERN zip_file_t * +zip_fopen_index(zip_t *za, zip_uint64_t index, zip_flags_t flags) { - int len, ret; - int zfflags; - struct zip_file *zf; - - if ((fileno < 0) || (fileno >= za->nentry)) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); - return NULL; - } - - if ((flags & ZIP_FL_UNCHANGED) == 0 - && ZIP_ENTRY_DATA_CHANGED(za->entry+fileno)) { - _zip_error_set(&za->error, ZIP_ER_CHANGED, 0); - return NULL; - } - - if (fileno >= za->cdir->nentry) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); - return NULL; - } - - zfflags = 0; - switch (za->cdir->entry[fileno].comp_method) { - case ZIP_CM_STORE: - zfflags |= ZIP_ZF_CRC; - break; - - case ZIP_CM_DEFLATE: - if ((flags & ZIP_FL_COMPRESSED) == 0) - zfflags |= ZIP_ZF_CRC | ZIP_ZF_DECOMP; - break; - default: - if ((flags & ZIP_FL_COMPRESSED) == 0) { - _zip_error_set(&za->error, ZIP_ER_COMPNOTSUPP, 0); - return NULL; - } - break; - } - - zf = _zip_file_new(za); - if (zf == NULL) { - _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); - return NULL; - } - - zf->flags = zfflags; - /* zf->name = za->cdir->entry[fileno].filename; */ - zf->method = za->cdir->entry[fileno].comp_method; - zf->bytes_left = za->cdir->entry[fileno].uncomp_size; - zf->cbytes_left = za->cdir->entry[fileno].comp_size; - zf->crc_orig = za->cdir->entry[fileno].crc; - - if ((zf->fpos=_zip_file_get_offset(za, fileno)) == 0) { - zip_fclose(zf); - return NULL; - } - - if ((zf->flags & ZIP_ZF_DECOMP) == 0) - zf->bytes_left = zf->cbytes_left; - else { - if ((zf->buffer=(char *)malloc(BUFSIZE)) == NULL) { - _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); - zip_fclose(zf); - return NULL; - } - - len = _zip_file_fillbuf(zf->buffer, BUFSIZE, zf); - if (len <= 0) { - _zip_error_copy(&za->error, &zf->error); - zip_fclose(zf); - return NULL; - } - - if ((zf->zstr = (z_stream *)malloc(sizeof(z_stream))) == NULL) { - _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); - zip_fclose(zf); - return NULL; - } - zf->zstr->zalloc = Z_NULL; - zf->zstr->zfree = Z_NULL; - zf->zstr->opaque = NULL; - zf->zstr->next_in = (Bytef *)zf->buffer; - zf->zstr->avail_in = len; - - /* negative value to tell zlib that there is no header */ - if ((ret=inflateInit2(zf->zstr, -MAX_WBITS)) != Z_OK) { - _zip_error_set(&za->error, ZIP_ER_ZLIB, ret); - zip_fclose(zf); - return NULL; - } - } - - /* JCD added begin */ - - /* store the file index for cloning purposes */ - zf->file_index = fileno; - - /* store position within this file */ - /* NB: position is relative to bytes returned from zip_fread(), is dependent on ZIP_FL_COMPRESSED, etc. */ - zf->file_fpos = 0; - - /* JCD added end */ - - return zf; -} - - - -int -_zip_file_fillbuf(void *buf, size_t buflen, struct zip_file *zf) -{ - ssize_t i, j; - - if (zf->error.zip_err != ZIP_ER_OK) - return -1; - - if ((zf->flags & ZIP_ZF_EOF) || zf->cbytes_left <= 0 || buflen <= 0) - return 0; - - if (fseeko(zf->za->zp, zf->fpos, SEEK_SET) < 0) { - _zip_error_set(&zf->error, ZIP_ER_SEEK, errno); - return -1; - } - if (buflen < zf->cbytes_left) - i = (ssize_t)buflen; - else - i = zf->cbytes_left; - - j = (ssize_t)fread(buf, 1, i, zf->za->zp); - if (j == 0) { - _zip_error_set(&zf->error, ZIP_ER_EOF, 0); - j = -1; - } - else if (j < 0) - _zip_error_set(&zf->error, ZIP_ER_READ, errno); - else { - zf->fpos += j; - zf->cbytes_left -= j; - } - - return (int)j; -} - - - -static struct zip_file * -_zip_file_new(struct zip *za) -{ - struct zip_file *zf, **file; - int n; - - if ((zf=(struct zip_file *)malloc(sizeof(struct zip_file))) == NULL) { - _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); - return NULL; - } - - if (za->nfile >= za->nfile_alloc-1) { - n = za->nfile_alloc + 10; - file = (struct zip_file **)realloc(za->file, - n*sizeof(struct zip_file *)); - if (file == NULL) { - _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); - free(zf); - return NULL; - } - za->nfile_alloc = n; - za->file = file; - } - - za->file[za->nfile++] = zf; - - zf->za = za; - _zip_error_init(&zf->error); - zf->flags = 0; - zf->crc = crc32(0L, Z_NULL, 0); - zf->crc_orig = 0; - zf->method = -1; - zf->bytes_left = zf->cbytes_left = 0; - zf->fpos = 0; - zf->buffer = NULL; - zf->zstr = NULL; - - return zf; + return zip_fopen_index_encrypted(za, index, flags, za->default_password); } diff --git a/ePub3/ThirdParty/libzip/zip_fopen_index_encrypted.c b/ePub3/ThirdParty/libzip/zip_fopen_index_encrypted.c new file mode 100644 index 000000000..21cc43333 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_fopen_index_encrypted.c @@ -0,0 +1,87 @@ +/* + zip_fopen_index_encrypted.c -- open file for reading by index w/ password + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include +#include +#include + +#include "zipint.h" + +static zip_file_t *_zip_file_new(zip_t *za); + + +ZIP_EXTERN zip_file_t * +zip_fopen_index_encrypted(zip_t *za, zip_uint64_t index, zip_flags_t flags, + const char *password) +{ + zip_file_t *zf; + zip_source_t *src; + + if ((src=_zip_source_zip_new(za, za, index, flags, 0, 0, password)) == NULL) + return NULL; + + if (zip_source_open(src) < 0) { + _zip_error_set_from_source(&za->error, src); + zip_source_free(src); + return NULL; + } + + if ((zf=_zip_file_new(za)) == NULL) { + zip_source_free(src); + return NULL; + } + + zf->src = src; + + return zf; +} + + +static zip_file_t * +_zip_file_new(zip_t *za) +{ + zip_file_t *zf; + + if ((zf=(zip_file_t *)malloc(sizeof(struct zip_file))) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return NULL; + } + + zf->za = za; + zip_error_init(&zf->error); + zf->eof = 0; + zf->src = NULL; + + return zf; +} diff --git a/ePub3/ThirdParty/libzip/zip_fread.c b/ePub3/ThirdParty/libzip/zip_fread.c index c1e7fd7f7..9c1cbe0c4 100644 --- a/ePub3/ThirdParty/libzip/zip_fread.c +++ b/ePub3/ThirdParty/libzip/zip_fread.c @@ -1,6 +1,6 @@ /* zip_fread.c -- read from file - Copyright (C) 1999-2009 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,18 +31,14 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "zipint.h" - -ZIP_EXTERN ssize_t -zip_fread(struct zip_file *zf, void *outbuf, size_t toread) +ZIP_EXTERN zip_int64_t +zip_fread(zip_file_t *zf, void *outbuf, zip_uint64_t toread) { - int ret; - size_t out_before, len; - int i; + zip_int64_t n; if (!zf) return -1; @@ -50,83 +46,18 @@ zip_fread(struct zip_file *zf, void *outbuf, size_t toread) if (zf->error.zip_err != 0) return -1; - if ((zf->flags & ZIP_ZF_EOF) || (toread == 0)) - return 0; - - if (zf->bytes_left == 0) { - zf->flags |= ZIP_ZF_EOF; - if (zf->flags & ZIP_ZF_CRC) { - if (zf->crc != zf->crc_orig) { - _zip_error_set(&zf->error, ZIP_ER_CRC, 0); - return -1; - } - } - return 0; - } - - if ((zf->flags & ZIP_ZF_DECOMP) == 0) { - ret = _zip_file_fillbuf(outbuf, toread, zf); - if (ret > 0) { - if (zf->flags & ZIP_ZF_CRC) - zf->crc = crc32(zf->crc, (Bytef *)outbuf, ret); - zf->bytes_left -= ret; - zf->file_fpos += ret; /* JCD added: zip_ftell() support */ - } - return ret; + if (toread > ZIP_INT64_MAX) { + zip_error_set(&zf->error, ZIP_ER_INVAL, 0); + return -1; } - - zf->zstr->next_out = (Bytef *)outbuf; - zf->zstr->avail_out = (unsigned int)toread; - out_before = zf->zstr->total_out; - - /* endless loop until something has been accomplished */ - for (;;) { - ret = inflate(zf->zstr, Z_SYNC_FLUSH); - switch (ret) { - case Z_STREAM_END: - if (zf->zstr->total_out == out_before) { - if (zf->crc != zf->crc_orig) { - _zip_error_set(&zf->error, ZIP_ER_CRC, 0); - return -1; - } - else - return 0; - } - - /* fallthrough */ - - case Z_OK: - len = zf->zstr->total_out - out_before; - if (len >= zf->bytes_left || len >= toread) { - if (zf->flags & ZIP_ZF_CRC) - zf->crc = crc32(zf->crc, (Bytef *)outbuf, (unsigned int)len); - zf->bytes_left -= (unsigned long)len; - zf->file_fpos += (off_t)len; /* JCD added: zip_ftell() support */ - return (ssize_t)len; - } - break; + if ((zf->eof) || (toread == 0)) + return 0; - case Z_BUF_ERROR: - if (zf->zstr->avail_in == 0) { - i = _zip_file_fillbuf(zf->buffer, BUFSIZE, zf); - if (i == 0) { - _zip_error_set(&zf->error, ZIP_ER_INCONS, 0); - return -1; - } - else if (i < 0) - return -1; - zf->zstr->next_in = (Bytef *)zf->buffer; - zf->zstr->avail_in = i; - continue; - } - /* fallthrough */ - case Z_NEED_DICT: - case Z_DATA_ERROR: - case Z_STREAM_ERROR: - case Z_MEM_ERROR: - _zip_error_set(&zf->error, ZIP_ER_ZLIB, ret); - return -1; - } + if ((n=zip_source_read(zf->src, outbuf, toread)) < 0) { + _zip_error_set_from_source(&zf->error, zf->src); + return -1; } + + return n; } diff --git a/ePub3/ThirdParty/libzip/zip_fseek.c b/ePub3/ThirdParty/libzip/zip_fseek.c deleted file mode 100644 index b98624fa4..000000000 --- a/ePub3/ThirdParty/libzip/zip_fseek.c +++ /dev/null @@ -1,198 +0,0 @@ -/* - zip_fopen_index.c -- seek to a location within a file in a zip archive - Copyright (C) 1999-2013 Dieter Baron and Thomas Klausner - Original implementation contributed by Jim Dovey - - This file is part of libzip, a library to manipulate ZIP archives. - The authors can be contacted at - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - 3. The names of the authors may not be used to endorse or promote - products derived from this software without specific prior - written permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS - OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include - -#include "zipint.h" - -#if defined(_MSC_VER) -# define strdup _strdup -# define fseeko fseek -# define ftello ftell -# define fileno _fileno -#endif - -static int _zip_fseek_bytes(struct zip_file* zf, off_t abspos, off_t flen); -static int _zip_fseek_comp(struct zip_file* zf, off_t abspos, off_t flen); - -/* helpers for dealing with inline decompression */ -static int _zip_fseek_to_start(struct zip_file* zf); -static int _zip_fseek_by_reading(struct zip_file* zf, size_t toread); - -ZIP_EXTERN int -zip_fseek(struct zip_file *zf, long pos, int whence) -{ - off_t abspos, flen; - - if (!zf) - return -1; - - if (zf->error.zip_err != 0) - return -1; - - if (pos == 0 && whence == ZIP_SEEK_CUR) - return 0; - - flen = zf->za->cdir->entry[zf->file_index].uncomp_size; - - switch (whence) - { - case ZIP_SEEK_CUR: - abspos = zf->file_fpos + pos; - break; - case ZIP_SEEK_SET: - abspos = pos; - break; - case ZIP_SEEK_END: - abspos = flen + pos; - break; - default: - /* incorrect/unspecified 'whence' parameter */ - _zip_error_set(&zf->error, ZIP_ER_INVAL, 0); - return -1; - } - - if (abspos == zf->file_fpos) - return 0; /* no change */ - - if ((zf->flags & ZIP_ZF_DECOMP) == 0) { - // file data is not compressed, or file was opened to read compressed data directly - return _zip_fseek_bytes(zf, abspos, flen); - } - else { - return _zip_fseek_comp(zf, abspos, flen); - } -} - -/* seeking by raw byte amounts - no compression/decompression to handle */ -int _zip_fseek_bytes(struct zip_file* zf, off_t abspos, off_t flen) -{ - /* can't set a negative offset */ - if (abspos < 0) { - _zip_error_set(&zf->error, ZIP_ER_INVAL, 0); - return -1; - } - /* CAN set offset past EOF: keeps offset, sets EOF */ - else if (abspos >= flen) { - zf->flags |= ZIP_ZF_EOF; - zf->bytes_left = 0; - } - /* not at or past EOF? ensure EOF is unset and update bytes_left */ - else { - zf->flags &= ~ZIP_ZF_EOF; - zf->bytes_left = flen - abspos; - } - zf->file_fpos = abspos; - return 0; -} - -/* seeking by raw byte amounts - no compression/decompression to handle */ -int _zip_fseek_comp(struct zip_file* zf, off_t abspos, off_t flen) -{ - if (abspos >= flen) { - // simple case -- set EOF - zf->flags |= ZIP_ZF_EOF; - zf->bytes_left = zf->cbytes_left = 0; - zf->file_fpos = abspos; - return 0; - } - else if (abspos > zf->file_fpos) { - // read & decompress bytes until we reach the right position - return _zip_fseek_by_reading(zf, abspos-zf->file_fpos); - } - - /* at this point, we're definitely moving backwards */ - - /* can't set a negative offset */ - if (abspos < 0) { - _zip_error_set(&zf->error, ZIP_ER_INVAL, 0); - return -1; - } - - if (_zip_fseek_to_start(zf) < 0) - return -1; /* error already set */ - - /* this is a no-op for abspos == 0 */ - return _zip_fseek_by_reading(zf, abspos); -} - -int _zip_fseek_to_start(struct zip_file* zf) -{ - int len, ret; - - zf->flags &= ~ZIP_ZF_EOF; - zf->file_fpos = 0; - zf->bytes_left = zf->za->cdir->entry[zf->file_index].uncomp_size; - zf->cbytes_left = zf->za->cdir->entry[zf->file_index].comp_size; - zf->fpos = _zip_file_get_offset_safe(zf->za, zf->file_index); - - len = _zip_file_fillbuf(zf->buffer, BUFSIZE, zf); - - zf->zstr->zalloc = Z_NULL; - zf->zstr->zfree = Z_NULL; - zf->zstr->opaque = NULL; - zf->zstr->next_in = (Bytef *)zf->buffer; - zf->zstr->avail_in = len; - - /* negative value to tell zlib that there is no header */ - if ((ret=inflateInit2(zf->zstr, -MAX_WBITS)) != Z_OK) { - _zip_error_set(&zf->error, ZIP_ER_ZLIB, ret); - return -1; - } - - return 0; -} - -int _zip_fseek_by_reading(struct zip_file* zf, size_t toread) -{ - char bytes[1024]; - while (toread > 0) { - ssize_t numRead = zip_fread(zf, bytes, (toread < 1024 ? toread : 1024)); - if (numRead < 0 ) - return -1; /* error already set */ - if (numRead == 0) { - /* avoid infinite loops */ - _zip_error_set(&zf->error, ZIP_ER_INCONS, 0); - return -1; - } - - toread -= numRead; - } - - /* zf has been updated for us by zip_fread() already */ - return 0; -} diff --git a/ePub3/ThirdParty/libzip/zip_get_archive_comment.c b/ePub3/ThirdParty/libzip/zip_get_archive_comment.c index 669eb7021..78f8ca09d 100644 --- a/ePub3/ThirdParty/libzip/zip_get_archive_comment.c +++ b/ePub3/ThirdParty/libzip/zip_get_archive_comment.c @@ -1,6 +1,6 @@ /* zip_get_archive_comment.c -- get archive comment - Copyright (C) 2006-2007 Dieter Baron and Thomas Klausner + Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,30 +31,29 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - + +#include #include "zipint.h" - ZIP_EXTERN const char * -zip_get_archive_comment(struct zip *za, int *lenp, int flags) +zip_get_archive_comment(zip_t *za, int *lenp, zip_flags_t flags) { - if ((flags & ZIP_FL_UNCHANGED) - || (za->ch_comment_len == -1)) { - if (za->cdir) { - if (lenp != NULL) - *lenp = za->cdir->comment_len; - return za->cdir->comment; - } - else { - if (lenp != NULL) - *lenp = -1; - return NULL; - } - } - - if (lenp != NULL) - *lenp = za->ch_comment_len; - return za->ch_comment; + zip_string_t *comment; + zip_uint32_t len; + const zip_uint8_t *str; + + if ((flags & ZIP_FL_UNCHANGED) || (za->comment_changes == NULL)) + comment = za->comment_orig; + else + comment = za->comment_changes; + + if ((str=_zip_string_get(comment, &len, flags, &za->error)) == NULL) + return NULL; + + if (lenp) + *lenp = (int)len; + + return (const char *)str; } diff --git a/ePub3/ThirdParty/libzip/zip_get_archive_flag.c b/ePub3/ThirdParty/libzip/zip_get_archive_flag.c index 4733d92b5..bffe10c11 100644 --- a/ePub3/ThirdParty/libzip/zip_get_archive_flag.c +++ b/ePub3/ThirdParty/libzip/zip_get_archive_flag.c @@ -1,6 +1,6 @@ /* zip_get_archive_flag.c -- get archive global flag - Copyright (C) 2008 Dieter Baron and Thomas Klausner + Copyright (C) 2008-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,16 +31,14 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "zipint.h" - ZIP_EXTERN int -zip_get_archive_flag(struct zip *za, int flag, int flags) +zip_get_archive_flag(zip_t *za, zip_flags_t flag, zip_flags_t flags) { - int fl; + unsigned int fl; fl = (flags & ZIP_FL_UNCHANGED) ? za->flags : za->ch_flags; diff --git a/ePub3/ThirdParty/libzip/zip_entry_free.c b/ePub3/ThirdParty/libzip/zip_get_compression_implementation.c similarity index 82% rename from ePub3/ThirdParty/libzip/zip_entry_free.c rename to ePub3/ThirdParty/libzip/zip_get_compression_implementation.c index c50c9434b..c1120d3ea 100644 --- a/ePub3/ThirdParty/libzip/zip_entry_free.c +++ b/ePub3/ThirdParty/libzip/zip_get_compression_implementation.c @@ -1,6 +1,6 @@ /* - zip_entry_free.c -- free struct zip_entry - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + zip_get_compression_implementation.c -- get compression implementation + Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,22 +31,14 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - - -#include #include "zipint.h" - -void -_zip_entry_free(struct zip_entry *ze) +zip_compression_implementation +_zip_get_compression_implementation(zip_int32_t cm) { - free(ze->ch_filename); - ze->ch_filename = NULL; - free(ze->ch_comment); - ze->ch_comment = NULL; - ze->ch_comment_len = -1; - - _zip_unchange_data(ze); + if (cm == ZIP_CM_DEFLATE || ZIP_CM_IS_DEFAULT(cm)) + return zip_source_deflate; + return NULL; } diff --git a/ePub3/ThirdParty/libzip/zip_get_encryption_implementation.c b/ePub3/ThirdParty/libzip/zip_get_encryption_implementation.c new file mode 100644 index 000000000..e2f833b41 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_get_encryption_implementation.c @@ -0,0 +1,44 @@ +/* + zip_get_encryption_implementation.c -- get encryption implementation + Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +zip_encryption_implementation +_zip_get_encryption_implementation(zip_uint16_t em) +{ + if (em == ZIP_EM_TRAD_PKWARE) + return zip_source_pkware; + return NULL; +} diff --git a/ePub3/ThirdParty/libzip/zip_get_file_comment.c b/ePub3/ThirdParty/libzip/zip_get_file_comment.c index adace7247..d5f50bf2a 100644 --- a/ePub3/ThirdParty/libzip/zip_get_file_comment.c +++ b/ePub3/ThirdParty/libzip/zip_get_file_comment.c @@ -1,6 +1,6 @@ /* zip_get_file_comment.c -- get file comment - Copyright (C) 2006-2007 Dieter Baron and Thomas Klausner + Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,28 +31,21 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - +#define _ZIP_COMPILING_DEPRECATED #include "zipint.h" - ZIP_EXTERN const char * -zip_get_file_comment(struct zip *za, int idx, int *lenp, int flags) +zip_get_file_comment(zip_t *za, zip_uint64_t idx, int *lenp, int flags) { - if (idx < 0 || idx >= za->nentry) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); - return NULL; - } + zip_uint32_t len; + const char *s; - if ((flags & ZIP_FL_UNCHANGED) - || (za->entry[idx].ch_comment_len == -1)) { - if (lenp != NULL) - *lenp = za->cdir->entry[idx].comment_len; - return za->cdir->entry[idx].comment; + if ((s=zip_file_get_comment(za, idx, &len, (zip_flags_t)flags)) != NULL) { + if (lenp) + *lenp = (int)len; } - - if (lenp != NULL) - *lenp = za->entry[idx].ch_comment_len; - return za->entry[idx].ch_comment; + + return s; } diff --git a/ePub3/ThirdParty/libzip/zip_get_name.c b/ePub3/ThirdParty/libzip/zip_get_name.c index 8f5050bd2..d29e63658 100644 --- a/ePub3/ThirdParty/libzip/zip_get_name.c +++ b/ePub3/ThirdParty/libzip/zip_get_name.c @@ -1,6 +1,6 @@ /* zip_get_name.c -- get filename for a file in zip file - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,41 +31,30 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - + +#include #include "zipint.h" - ZIP_EXTERN const char * -zip_get_name(struct zip *za, int idx, int flags) +zip_get_name(zip_t *za, zip_uint64_t idx, zip_flags_t flags) { return _zip_get_name(za, idx, flags, &za->error); } - const char * -_zip_get_name(struct zip *za, int idx, int flags, struct zip_error *error) +_zip_get_name(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error) { - if (idx < 0 || idx >= za->nentry) { - _zip_error_set(error, ZIP_ER_INVAL, 0); - return NULL; - } + zip_dirent_t *de; + const zip_uint8_t *str; - if ((flags & ZIP_FL_UNCHANGED) == 0) { - if (za->entry[idx].state == ZIP_ST_DELETED) { - _zip_error_set(error, ZIP_ER_DELETED, 0); - return NULL; - } - if (za->entry[idx].ch_filename) - return za->entry[idx].ch_filename; - } + if ((de=_zip_get_dirent(za, idx, flags, error)) == NULL) + return NULL; - if (za->cdir == NULL || idx >= za->cdir->nentry) { - _zip_error_set(error, ZIP_ER_INVAL, 0); + if ((str=_zip_string_get(de->filename, NULL, flags, error)) == NULL) return NULL; - } - - return za->cdir->entry[idx].filename; + + return (const char *)str; } diff --git a/ePub3/ThirdParty/libzip/zip_get_num_entries.c b/ePub3/ThirdParty/libzip/zip_get_num_entries.c new file mode 100644 index 000000000..c8644a4c5 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_get_num_entries.c @@ -0,0 +1,53 @@ +/* + zip_get_num_entries.c -- get number of entries in archive + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +ZIP_EXTERN zip_int64_t +zip_get_num_entries(zip_t *za, zip_flags_t flags) +{ + zip_uint64_t n; + + if (za == NULL) + return -1; + + if (flags & ZIP_FL_UNCHANGED) { + n = za->nentry; + while (n>0 && za->entry[n-1].orig == NULL) + --n; + return (zip_int64_t)n; + } + return (zip_int64_t)za->nentry; +} diff --git a/ePub3/ThirdParty/libzip/zip_get_num_files.c b/ePub3/ThirdParty/libzip/zip_get_num_files.c index 1d9baa3d6..cf96353fc 100644 --- a/ePub3/ThirdParty/libzip/zip_get_num_files.c +++ b/ePub3/ThirdParty/libzip/zip_get_num_files.c @@ -1,6 +1,6 @@ /* zip_get_num_files.c -- get number of files in archive - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,17 +31,22 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - +#define _ZIP_COMPILING_DEPRECATED #include "zipint.h" +#include - ZIP_EXTERN int -zip_get_num_files(struct zip *za) +zip_get_num_files(zip_t *za) { if (za == NULL) return -1; - return za->nentry; + if (za->nentry > INT_MAX) { + zip_error_set(&za->error, ZIP_ER_OPNOTSUPP, 0); + return -1; + } + + return (int)za->nentry; } diff --git a/ePub3/ThirdParty/libzip/zip_io_util.c b/ePub3/ThirdParty/libzip/zip_io_util.c new file mode 100644 index 000000000..4a6bc1ddc --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_io_util.c @@ -0,0 +1,139 @@ +/* + zip_io_util.c -- I/O helper functions + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include "zipint.h" + +int +_zip_read(zip_source_t *src, zip_uint8_t *b, zip_uint64_t length, zip_error_t *error) +{ + zip_int64_t n; + + if (length > ZIP_INT64_MAX) { + zip_error_set(error, ZIP_ER_INTERNAL, 0); + return -1; + } + + if ((n = zip_source_read(src, b, length)) < 0) { + _zip_error_set_from_source(error, src); + return -1; + } + + if (n < (zip_int64_t)length) { + zip_error_set(error, ZIP_ER_EOF, 0); + return -1; + } + + return 0; +} + + +zip_uint8_t * +_zip_read_data(zip_buffer_t *buffer, zip_source_t *src, size_t length, bool nulp, zip_error_t *error) +{ + zip_uint8_t *r; + + if (length == 0 && !nulp) { + return NULL; + } + + r = (zip_uint8_t *)malloc(length + (nulp ? 1 : 0)); + if (!r) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + return NULL; + } + + if (buffer) { + zip_uint8_t *data = _zip_buffer_get(buffer, length); + + if (data == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + free(r); + return NULL; + } + memcpy(r, data, length); + } + else { + if (_zip_read(src, r, length, error) < 0) { + free(r); + return NULL; + } + } + + if (nulp) { + zip_uint8_t *o; + /* replace any in-string NUL characters with spaces */ + r[length] = 0; + for (o=r; osrc, data, length)) < 0) { + _zip_error_set_from_source(&za->error, za->src); + return -1; + } + if ((zip_uint64_t)n != length) { + zip_error_set(&za->error, ZIP_ER_WRITE, EINTR); + return -1; + } + + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_memdup.c b/ePub3/ThirdParty/libzip/zip_memdup.c index 641125ed2..cc6d767d9 100644 --- a/ePub3/ThirdParty/libzip/zip_memdup.c +++ b/ePub3/ThirdParty/libzip/zip_memdup.c @@ -1,6 +1,6 @@ /* zip_memdup.c -- internal zip function, "strdup" with len - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -36,16 +36,18 @@ #include "zipint.h" - void * -_zip_memdup(const void *mem, size_t len, struct zip_error *error) +_zip_memdup(const void *mem, size_t len, zip_error_t *error) { void *ret; + if (len == 0) + return NULL; + ret = malloc(len); if (!ret) { - _zip_error_set(error, ZIP_ER_MEMORY, 0); + zip_error_set(error, ZIP_ER_MEMORY, 0); return NULL; } diff --git a/ePub3/ThirdParty/libzip/zip_name_locate.c b/ePub3/ThirdParty/libzip/zip_name_locate.c index 02472b33e..820ea0ca7 100644 --- a/ePub3/ThirdParty/libzip/zip_name_locate.c +++ b/ePub3/ThirdParty/libzip/zip_name_locate.c @@ -1,6 +1,6 @@ /* zip_name_locate.c -- get index by name - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,53 +31,43 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include +#ifdef HAVE_STRINGS_H +#include +#endif #include "zipint.h" -#if defined(_MSC_VER) -# define strdup _strdup -# define fseeko fseek -# define ftello ftell -# define fileno _fileno -# define strcasecmp _stricmp -#endif - - -ZIP_EXTERN int -zip_name_locate(struct zip *za, const char *fname, int flags) +ZIP_EXTERN zip_int64_t +zip_name_locate(zip_t *za, const char *fname, zip_flags_t flags) { return _zip_name_locate(za, fname, flags, &za->error); } - -int -_zip_name_locate(struct zip *za, const char *fname, int flags, - struct zip_error *error) +zip_int64_t +_zip_name_locate(zip_t *za, const char *fname, zip_flags_t flags, zip_error_t *error) { int (*cmp)(const char *, const char *); const char *fn, *p; - int i, n; + zip_uint64_t i; + + if (za == NULL) + return -1; if (fname == NULL) { - _zip_error_set(error, ZIP_ER_INVAL, 0); + zip_error_set(error, ZIP_ER_INVAL, 0); return -1; } - + cmp = (flags & ZIP_FL_NOCASE) ? strcasecmp : strcmp; - n = (flags & ZIP_FL_UNCHANGED) ? za->cdir->nentry : za->nentry; - for (i=0; icdir->entry[i].filename; - else - fn = _zip_get_name(za, i, flags, error); + for (i=0; inentry; i++) { + fn = _zip_get_name(za, i, flags, error); - /* newly added (partially filled) entry */ + /* newly added (partially filled) entry or error */ if (fn == NULL) continue; @@ -87,10 +77,12 @@ _zip_name_locate(struct zip *za, const char *fname, int flags, fn = p+1; } - if (cmp(fname, fn) == 0) - return i; + if (cmp(fname, fn) == 0) { + _zip_error_clear(error); + return (zip_int64_t)i; + } } - _zip_error_set(error, ZIP_ER_NOENT, 0); + zip_error_set(error, ZIP_ER_NOENT, 0); return -1; } diff --git a/ePub3/ThirdParty/libzip/zip_new.c b/ePub3/ThirdParty/libzip/zip_new.c index 3e8ccee64..d54a247c2 100644 --- a/ePub3/ThirdParty/libzip/zip_new.c +++ b/ePub3/ThirdParty/libzip/zip_new.c @@ -1,6 +1,6 @@ /* zip_new.c -- create and init struct zip - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,40 +31,39 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include "zipint.h" - /* _zip_new: creates a new zipfile struct, and sets the contents to zero; returns the new struct. */ -struct zip * -_zip_new(struct zip_error *error) +zip_t * +_zip_new(zip_error_t *error) { - struct zip *za; + zip_t *za; - za = (struct zip *)malloc(sizeof(struct zip)); + za = (zip_t *)malloc(sizeof(struct zip)); if (!za) { - _zip_error_set(error, ZIP_ER_MEMORY, 0); + zip_error_set(error, ZIP_ER_MEMORY, 0); return NULL; } - za->zn = NULL; - za->zp = NULL; - _zip_error_init(&za->error); - za->cdir = NULL; - za->ch_comment = NULL; - za->ch_comment_len = -1; + za->src = NULL; + za->open_flags = 0; + zip_error_init(&za->error); + za->flags = za->ch_flags = 0; + za->default_password = NULL; + za->comment_orig = za->comment_changes = NULL; + za->comment_changed = 0; za->nentry = za->nentry_alloc = 0; za->entry = NULL; - za->nfile = za->nfile_alloc = 0; - za->file = NULL; - za->flags = za->ch_flags = 0; + za->nopen_source = za->nopen_source_alloc = 0; + za->open_source = NULL; + za->tempdir = NULL; return za; } diff --git a/ePub3/ThirdParty/libzip/zip_open.c b/ePub3/ThirdParty/libzip/zip_open.c index cbf8e8e93..fb9c566cb 100644 --- a/ePub3/ThirdParty/libzip/zip_open.c +++ b/ePub3/ThirdParty/libzip/zip_open.c @@ -1,6 +1,6 @@ /* - zip_open.c -- open zip archive - Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner + zip_open.c -- open zip archive by name + Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,7 +31,6 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include @@ -42,111 +41,211 @@ #include "zipint.h" -#if defined(_MSC_VER) -# define strdup _strdup -# define fseeko fseek -# define ftello ftell -# define fileno _fileno -#endif +typedef enum { + EXISTS_ERROR = -1, + EXISTS_NOT = 0, + EXISTS_EMPTY, + EXISTS_NONEMPTY, +} exists_t; +static zip_t *_zip_allocate_new(zip_source_t *src, unsigned int flags, zip_error_t *error); +static zip_int64_t _zip_checkcons(zip_t *za, zip_cdir_t *cdir, zip_error_t *error); +static zip_cdir_t *_zip_find_central_dir(zip_t *za, zip_uint64_t len); +static exists_t _zip_file_exists(zip_source_t *src, zip_error_t *error); +static int _zip_headercomp(const zip_dirent_t *, const zip_dirent_t *); +static unsigned char *_zip_memmem(const unsigned char *, size_t, const unsigned char *, size_t); +static zip_cdir_t *_zip_read_cdir(zip_t *za, zip_buffer_t *buffer, zip_uint64_t buf_offset, zip_error_t *error); +static zip_cdir_t *_zip_read_eocd(zip_buffer_t *buffer, zip_uint64_t buf_offset, unsigned int flags, zip_error_t *error); +static zip_cdir_t *_zip_read_eocd64(zip_source_t *src, zip_buffer_t *buffer, zip_uint64_t buf_offset, unsigned int flags, zip_error_t *error); + + +ZIP_EXTERN zip_t * +zip_open(const char *fn, int _flags, int *zep) +{ + zip_t *za; + zip_source_t *src; + struct zip_error error; + + zip_error_init(&error); + if ((src = zip_source_file_create(fn, 0, -1, &error)) == NULL) { + _zip_set_open_error(zep, &error, 0); + zip_error_fini(&error); + return NULL; + } + + if ((za = zip_open_from_source(src, _flags, &error)) == NULL) { + zip_source_free(src); + _zip_set_open_error(zep, &error, 0); + zip_error_fini(&error); + return NULL; + } + + zip_error_fini(&error); + return za; +} + -static void set_error(int *, struct zip_error *, int); -static struct zip *_zip_allocate_new(const char *, int *); -static int _zip_checkcons(FILE *, struct zip_cdir *, struct zip_error *); -static void _zip_check_torrentzip(struct zip *); -static struct zip_cdir *_zip_find_central_dir(FILE *, int, int *, off_t); -static int _zip_file_exists(const char *, int, int *); -static int _zip_headercomp(struct zip_dirent *, int, - struct zip_dirent *, int); -static unsigned char *_zip_memmem(const unsigned char *, int, - const unsigned char *, int); -static struct zip_cdir *_zip_readcdir(FILE *, unsigned char *, unsigned char *, - int, int, struct zip_error *); - - - -ZIP_EXTERN struct zip * -zip_open(const char *fn, int flags, int *zep) +ZIP_EXTERN zip_t * +zip_open_from_source(zip_source_t *src, int _flags, zip_error_t *error) { - FILE *fp; - struct zip *za; - struct zip_cdir *cdir; - int i; - off_t len; + static zip_int64_t needed_support_read = -1; + static zip_int64_t needed_support_write = -1; - switch (_zip_file_exists(fn, flags, zep)) { - case -1: - return NULL; - case 0: - return _zip_allocate_new(fn, zep); - default: - break; + unsigned int flags; + zip_int64_t supported; + exists_t exists; + + if (_flags < 0 || src == NULL) { + zip_error_set(error, ZIP_ER_INVAL, 0); + return NULL; + } + flags = (unsigned int)_flags; + + supported = zip_source_supports(src); + if (needed_support_read == -1) { + needed_support_read = zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_SEEK, ZIP_SOURCE_TELL, ZIP_SOURCE_STAT, -1); + needed_support_write = zip_source_make_command_bitmap(ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_REMOVE, -1); + } + if ((supported & needed_support_read) != needed_support_read) { + zip_error_set(error, ZIP_ER_OPNOTSUPP, 0); + return NULL; + } + if ((supported & needed_support_write) != needed_support_write) { + flags |= ZIP_RDONLY; } - if ((fp=fopen(fn, "rb")) == NULL) { - set_error(zep, NULL, ZIP_ER_OPEN); + if ((flags & (ZIP_RDONLY|ZIP_TRUNCATE)) == (ZIP_RDONLY|ZIP_TRUNCATE)) { + zip_error_set(error, ZIP_ER_RDONLY, 0); return NULL; } - fseeko(fp, 0, SEEK_END); - len = ftello(fp); + exists = _zip_file_exists(src, error); + switch (exists) { + case EXISTS_ERROR: + return NULL; - /* treat empty files as empty archives */ - if (len == 0) { - if ((za=_zip_allocate_new(fn, zep)) == NULL) - fclose(fp); - else - za->zp = fp; + case EXISTS_NOT: + if ((flags & ZIP_CREATE) == 0) { + zip_error_set(error, ZIP_ER_NOENT, 0); + return NULL; + } + return _zip_allocate_new(src, flags, error); + + default: { + zip_t *za; + if (flags & ZIP_EXCL) { + zip_error_set(error, ZIP_ER_EXISTS, 0); + return NULL; + } + if (zip_source_open(src) < 0) { + _zip_error_set_from_source(error, src); + return NULL; + } + + if (flags & ZIP_TRUNCATE) { + za = _zip_allocate_new(src, flags, error); + } + else { + /* ZIP_CREATE gets ignored if file exists and not ZIP_EXCL, just like open() */ + za = _zip_open(src, flags, error); + } + + if (za == NULL) { + zip_source_close(src); + return NULL; + } return za; } + } +} - cdir = _zip_find_central_dir(fp, flags, zep, len); - if (cdir == NULL) { - fclose(fp); - return NULL; +ZIP_EXTERN int +zip_archive_set_tempdir(zip_t *za, const char *tempdir) +{ + char *new_tempdir; + + if (tempdir) { + if ((new_tempdir = strdup(tempdir)) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, errno); + return -1; + } } + else + new_tempdir = NULL; + + free(za->tempdir); + za->tempdir = new_tempdir; + + return 0; +} - if ((za=_zip_allocate_new(fn, zep)) == NULL) { - _zip_cdir_free(cdir); - fclose(fp); +zip_t * +_zip_open(zip_source_t *src, unsigned int flags, zip_error_t *error) +{ + zip_t *za; + zip_cdir_t *cdir; + struct zip_stat st; + zip_uint64_t len; + + zip_stat_init(&st); + if (zip_source_stat(src, &st) < 0) { + _zip_error_set_from_source(error, src); return NULL; } + if ((st.valid & ZIP_STAT_SIZE) == 0) { + zip_error_set(error, ZIP_ER_SEEK, EOPNOTSUPP); + return NULL; + } + len = st.size; + + /* treat empty files as empty archives */ + if (len == 0) { + if ((za=_zip_allocate_new(src, flags, error)) == NULL) { + zip_source_free(src); + return NULL; + } - za->cdir = cdir; - za->zp = fp; + return za; + } - if ((za->entry=(struct zip_entry *)malloc(sizeof(*(za->entry)) - * cdir->nentry)) == NULL) { - set_error(zep, NULL, ZIP_ER_MEMORY); - _zip_free(za); + if ((za=_zip_allocate_new(src, flags, error)) == NULL) { + return NULL; + } + + if ((cdir = _zip_find_central_dir(za, len)) == NULL) { + _zip_error_copy(error, &za->error); + /* keep src so discard does not get rid of it */ + zip_source_keep(src); + zip_discard(za); return NULL; } - for (i=0; inentry; i++) - _zip_entry_new(za); - _zip_check_torrentzip(za); + za->entry = cdir->entry; + za->nentry = cdir->nentry; + za->nentry_alloc = cdir->nentry_alloc; + za->comment_orig = cdir->comment; + za->ch_flags = za->flags; + free(cdir); + return za; } - -static void -set_error(int *zep, struct zip_error *err, int ze) +void +_zip_set_open_error(int *zep, const zip_error_t *err, int ze) { - int se; - if (err) { - _zip_error_get(err, &ze, &se); - if (zip_error_get_sys_type(ze) == ZIP_ET_SYS) - errno = se; + ze = zip_error_code_zip(err); + if (zip_error_system_type(err) == ZIP_ET_SYS) { + errno = zip_error_code_system(err); + } } if (zep) *zep = ze; } - /* _zip_readcdir: tries to find a valid end-of-central-directory at the beginning of @@ -154,113 +253,157 @@ set_error(int *zep, struct zip_error *err, int ze) Returns a struct zip_cdir which contains the central directory entries, or NULL if unsuccessful. */ -static struct zip_cdir * -_zip_readcdir(FILE *fp, unsigned char *buf, unsigned char *eocd, int buflen, - int flags, struct zip_error *error) +static zip_cdir_t * +_zip_read_cdir(zip_t *za, zip_buffer_t *buffer, zip_uint64_t buf_offset, zip_error_t *error) { - struct zip_cdir *cd; - unsigned char *cdp, **bufp; - int i, nentry; - ssize_t comlen; - unsigned int left; - - comlen = (ssize_t)(buf + (size_t)buflen - eocd - (size_t)EOCDLEN); - if (comlen < 0) { + zip_cdir_t *cd; + zip_uint16_t comment_len; + zip_uint64_t i, left; + zip_uint64_t eocd_offset = _zip_buffer_offset(buffer); + zip_buffer_t *cd_buffer; + + if (_zip_buffer_left(buffer) < EOCDLEN) { /* not enough bytes left for comment */ - _zip_error_set(error, ZIP_ER_NOZIP, 0); + zip_error_set(error, ZIP_ER_NOZIP, 0); return NULL; } - + /* check for end-of-central-dir magic */ - if (memcmp(eocd, EOCD_MAGIC, 4) != 0) { - _zip_error_set(error, ZIP_ER_NOZIP, 0); + if (memcmp(_zip_buffer_get(buffer, 4), EOCD_MAGIC, 4) != 0) { + zip_error_set(error, ZIP_ER_NOZIP, 0); return NULL; } - if (memcmp(eocd+4, "\0\0\0\0", 4) != 0) { - _zip_error_set(error, ZIP_ER_MULTIDISK, 0); + if (_zip_buffer_get_32(buffer) != 0) { + zip_error_set(error, ZIP_ER_MULTIDISK, 0); return NULL; } - cdp = eocd + 8; - /* number of cdir-entries on this disk */ - i = _zip_read2(&cdp); - /* number of cdir-entries */ - nentry = _zip_read2(&cdp); + if (eocd_offset >= EOCD64LOCLEN && memcmp(_zip_buffer_data(buffer) + eocd_offset - EOCD64LOCLEN, EOCD64LOC_MAGIC, 4) == 0) { + _zip_buffer_set_offset(buffer, eocd_offset - EOCD64LOCLEN); + cd = _zip_read_eocd64(za->src, buffer, buf_offset, za->flags, error); + } + else { + _zip_buffer_set_offset(buffer, eocd_offset); + cd = _zip_read_eocd(buffer, buf_offset, za->flags, error); + } - if ((cd=_zip_cdir_new(nentry, error)) == NULL) + if (cd == NULL) return NULL; - cd->size = _zip_read4(&cdp); - cd->offset = _zip_read4(&cdp); - cd->comment = NULL; - cd->comment_len = _zip_read2(&cdp); + _zip_buffer_set_offset(buffer, eocd_offset + 20); + comment_len = _zip_buffer_get_16(buffer); - if ((comlen < cd->comment_len) || (cd->nentry != i)) { - _zip_error_set(error, ZIP_ER_NOZIP, 0); - free(cd); - return NULL; - } - if ((flags & ZIP_CHECKCONS) && comlen != cd->comment_len) { - _zip_error_set(error, ZIP_ER_INCONS, 0); - free(cd); + if (cd->offset + cd->size > buf_offset + eocd_offset) { + /* cdir spans past EOCD record */ + zip_error_set(error, ZIP_ER_INCONS, 0); + _zip_cdir_free(cd); return NULL; } - if (cd->comment_len) { - if ((cd->comment=(char *)_zip_memdup(eocd+EOCDLEN, - cd->comment_len, error)) - == NULL) { - free(cd); - return NULL; - } + if (comment_len || (za->open_flags & ZIP_CHECKCONS)) { + zip_uint64_t tail_len; + + _zip_buffer_set_offset(buffer, eocd_offset + EOCDLEN); + tail_len = _zip_buffer_left(buffer); + + if (tail_len < comment_len || ((za->open_flags & ZIP_CHECKCONS) && tail_len != comment_len)) { + zip_error_set(error, ZIP_ER_INCONS, 0); + _zip_cdir_free(cd); + return NULL; + } + + if (comment_len) { + if ((cd->comment=_zip_string_new(_zip_buffer_get(buffer, comment_len), comment_len, ZIP_FL_ENC_GUESS, error)) == NULL) { + _zip_cdir_free(cd); + return NULL; + } + } } - if (cd->size < (unsigned int)(eocd-buf)) { + if (cd->offset >= buf_offset) { + zip_uint8_t *data; /* if buffer already read in, use it */ - cdp = eocd - cd->size; - bufp = &cdp; + _zip_buffer_set_offset(buffer, cd->offset - buf_offset); + + if ((data = _zip_buffer_get(buffer, cd->size)) == NULL) { + zip_error_set(error, ZIP_ER_INCONS, 0); + _zip_cdir_free(cd); + return NULL; + } + if ((cd_buffer = _zip_buffer_new(data, cd->size)) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + _zip_cdir_free(cd); + return NULL; + } } else { - /* go to start of cdir and read it entry by entry */ - bufp = NULL; - clearerr(fp); - fseeko(fp, cd->offset, SEEK_SET); - /* possible consistency check: cd->offset = - len-(cd->size+cd->comment_len+EOCDLEN) ? */ - if (ferror(fp) || ((unsigned long)ftello(fp) != cd->offset)) { - /* seek error or offset of cdir wrong */ - if (ferror(fp)) - _zip_error_set(error, ZIP_ER_SEEK, errno); - else - _zip_error_set(error, ZIP_ER_NOZIP, 0); - free(cd); + cd_buffer = NULL; + + if (zip_source_seek(za->src, (zip_int64_t)cd->offset, SEEK_SET) < 0) { + _zip_error_set_from_source(error, za->src); + _zip_cdir_free(cd); + return NULL; + } + + /* possible consistency check: cd->offset = len-(cd->size+cd->comment_len+EOCDLEN) ? */ + if (zip_source_tell(za->src) != (zip_int64_t)cd->offset) { + zip_error_set(error, ZIP_ER_NOZIP, 0); + _zip_cdir_free(cd); return NULL; } } - left = cd->size; + left = (zip_uint64_t)cd->size; i=0; - do { - if (i == cd->nentry && left > 0) { - /* Infozip extension for more than 64k entries: - nentries wraps around, size indicates correct EOCD */ - _zip_cdir_grow(cd, cd->nentry+0x10000, error); - } - - if ((_zip_dirent_read(cd->entry+i, fp, bufp, &left, 0, error)) < 0) { - cd->nentry = i; + while (inentry && left > 0) { + zip_int64_t entry_size; + if ((cd->entry[i].orig=_zip_dirent_new()) == NULL || (entry_size = _zip_dirent_read(cd->entry[i].orig, za->src, cd_buffer, false, error)) < 0) { _zip_cdir_free(cd); + _zip_buffer_free(cd_buffer); return NULL; } i++; - - } while (inentry); + left -= (zip_uint64_t)entry_size; + } + + if (i != cd->nentry) { + zip_error_set(error, ZIP_ER_INCONS, 0); + _zip_buffer_free(cd_buffer); + _zip_cdir_free(cd); + return NULL; + } + if (za->open_flags & ZIP_CHECKCONS) { + bool ok; + + if (cd_buffer) { + ok = _zip_buffer_eof(cd_buffer); + } + else { + zip_int64_t offset = zip_source_tell(za->src); + + if (offset < 0) { + _zip_error_set_from_source(error, za->src); + _zip_buffer_free(cd_buffer); + _zip_cdir_free(cd); + return NULL; + } + ok = ((zip_uint64_t)offset == cd->offset + cd->size); + } + + if (!ok) { + zip_error_set(error, ZIP_ER_INCONS, 0); + _zip_buffer_free(cd_buffer); + _zip_cdir_free(cd); + return NULL; + } + } + + _zip_buffer_free(cd_buffer); return cd; } - /* _zip_checkcons: Checks the consistency of the central directory by comparing central @@ -268,297 +411,228 @@ _zip_readcdir(FILE *fp, unsigned char *buf, unsigned char *eocd, int buflen, file and header offsets. Returns -1 if not plausible, else the difference between the lowest and the highest fileposition reached */ -static int -_zip_checkcons(FILE *fp, struct zip_cdir *cd, struct zip_error *error) +static zip_int64_t +_zip_checkcons(zip_t *za, zip_cdir_t *cd, zip_error_t *error) { - int i; - unsigned int min, max, j; + zip_uint64_t i; + zip_uint64_t min, max, j; struct zip_dirent temp; + _zip_dirent_init(&temp); if (cd->nentry) { - max = cd->entry[0].offset; - min = cd->entry[0].offset; + max = cd->entry[0].orig->offset; + min = cd->entry[0].orig->offset; } else min = max = 0; for (i=0; inentry; i++) { - if (cd->entry[i].offset < min) - min = cd->entry[i].offset; - if (min > cd->offset) { - _zip_error_set(error, ZIP_ER_NOZIP, 0); + if (cd->entry[i].orig->offset < min) + min = cd->entry[i].orig->offset; + if (min > (zip_uint64_t)cd->offset) { + zip_error_set(error, ZIP_ER_NOZIP, 0); return -1; } - j = cd->entry[i].offset + cd->entry[i].comp_size - + cd->entry[i].filename_len + LENTRYSIZE; + j = cd->entry[i].orig->offset + cd->entry[i].orig->comp_size + + _zip_string_length(cd->entry[i].orig->filename) + LENTRYSIZE; if (j > max) max = j; - if (max > cd->offset) { - _zip_error_set(error, ZIP_ER_NOZIP, 0); + if (max > (zip_uint64_t)cd->offset) { + zip_error_set(error, ZIP_ER_NOZIP, 0); return -1; } - if (fseeko(fp, cd->entry[i].offset, SEEK_SET) != 0) { - _zip_error_set(error, ZIP_ER_SEEK, 0); - return -1; + if (zip_source_seek(za->src, (zip_int64_t)cd->entry[i].orig->offset, SEEK_SET) < 0) { + _zip_error_set_from_source(error, za->src); + return -1; } - if (_zip_dirent_read(&temp, fp, NULL, NULL, 1, error) == -1) + if (_zip_dirent_read(&temp, za->src, NULL, true, error) == -1) { + _zip_dirent_finalize(&temp); return -1; + } - if (_zip_headercomp(cd->entry+i, 0, &temp, 1) != 0) { - _zip_error_set(error, ZIP_ER_INCONS, 0); + if (_zip_headercomp(cd->entry[i].orig, &temp) != 0) { + zip_error_set(error, ZIP_ER_INCONS, 0); _zip_dirent_finalize(&temp); return -1; } + + cd->entry[i].orig->extra_fields = _zip_ef_merge(cd->entry[i].orig->extra_fields, temp.extra_fields); + cd->entry[i].orig->local_extra_fields_read = 1; + temp.extra_fields = NULL; + _zip_dirent_finalize(&temp); } - return max - min; -} - - - -/* _zip_check_torrentzip: - check wether ZA has a valid TORRENTZIP comment, i.e. is torrentzipped */ - -static void -_zip_check_torrentzip(struct zip *za) -{ - uLong crc_got, crc_should; - char buf[8+1]; - char *end; - - if (za->zp == NULL || za->cdir == NULL) - return; - - if (za->cdir->comment_len != TORRENT_SIG_LEN+8 - || strncmp(za->cdir->comment, TORRENT_SIG, TORRENT_SIG_LEN) != 0) - return; - - memcpy(buf, za->cdir->comment+TORRENT_SIG_LEN, 8); - buf[8] = '\0'; - errno = 0; - crc_should = strtoul(buf, &end, 16); - if ((crc_should == UINT_MAX && errno != 0) || (end && *end)) - return; - - if (_zip_filerange_crc(za->zp, za->cdir->offset, za->cdir->size, - &crc_got, NULL) < 0) - return; - - if (crc_got == crc_should) - za->flags |= ZIP_AFL_TORRENT; + return (max-min) < ZIP_INT64_MAX ? (zip_int64_t)(max-min) : ZIP_INT64_MAX; } - - /* _zip_headercomp: - compares two headers h1 and h2; if they are local headers, set - local1p or local2p respectively to 1, else 0. Return 0 if they - are identical, -1 if not. */ + compares a central directory entry and a local file header + Return 0 if they are consistent, -1 if not. */ static int -_zip_headercomp(struct zip_dirent *h1, int local1p, struct zip_dirent *h2, - int local2p) +_zip_headercomp(const zip_dirent_t *central, const zip_dirent_t *local) { - if ((h1->version_needed != h2->version_needed) + if ((central->version_needed != local->version_needed) #if 0 /* some zip-files have different values in local and global headers for the bitflags */ - || (h1->bitflags != h2->bitflags) + || (central->bitflags != local->bitflags) #endif - || (h1->comp_method != h2->comp_method) - || (h1->last_mod != h2->last_mod) - || (h1->filename_len != h2->filename_len) - || !h1->filename || !h2->filename - || strcmp(h1->filename, h2->filename)) + || (central->comp_method != local->comp_method) + || (central->last_mod != local->last_mod) + || !_zip_string_equal(central->filename, local->filename)) return -1; - /* check that CRC and sizes are zero if data descriptor is used */ - if ((h1->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) && local1p - && (h1->crc != 0 - || h1->comp_size != 0 - || h1->uncomp_size != 0)) - return -1; - if ((h2->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) && local2p - && (h2->crc != 0 - || h2->comp_size != 0 - || h2->uncomp_size != 0)) - return -1; - - /* check that CRC and sizes are equal if no data descriptor is used */ - if (((h1->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) == 0 || local1p == 0) - && ((h2->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) == 0 || local2p == 0)) { - if ((h1->crc != h2->crc) - || (h1->comp_size != h2->comp_size) - || (h1->uncomp_size != h2->uncomp_size)) + if ((central->crc != local->crc) || (central->comp_size != local->comp_size) + || (central->uncomp_size != local->uncomp_size)) { + /* InfoZip stores valid values in local header even when data descriptor is used. + This is in violation of the appnote. */ + if (((local->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) == 0 + || local->crc != 0 || local->comp_size != 0 || local->uncomp_size != 0)) return -1; } - - if ((local1p == local2p) - && ((h1->extrafield_len != h2->extrafield_len) - || (h1->extrafield_len && h2->extrafield - && memcmp(h1->extrafield, h2->extrafield, - h1->extrafield_len)))) - return -1; - - /* if either is local, nothing more to check */ - if (local1p || local2p) - return 0; - - if ((h1->version_madeby != h2->version_madeby) - || (h1->disk_number != h2->disk_number) - || (h1->int_attrib != h2->int_attrib) - || (h1->ext_attrib != h2->ext_attrib) - || (h1->offset != h2->offset) - || (h1->comment_len != h2->comment_len) - || (h1->comment_len && h2->comment - && memcmp(h1->comment, h2->comment, h1->comment_len))) - return -1; return 0; } - -static struct zip * -_zip_allocate_new(const char *fn, int *zep) +static zip_t * +_zip_allocate_new(zip_source_t *src, unsigned int flags, zip_error_t *error) { - struct zip *za; - struct zip_error error; + zip_t *za; - if ((za=_zip_new(&error)) == NULL) { - set_error(zep, &error, 0); + if ((za = _zip_new(error)) == NULL) { return NULL; } - - za->zn = strdup(fn); - if (!za->zn) { - _zip_free(za); - set_error(zep, NULL, ZIP_ER_MEMORY); - return NULL; + + za->src = src; + za->open_flags = flags; + if (flags & ZIP_RDONLY) { + za->flags |= ZIP_AFL_RDONLY; + za->ch_flags |= ZIP_AFL_RDONLY; } return za; } - -static int -_zip_file_exists(const char *fn, int flags, int *zep) +/* + * tests for file existence + */ +static exists_t +_zip_file_exists(zip_source_t *src, zip_error_t *error) { - struct stat st; + struct zip_stat st; - if (fn == NULL) { - set_error(zep, NULL, ZIP_ER_INVAL); - return -1; - } - - if (stat(fn, &st) != 0) { - if (flags & ZIP_CREATE) - return 0; - else { - set_error(zep, NULL, ZIP_ER_OPEN); - return -1; + zip_stat_init(&st); + if (zip_source_stat(src, &st) != 0) { + zip_error_t *src_error = zip_source_error(src); + if (zip_error_code_zip(src_error) == ZIP_ER_READ && zip_error_code_system(src_error) == ENOENT) { + return EXISTS_NOT; } + _zip_error_copy(error, src_error); + return EXISTS_ERROR; } - else if ((flags & ZIP_EXCL)) { - set_error(zep, NULL, ZIP_ER_EXISTS); - return -1; - } - /* ZIP_CREATE gets ignored if file exists and not ZIP_EXCL, - just like open() */ - return 1; + return (st.valid & ZIP_STAT_SIZE) && st.size == 0 ? EXISTS_EMPTY : EXISTS_NONEMPTY; } - -static struct zip_cdir * -_zip_find_central_dir(FILE *fp, int flags, int *zep, off_t len) +static zip_cdir_t * +_zip_find_central_dir(zip_t *za, zip_uint64_t len) { - struct zip_cdir *cdir, *cdirnew; - unsigned char *buf, *match; - int a, best, i; - size_t buflen; - struct zip_error zerr; - - i = fseeko(fp, -(len < CDBUFSIZE ? len : CDBUFSIZE), SEEK_END); - if (i == -1 && errno != EFBIG) { - /* seek before start of file on my machine */ - set_error(zep, NULL, ZIP_ER_SEEK); - return NULL; + zip_cdir_t *cdir, *cdirnew; + zip_uint8_t *match; + zip_int64_t buf_offset; + zip_uint64_t buflen; + zip_int64_t a; + zip_int64_t best; + zip_error_t error; + zip_buffer_t *buffer; + + if (len < EOCDLEN) { + zip_error_set(&za->error, ZIP_ER_NOZIP, 0); + return NULL; } - /* 64k is too much for stack */ - if ((buf=(unsigned char *)malloc(CDBUFSIZE)) == NULL) { - set_error(zep, NULL, ZIP_ER_MEMORY); - return NULL; + buflen = (len < CDBUFSIZE ? len : CDBUFSIZE); + if (zip_source_seek(za->src, -(zip_int64_t)buflen, SEEK_END) < 0) { + zip_error_t *src_error = zip_source_error(za->src); + if (zip_error_code_zip(src_error) != ZIP_ER_SEEK || zip_error_code_system(src_error) != EFBIG) { + /* seek before start of file on my machine */ + _zip_error_copy(&za->error, src_error); + return NULL; + } } - - clearerr(fp); - buflen = (int)fread(buf, 1, CDBUFSIZE, fp); - - if (ferror(fp)) { - set_error(zep, NULL, ZIP_ER_READ); - free(buf); - return NULL; + if ((buf_offset = zip_source_tell(za->src)) < 0) { + _zip_error_set_from_source(&za->error, za->src); + return NULL; } + if ((buffer = _zip_buffer_new_from_source(za->src, buflen, NULL, &za->error)) == NULL) { + return NULL; + } + best = -1; cdir = NULL; - match = buf; - _zip_error_set(&zerr, ZIP_ER_NOZIP, 0); - - while ((match=_zip_memmem(match, (int)(buflen-(match-buf)-18), - (const unsigned char *)EOCD_MAGIC, 4))!=NULL) { - /* found match -- check, if good */ - /* to avoid finding the same match all over again */ - match++; - if ((cdirnew=_zip_readcdir(fp, buf, match-1, (int)buflen, flags, - &zerr)) == NULL) - continue; - - if (cdir) { - if (best <= 0) - best = _zip_checkcons(fp, cdir, &zerr); - a = _zip_checkcons(fp, cdirnew, &zerr); - if (best < a) { - _zip_cdir_free(cdir); - cdir = cdirnew; - best = a; - } - else - _zip_cdir_free(cdirnew); - } - else { - cdir = cdirnew; - if (flags & ZIP_CHECKCONS) - best = _zip_checkcons(fp, cdir, &zerr); - else - best = 0; - } - cdirnew = NULL; + if (buflen >= CDBUFSIZE) { + /* EOCD64 locator is before EOCD, so leave place for it */ + _zip_buffer_set_offset(buffer, EOCD64LOCLEN); + } + zip_error_set(&error, ZIP_ER_NOZIP, 0); + + match = _zip_buffer_get(buffer, 0); + while ((match=_zip_memmem(match, _zip_buffer_left(buffer)-(EOCDLEN-4), (const unsigned char *)EOCD_MAGIC, 4)) != NULL) { + _zip_buffer_set_offset(buffer, (zip_uint64_t)(match - _zip_buffer_data(buffer))); + if ((cdirnew = _zip_read_cdir(za, buffer, (zip_uint64_t)buf_offset, &error)) != NULL) { + if (cdir) { + if (best <= 0) { + best = _zip_checkcons(za, cdir, &error); + } + + a = _zip_checkcons(za, cdirnew, &error); + if (best < a) { + _zip_cdir_free(cdir); + cdir = cdirnew; + best = a; + } + else { + _zip_cdir_free(cdirnew); + } + } + else { + cdir = cdirnew; + if (za->open_flags & ZIP_CHECKCONS) + best = _zip_checkcons(za, cdir, &error); + else { + best = 0; + } + } + cdirnew = NULL; + } + + match++; + _zip_buffer_set_offset(buffer, (zip_uint64_t)(match - _zip_buffer_data(buffer))); } - free(buf); + _zip_buffer_free(buffer); if (best < 0) { - set_error(zep, &zerr, 0); - _zip_cdir_free(cdir); - return NULL; + _zip_error_copy(&za->error, &error); + _zip_cdir_free(cdir); + return NULL; } return cdir; } - static unsigned char * -_zip_memmem(const unsigned char *big, int biglen, const unsigned char *little, - int littlelen) +_zip_memmem(const unsigned char *big, size_t biglen, const unsigned char *little, size_t littlelen) { const unsigned char *p; @@ -566,11 +640,169 @@ _zip_memmem(const unsigned char *big, int biglen, const unsigned char *little, return NULL; p = big-1; while ((p=(const unsigned char *) - memchr(p+1, little[0], (size_t)(big-(p+1)+biglen-littlelen+1))) - != NULL) { + memchr(p+1, little[0], (size_t)(big-(p+1))+(size_t)(biglen-littlelen)+1)) != NULL) { if (memcmp(p+1, little+1, littlelen-1)==0) return (unsigned char *)p; } return NULL; } + + +static zip_cdir_t *_zip_read_eocd(zip_buffer_t *buffer, zip_uint64_t buf_offset, unsigned int flags, zip_error_t *error) +{ + zip_cdir_t *cd; + zip_uint64_t i, nentry, size, offset, eocd_offset; + + if (_zip_buffer_left(buffer) < EOCDLEN) { + zip_error_set(error, ZIP_ER_INCONS, 0); + return NULL; + } + + eocd_offset = _zip_buffer_offset(buffer); + + _zip_buffer_get(buffer, 8); /* magic and number of disks already verified */ + + /* number of cdir-entries on this disk */ + i = _zip_buffer_get_16(buffer); + /* number of cdir-entries */ + nentry = _zip_buffer_get_16(buffer); + + if (nentry != i) { + zip_error_set(error, ZIP_ER_NOZIP, 0); + return NULL; + } + + size = _zip_buffer_get_32(buffer); + offset = _zip_buffer_get_32(buffer); + + if (offset+size < offset) { + zip_error_set(error, ZIP_ER_SEEK, EFBIG); + return NULL; + } + + if (offset+size > buf_offset + eocd_offset) { + /* cdir spans past EOCD record */ + zip_error_set(error, ZIP_ER_INCONS, 0); + return NULL; + } + + if ((flags & ZIP_CHECKCONS) && offset+size != buf_offset + eocd_offset) { + zip_error_set(error, ZIP_ER_INCONS, 0); + return NULL; + } + + if ((cd=_zip_cdir_new(nentry, error)) == NULL) + return NULL; + + cd->size = size; + cd->offset = offset; + + return cd; +} + + +static zip_cdir_t * +_zip_read_eocd64(zip_source_t *src, zip_buffer_t *buffer, zip_uint64_t buf_offset, unsigned int flags, zip_error_t *error) +{ + zip_cdir_t *cd; + zip_uint64_t offset; + zip_uint8_t eocd[EOCD64LEN]; + zip_uint64_t eocd_offset; + zip_uint64_t size, nentry, i, eocdloc_offset; + bool free_buffer; + + eocdloc_offset = _zip_buffer_offset(buffer); + + _zip_buffer_get(buffer, 8); /* magic and single disk already verified */ + eocd_offset = _zip_buffer_get_64(buffer); + + if (eocd_offset > ZIP_INT64_MAX || eocd_offset + EOCD64LEN < eocd_offset) { + zip_error_set(error, ZIP_ER_SEEK, EFBIG); + return NULL; + } + + if (eocd_offset + EOCD64LEN > eocdloc_offset + buf_offset) { + zip_error_set(error, ZIP_ER_INCONS, 0); + return NULL; + } + + if (eocd_offset >= buf_offset && eocd_offset + EOCD64LEN <= buf_offset + _zip_buffer_size(buffer)) { + _zip_buffer_set_offset(buffer, eocd_offset - buf_offset); + free_buffer = false; + } + else { + if (zip_source_seek(src, (zip_int64_t)eocd_offset, SEEK_SET) < 0) { + _zip_error_set_from_source(error, src); + return NULL; + } + if ((buffer = _zip_buffer_new_from_source(src, EOCD64LEN, eocd, error)) == NULL) { + return NULL; + } + free_buffer = true; + } + + if (memcmp(_zip_buffer_get(buffer, 4), EOCD64_MAGIC, 4) != 0) { + zip_error_set(error, ZIP_ER_INCONS, 0); + if (free_buffer) { + _zip_buffer_free(buffer); + } + return NULL; + } + + size = _zip_buffer_get_64(buffer); + + if ((flags & ZIP_CHECKCONS) && size + eocd_offset + 12 != buf_offset + eocdloc_offset) { + zip_error_set(error, ZIP_ER_INCONS, 0); + if (free_buffer) { + _zip_buffer_free(buffer); + } + return NULL; + } + + _zip_buffer_get(buffer, 12); /* skip version made by/needed and num disks */ + + nentry = _zip_buffer_get_64(buffer); + i = _zip_buffer_get_64(buffer); + + if (nentry != i) { + zip_error_set(error, ZIP_ER_MULTIDISK, 0); + if (free_buffer) { + _zip_buffer_free(buffer); + } + return NULL; + } + + size = _zip_buffer_get_64(buffer); + offset = _zip_buffer_get_64(buffer); + + if (!_zip_buffer_ok(buffer)) { + zip_error_set(error, ZIP_ER_INTERNAL, 0); + if (free_buffer) { + _zip_buffer_free(buffer); + } + return NULL; + } + + if (free_buffer) { + _zip_buffer_free(buffer); + } + + if (offset > ZIP_INT64_MAX || offset+size < offset) { + zip_error_set(error, ZIP_ER_SEEK, EFBIG); + return NULL; + } + if ((flags & ZIP_CHECKCONS) && offset+size != eocd_offset) { + zip_error_set(error, ZIP_ER_INCONS, 0); + return NULL; + } + + if ((cd=_zip_cdir_new(nentry, error)) == NULL) + return NULL; + + + cd->size = size; + cd->offset = offset; + + return cd; +} diff --git a/ePub3/ThirdParty/libzip/zip_rename.c b/ePub3/ThirdParty/libzip/zip_rename.c index 1d056bbe3..14e101d79 100644 --- a/ePub3/ThirdParty/libzip/zip_rename.c +++ b/ePub3/ThirdParty/libzip/zip_rename.c @@ -1,6 +1,6 @@ /* zip_rename.c -- rename file in zip archive - Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,35 +31,15 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include +#define _ZIP_COMPILING_DEPRECATED #include "zipint.h" - ZIP_EXTERN int -zip_rename(struct zip *za, int idx, const char *name) +zip_rename(zip_t *za, zip_uint64_t idx, const char *name) { - const char *old_name; - int old_is_dir, new_is_dir; - - if (idx >= za->nentry || idx < 0 || name[0] == '\0') { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); - return -1; - } - - if ((old_name=zip_get_name(za, idx, 0)) == NULL) - return -1; - - new_is_dir = (name[strlen(name)-1] == '/'); - old_is_dir = (old_name[strlen(old_name)-1] == '/'); - - if (new_is_dir != old_is_dir) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); - return -1; - } - - return _zip_set_name(za, idx, name); + return zip_file_rename(za, idx, name, 0); } diff --git a/ePub3/ThirdParty/libzip/zip_replace.c b/ePub3/ThirdParty/libzip/zip_replace.c index 6cdb80c50..eed019a09 100644 --- a/ePub3/ThirdParty/libzip/zip_replace.c +++ b/ePub3/ThirdParty/libzip/zip_replace.c @@ -1,6 +1,6 @@ /* zip_replace.c -- replace file via callback function - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,48 +31,13 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - +#define _ZIP_COMPILING_DEPRECATED #include "zipint.h" - ZIP_EXTERN int -zip_replace(struct zip *za, int idx, struct zip_source *source) +zip_replace(zip_t *za, zip_uint64_t idx, zip_source_t *source) { - if (idx < 0 || idx >= za->nentry || source == NULL) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); - return -1; - } - - if (_zip_replace(za, idx, NULL, source) == -1) - return -1; - - return 0; -} - - - - -int -_zip_replace(struct zip *za, int idx, const char *name, - struct zip_source *source) -{ - if (idx == -1) { - if (_zip_entry_new(za) == NULL) - return -1; - - idx = za->nentry - 1; - } - - _zip_unchange_data(za->entry+idx); - - if (name && _zip_set_name(za, idx, name) != 0) - return -1; - - za->entry[idx].state = ((za->cdir == NULL || idx >= za->cdir->nentry) - ? ZIP_ST_ADDED : ZIP_ST_REPLACED); - za->entry[idx].source = source; - - return idx; + return zip_file_replace(za, idx, source, 0); } diff --git a/ePub3/ThirdParty/libzip/zip_set_archive_comment.c b/ePub3/ThirdParty/libzip/zip_set_archive_comment.c index 343fa5491..9090eec95 100644 --- a/ePub3/ThirdParty/libzip/zip_set_archive_comment.c +++ b/ePub3/ThirdParty/libzip/zip_set_archive_comment.c @@ -1,6 +1,6 @@ /* zip_set_archive_comment.c -- set archive comment - Copyright (C) 2006-2007 Dieter Baron and Thomas Klausner + Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,35 +31,52 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include "zipint.h" - ZIP_EXTERN int -zip_set_archive_comment(struct zip *za, const char *comment, int len) +zip_set_archive_comment(zip_t *za, const char *comment, zip_uint16_t len) { - char *tmpcom; + zip_string_t *cstr; - if (len < 0 || len > MAXCOMLEN - || (len > 0 && comment == NULL)) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); + if (ZIP_IS_RDONLY(za)) { + zip_error_set(&za->error, ZIP_ER_RDONLY, 0); + return -1; + } + + if (len > 0 && comment == NULL) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); return -1; } if (len > 0) { - if ((tmpcom=(char *)_zip_memdup(comment, len, &za->error)) == NULL) + if ((cstr=_zip_string_new((const zip_uint8_t *)comment, len, ZIP_FL_ENC_GUESS, &za->error)) == NULL) + return -1; + + if (_zip_guess_encoding(cstr, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_CP437) { + _zip_string_free(cstr); + zip_error_set(&za->error, ZIP_ER_INVAL, 0); return -1; + } } else - tmpcom = NULL; + cstr = NULL; + + _zip_string_free(za->comment_changes); + za->comment_changes = NULL; - free(za->ch_comment); - za->ch_comment = tmpcom; - za->ch_comment_len = len; + if (((za->comment_orig && _zip_string_equal(za->comment_orig, cstr)) + || (za->comment_orig == NULL && cstr == NULL))) { + _zip_string_free(cstr); + za->comment_changed = 0; + } + else { + za->comment_changes = cstr; + za->comment_changed = 1; + } return 0; } diff --git a/ePub3/ThirdParty/libzip/zip_set_archive_flag.c b/ePub3/ThirdParty/libzip/zip_set_archive_flag.c index 720e1f350..2625b2e65 100644 --- a/ePub3/ThirdParty/libzip/zip_set_archive_flag.c +++ b/ePub3/ThirdParty/libzip/zip_set_archive_flag.c @@ -1,6 +1,6 @@ /* zip_get_archive_flag.c -- set archive global flag - Copyright (C) 2008 Dieter Baron and Thomas Klausner + Copyright (C) 2008-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,19 +31,37 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "zipint.h" - ZIP_EXTERN int -zip_set_archive_flag(struct zip *za, int flag, int value) +zip_set_archive_flag(zip_t *za, zip_flags_t flag, int value) { + unsigned int new_flags; + if (value) - za->ch_flags |= flag; + new_flags = za->ch_flags | flag; else - za->ch_flags &= ~flag; + new_flags = za->ch_flags & ~flag; + + if (new_flags == za->ch_flags) + return 0; + + if (ZIP_IS_RDONLY(za)) { + zip_error_set(&za->error, ZIP_ER_RDONLY, 0); + return -1; + } + + if ((flag & ZIP_AFL_RDONLY) && value + && (za->ch_flags & ZIP_AFL_RDONLY) == 0) { + if (_zip_changed(za, NULL)) { + zip_error_set(&za->error, ZIP_ER_CHANGED, 0); + return -1; + } + } + + za->ch_flags = new_flags; return 0; } diff --git a/ePub3/ThirdParty/libzip/zip_entry_new.c b/ePub3/ThirdParty/libzip/zip_set_default_password.c similarity index 64% rename from ePub3/ThirdParty/libzip/zip_entry_new.c rename to ePub3/ThirdParty/libzip/zip_set_default_password.c index 7059b1b06..ac098dc5f 100644 --- a/ePub3/ThirdParty/libzip/zip_entry_new.c +++ b/ePub3/ThirdParty/libzip/zip_set_default_password.c @@ -1,6 +1,6 @@ /* - zip_entry_new.c -- create and init struct zip_entry - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + zip_set_default_password.c -- set default password for decryption + Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,48 +31,30 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include +#include #include "zipint.h" - -struct zip_entry * -_zip_entry_new(struct zip *za) +ZIP_EXTERN int +zip_set_default_password(zip_t *za, const char *passwd) { - struct zip_entry *ze; - if (!za) { - ze = (struct zip_entry *)malloc(sizeof(struct zip_entry)); - if (!ze) { - _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); - return NULL; + if (za == NULL) + return -1; + + if (za->default_password) + free(za->default_password); + + if (passwd) { + if ((za->default_password=strdup(passwd)) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return -1; } } - else { - if (za->nentry >= za->nentry_alloc-1) { - za->nentry_alloc += 16; - za->entry = (struct zip_entry *)realloc(za->entry, - sizeof(struct zip_entry) - * za->nentry_alloc); - if (!za->entry) { - _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); - return NULL; - } - } - ze = za->entry+za->nentry; - } - - ze->state = ZIP_ST_UNCHANGED; - - ze->ch_filename = NULL; - ze->ch_comment = NULL; - ze->ch_comment_len = -1; - ze->source = NULL; - - if (za) - za->nentry++; + else + za->default_password = NULL; - return ze; + return 0; } diff --git a/ePub3/ThirdParty/libzip/zip_set_file_comment.c b/ePub3/ThirdParty/libzip/zip_set_file_comment.c index bc1938e1d..d35669374 100644 --- a/ePub3/ThirdParty/libzip/zip_set_file_comment.c +++ b/ePub3/ThirdParty/libzip/zip_set_file_comment.c @@ -1,6 +1,6 @@ /* zip_set_file_comment.c -- set comment for file in archive - Copyright (C) 2006-2007 Dieter Baron and Thomas Klausner + Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,36 +31,19 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include +#define _ZIP_COMPILING_DEPRECATED #include "zipint.h" - ZIP_EXTERN int -zip_set_file_comment(struct zip *za, int idx, const char *comment, int len) +zip_set_file_comment(zip_t *za, zip_uint64_t idx, const char *comment, int len) { - char *tmpcom; - - if (idx < 0 || idx >= za->nentry - || len < 0 || len > MAXCOMLEN - || (len > 0 && comment == NULL)) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); - return -1; - } - - if (len > 0) { - if ((tmpcom=(char *)_zip_memdup(comment, len, &za->error)) == NULL) - return -1; + if (len < 0 || len > ZIP_UINT16_MAX) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; } - else - tmpcom = NULL; - - free(za->entry[idx].ch_comment); - za->entry[idx].ch_comment = tmpcom; - za->entry[idx].ch_comment_len = len; - - return 0; + return zip_file_set_comment(za, idx, comment, (zip_uint16_t)len, 0); } diff --git a/ePub3/ThirdParty/libzip/zip_set_file_compression.c b/ePub3/ThirdParty/libzip/zip_set_file_compression.c new file mode 100644 index 000000000..7bb0bf945 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_set_file_compression.c @@ -0,0 +1,87 @@ +/* + zip_set_file_compression.c -- set compression for file in archive + Copyright (C) 2012-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +ZIP_EXTERN int +zip_set_file_compression(zip_t *za, zip_uint64_t idx, zip_int32_t method, zip_uint32_t flags) +{ + zip_entry_t *e; + zip_int32_t old_method; + + if (idx >= za->nentry) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (ZIP_IS_RDONLY(za)) { + zip_error_set(&za->error, ZIP_ER_RDONLY, 0); + return -1; + } + + if (method != ZIP_CM_DEFAULT && method != ZIP_CM_STORE && method != ZIP_CM_DEFLATE) { + zip_error_set(&za->error, ZIP_ER_COMPNOTSUPP, 0); + return -1; + } + + e = za->entry+idx; + + old_method = (e->orig == NULL ? ZIP_CM_DEFAULT : e->orig->comp_method); + + /* TODO: revisit this when flags are supported, since they may require a recompression */ + + if (method == old_method) { + if (e->changes) { + e->changes->changed &= ~ZIP_DIRENT_COMP_METHOD; + if (e->changes->changed == 0) { + _zip_dirent_free(e->changes); + e->changes = NULL; + } + } + } + else { + if (e->changes == NULL) { + if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return -1; + } + } + + e->changes->comp_method = method; + e->changes->changed |= ZIP_DIRENT_COMP_METHOD; + } + + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_set_name.c b/ePub3/ThirdParty/libzip/zip_set_name.c index cf1d2a96d..5a1038175 100644 --- a/ePub3/ThirdParty/libzip/zip_set_name.c +++ b/ePub3/ThirdParty/libzip/zip_set_name.c @@ -1,6 +1,6 @@ /* zip_set_name.c -- rename helper function - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,49 +31,85 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include #include "zipint.h" -#if defined(_MSC_VER) -# define strdup _strdup -#endif - - int -_zip_set_name(struct zip *za, int idx, const char *name) +_zip_set_name(zip_t *za, zip_uint64_t idx, const char *name, zip_flags_t flags) { - char *s; - int i; - - if (idx < 0 || idx >= za->nentry || name == NULL) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); + zip_entry_t *e; + zip_string_t *str; + int changed; + zip_int64_t i; + + if (idx >= za->nentry) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); return -1; } - if ((i=_zip_name_locate(za, name, 0, NULL)) != -1 && i != idx) { - _zip_error_set(&za->error, ZIP_ER_EXISTS, 0); + if (ZIP_IS_RDONLY(za)) { + zip_error_set(&za->error, ZIP_ER_RDONLY, 0); + return -1; + } + + if (name && strlen(name) > 0) { + /* TODO: check for string too long */ + if ((str=_zip_string_new((const zip_uint8_t *)name, (zip_uint16_t)strlen(name), flags, &za->error)) == NULL) + return -1; + if ((flags & ZIP_FL_ENCODING_ALL) == ZIP_FL_ENC_GUESS && _zip_guess_encoding(str, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_UTF8_GUESSED) + str->encoding = ZIP_ENCODING_UTF8_KNOWN; + } + else + str = NULL; + + /* TODO: encoding flags needed for CP437? */ + if ((i=_zip_name_locate(za, name, 0, NULL)) >= 0 && (zip_uint64_t)i != idx) { + _zip_string_free(str); + zip_error_set(&za->error, ZIP_ER_EXISTS, 0); return -1; } /* no effective name change */ - if (i == idx) + if (i>=0 && (zip_uint64_t)i == idx) { + _zip_string_free(str); return 0; - - if ((s=strdup(name)) == NULL) { - _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); - return -1; } - - if (za->entry[idx].state == ZIP_ST_UNCHANGED) - za->entry[idx].state = ZIP_ST_RENAMED; - free(za->entry[idx].ch_filename); - za->entry[idx].ch_filename = s; + e = za->entry+idx; + + if (e->changes) { + _zip_string_free(e->changes->filename); + e->changes->filename = NULL; + e->changes->changed &= ~ZIP_DIRENT_FILENAME; + } + + if (e->orig) + changed = !_zip_string_equal(e->orig->filename, str); + else + changed = 1; + + if (changed) { + if (e->changes == NULL) { + if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + _zip_string_free(str); + return -1; + } + } + e->changes->filename = str; + e->changes->changed |= ZIP_DIRENT_FILENAME; + } + else { + _zip_string_free(str); + if (e->changes && e->changes->changed == 0) { + _zip_dirent_free(e->changes); + e->changes = NULL; + } + } return 0; } diff --git a/ePub3/ThirdParty/libzip/zip_source_begin_write.c b/ePub3/ThirdParty/libzip/zip_source_begin_write.c new file mode 100644 index 000000000..045933771 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_begin_write.c @@ -0,0 +1,53 @@ +/* + zip_source_begin_write.c -- start a new file for writing + Copyright (C) 2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +ZIP_EXTERN int +zip_source_begin_write(zip_source_t *src) +{ + if (ZIP_SOURCE_IS_OPEN_WRITING(src)) { + zip_error_set(&src->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_BEGIN_WRITE) < 0) { + return -1; + } + + src->write_state = ZIP_SOURCE_WRITE_OPEN; + + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_buffer.c b/ePub3/ThirdParty/libzip/zip_source_buffer.c index 7624df534..01304d9cd 100644 --- a/ePub3/ThirdParty/libzip/zip_source_buffer.c +++ b/ePub3/ThirdParty/libzip/zip_source_buffer.c @@ -1,6 +1,6 @@ /* zip_source_buffer.c -- create zip data source from buffer - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,127 +31,405 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - - +#include #include #include #include "zipint.h" +#ifndef WRITE_FRAGMENT_SIZE +#define WRITE_FRAGMENT_SIZE 64*1024 +#endif + +struct buffer { + zip_uint64_t fragment_size; /* size of each fragment */ + + zip_uint8_t **fragments; /* pointers to fragments */ + zip_uint64_t nfragments; /* number of allocated fragments */ + zip_uint64_t fragments_capacity; /* size of fragments (number of pointers) */ + zip_uint64_t size; /* size of data in bytes */ + zip_uint64_t offset; /* current offset */ + int free_data; +}; + +typedef struct buffer buffer_t; + struct read_data { - const char *buf, *data, *end; + zip_error_t error; time_t mtime; - int freep; + buffer_t *in; + buffer_t *out; }; -static ssize_t read_data(void *state, void *data, size_t len, - enum zip_source_cmd cmd); +static void buffer_free(buffer_t *buffer); +static buffer_t *buffer_new(zip_uint64_t fragment_size); +static buffer_t *buffer_new_read(const void *data, zip_uint64_t length, int free_data); +static buffer_t *buffer_new_write(zip_uint64_t fragment_size); +static zip_int64_t buffer_read(buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length); +static int buffer_seek(buffer_t *buffer, void *data, zip_uint64_t len, zip_error_t *error); +static zip_int64_t buffer_write(buffer_t *buffer, const zip_uint8_t *data, zip_uint64_t length, zip_error_t *); - +static zip_int64_t read_data(void *, void *, zip_uint64_t, zip_source_cmd_t); -ZIP_EXTERN struct zip_source * -zip_source_buffer(struct zip *za, const void *data, off_t len, int freep) -{ - struct read_data *f; - struct zip_source *zs; +ZIP_EXTERN zip_source_t * +zip_source_buffer(zip_t *za, const void *data, zip_uint64_t len, int freep) +{ if (za == NULL) return NULL; - if (len < 0 || (data == NULL && len > 0)) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return zip_source_buffer_create(data, len, freep, &za->error); +} + + +ZIP_EXTERN zip_source_t * +zip_source_buffer_create(const void *data, zip_uint64_t len, int freep, zip_error_t *error) +{ + struct read_data *ctx; + zip_source_t *zs; + + if (data == NULL && len > 0) { + zip_error_set(error, ZIP_ER_INVAL, 0); return NULL; } - if ((f=(struct read_data *)malloc(sizeof(*f))) == NULL) { - _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + if ((ctx=(struct read_data *)malloc(sizeof(*ctx))) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); return NULL; } - f->data = (const char *)data; - f->end = ((const char *)data)+len; - f->freep = freep; - f->mtime = time(NULL); + if ((ctx->in = buffer_new_read(data, len, freep)) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + free(ctx); + return NULL; + } + + ctx->out = NULL; + ctx->mtime = time(NULL); + zip_error_init(&ctx->error); - if ((zs=zip_source_function(za, read_data, f)) == NULL) { - free(f); + if ((zs=zip_source_function_create(read_data, ctx, error)) == NULL) { + buffer_free(ctx->in); + free(ctx); return NULL; } return zs; } - -static ssize_t -read_data(void *state, void *data, size_t len, enum zip_source_cmd cmd) +static zip_int64_t +read_data(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd) { - struct read_data *z; - char *buf; - size_t n; - - z = (struct read_data *)state; - buf = (char *)data; + struct read_data *ctx = (struct read_data *)state; switch (cmd) { - case ZIP_SOURCE_OPEN: - z->buf = z->data; - return 0; + case ZIP_SOURCE_BEGIN_WRITE: + if ((ctx->out = buffer_new_write(WRITE_FRAGMENT_SIZE)) == NULL) { + zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0); + return -1; + } + return 0; + + case ZIP_SOURCE_CLOSE: + return 0; + + case ZIP_SOURCE_COMMIT_WRITE: + buffer_free(ctx->in); + ctx->in = ctx->out; + ctx->out = NULL; + return 0; + + case ZIP_SOURCE_ERROR: + return zip_error_to_data(&ctx->error, data, len); + + case ZIP_SOURCE_FREE: + buffer_free(ctx->in); + buffer_free(ctx->out); + free(ctx); + return 0; + + case ZIP_SOURCE_OPEN: + ctx->in->offset = 0; + return 0; + + case ZIP_SOURCE_READ: + if (len > ZIP_INT64_MAX) { + zip_error_set(&ctx->error, ZIP_ER_INVAL, 0); + return -1; + } + return buffer_read(ctx->in, (zip_uint8_t *)data, len); + + case ZIP_SOURCE_REMOVE: + { + buffer_t *empty = buffer_new_read(NULL, 0, 0); + if (empty == 0) { + zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0); + return -1; + } - case ZIP_SOURCE_READ: - n = z->end - z->buf; - if (n > len) - n = len; - - if (n) { - memcpy(buf, z->buf, n); - z->buf += n; + buffer_free(ctx->in); + ctx->in = empty; + return 0; } - return (ssize_t)n; - - case ZIP_SOURCE_CLOSE: - return 0; + case ZIP_SOURCE_ROLLBACK_WRITE: + buffer_free(ctx->out); + ctx->out = NULL; + return 0; + + case ZIP_SOURCE_SEEK: + return buffer_seek(ctx->in, data, len, &ctx->error); - case ZIP_SOURCE_STAT: + case ZIP_SOURCE_SEEK_WRITE: + return buffer_seek(ctx->out, data, len, &ctx->error); + + case ZIP_SOURCE_STAT: { - struct zip_stat *st; + zip_stat_t *st; - if (len < sizeof(*st)) + if (len < sizeof(*st)) { + zip_error_set(&ctx->error, ZIP_ER_INVAL, 0); return -1; + } - st = (struct zip_stat *)data; + st = (zip_stat_t *)data; zip_stat_init(st); - st->mtime = z->mtime; - st->size = (off_t)(z->end - z->data); + st->mtime = ctx->mtime; + st->size = ctx->in->size; + st->comp_size = st->size; + st->comp_method = ZIP_CM_STORE; + st->encryption_method = ZIP_EM_NONE; + st->valid = ZIP_STAT_MTIME|ZIP_STAT_SIZE|ZIP_STAT_COMP_SIZE|ZIP_STAT_COMP_METHOD|ZIP_STAT_ENCRYPTION_METHOD; return sizeof(*st); } - case ZIP_SOURCE_ERROR: - { - int *e; + case ZIP_SOURCE_SUPPORTS: + return zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, ZIP_SOURCE_SEEK, ZIP_SOURCE_TELL, ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_REMOVE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_WRITE, -1); + + case ZIP_SOURCE_TELL: + if (ctx->in->offset > ZIP_INT64_MAX) { + zip_error_set(&ctx->error, ZIP_ER_TELL, EOVERFLOW); + return -1; + } + return (zip_int64_t)ctx->in->offset; + + + case ZIP_SOURCE_TELL_WRITE: + if (ctx->out->offset > ZIP_INT64_MAX) { + zip_error_set(&ctx->error, ZIP_ER_TELL, EOVERFLOW); + return -1; + } + return (zip_int64_t)ctx->out->offset; - if (len < sizeof(int)*2) + case ZIP_SOURCE_WRITE: + if (len > ZIP_INT64_MAX) { + zip_error_set(&ctx->error, ZIP_ER_INVAL, 0); return -1; + } + return buffer_write(ctx->out, (zip_uint8_t *)data, len, &ctx->error); + + default: + zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0); + return -1; + } +} + - e = (int *)data; - e[0] = e[1] = 0; +static void +buffer_free(buffer_t *buffer) +{ + if (buffer == NULL) { + return; + } + + if (buffer->free_data) { + zip_uint64_t i; + + for (i=0; i < buffer->nfragments; i++) { + free(buffer->fragments[i]); } - return sizeof(int)*2; + } + free(buffer->fragments); + free(buffer); +} + + +static buffer_t * +buffer_new(zip_uint64_t fragment_size) +{ + buffer_t *buffer; + + if ((buffer = (buffer_t *)malloc(sizeof(*buffer))) == NULL) { + return NULL; + } + + buffer->fragment_size = fragment_size; + buffer->offset = 0; + buffer->free_data = 0; + buffer->nfragments = 0; + buffer->fragments_capacity = 0; + buffer->fragments = NULL; + buffer->size = 0; + + return buffer; +} + + +static buffer_t * +buffer_new_read(const void *data, zip_uint64_t length, int free_data) +{ + buffer_t *buffer; + + if ((buffer = buffer_new(length)) == NULL) { + return NULL; + } - case ZIP_SOURCE_FREE: - if (z->freep) { - free((void *)z->data); - z->data = NULL; + buffer->size = length; + + if (length > 0) { + if ((buffer->fragments = (zip_uint8_t **)malloc(sizeof(*(buffer->fragments)))) == NULL) { + buffer_free(buffer); + return NULL; } - free(z); + buffer->fragments_capacity = 1; + + buffer->nfragments = 1; + buffer->fragments[0] = (zip_uint8_t *)data; + buffer->free_data = free_data; + } + + return buffer; +} + + +static buffer_t * +buffer_new_write(zip_uint64_t fragment_size) +{ + buffer_t *buffer; + + if ((buffer = buffer_new(fragment_size)) == NULL) { + return NULL; + } + + if ((buffer->fragments = (zip_uint8_t **)malloc(sizeof(*(buffer->fragments)))) == NULL) { + buffer_free(buffer); + return NULL; + } + buffer->fragments_capacity = 1; + buffer->nfragments = 0; + buffer->free_data = 1; + + return buffer; +} + + +static zip_int64_t +buffer_read(buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length) +{ + zip_uint64_t n, i, fragment_offset; + + length = ZIP_MIN(length, buffer->size - buffer->offset); + + if (length == 0) { return 0; + } + if (length > ZIP_INT64_MAX) { + return -1; + } + + i = buffer->offset / buffer->fragment_size; + fragment_offset = buffer->offset % buffer->fragment_size; + n = 0; + while (n < length) { + zip_uint64_t left = ZIP_MIN(length - n, buffer->fragment_size - fragment_offset); + + memcpy(data + n, buffer->fragments[i] + fragment_offset, left); + + n += left; + i++; + fragment_offset = 0; + } + + buffer->offset += n; + return (zip_int64_t)n; +} + + +static int +buffer_seek(buffer_t *buffer, void *data, zip_uint64_t len, zip_error_t *error) +{ + zip_int64_t new_offset = zip_source_seek_compute_offset(buffer->offset, buffer->size, data, len, error); + + if (new_offset < 0) { + return -1; + } + + buffer->offset = (zip_uint64_t)new_offset; + return 0; +} + + +static zip_int64_t +buffer_write(buffer_t *buffer, const zip_uint8_t *data, zip_uint64_t length, zip_error_t *error) +{ + zip_uint64_t n, i, fragment_offset; + + if (buffer->offset + length + buffer->fragment_size - 1 < length) { + zip_error_set(error, ZIP_ER_INVAL, 0); + return -1; + } + + /* grow buffer if needed */ + if (buffer->offset + length > buffer->nfragments * buffer->fragment_size) { + zip_uint64_t needed_fragments = (buffer->offset + length + buffer->fragment_size - 1) / buffer->fragment_size; + + if (needed_fragments > buffer->fragments_capacity) { + zip_uint64_t new_capacity = buffer->fragments_capacity; + + while (new_capacity < needed_fragments) { + new_capacity *= 2; + } + + zip_uint8_t **fragments = (zip_uint8_t **)realloc(buffer->fragments, new_capacity * sizeof(*fragments)); + + if (fragments == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + return -1; + } + + buffer->fragments = fragments; + buffer->fragments_capacity = new_capacity; + } + + while (buffer->nfragments < needed_fragments) { + if ((buffer->fragments[buffer->nfragments] = (zip_uint8_t *)malloc(buffer->fragment_size)) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + return -1; + } + buffer->nfragments++; + } + } + + i = buffer->offset / buffer->fragment_size; + fragment_offset = buffer->offset % buffer->fragment_size; + n = 0; + while (n < length) { + zip_uint64_t left = ZIP_MIN(length - n, buffer->fragment_size - fragment_offset); + + memcpy(buffer->fragments[i] + fragment_offset, data + n, left); + + n += left; + i++; + fragment_offset = 0; + } - default: - ; + buffer->offset += n; + if (buffer->offset > buffer->size) { + buffer->size = buffer->offset; } - return -1; + return (zip_int64_t)n; } diff --git a/ePub3/ThirdParty/libzip/zip_source_call.c b/ePub3/ThirdParty/libzip/zip_source_call.c new file mode 100644 index 000000000..21f28bc42 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_call.c @@ -0,0 +1,69 @@ +/* + zip_source_call.c -- invoke callback command on zip_source + Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "zipint.h" + + +zip_int64_t +_zip_source_call(zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command) +{ + zip_int64_t ret; + + if ((src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(command)) == 0) { + zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0); + return -1; + } + + if (src->src == NULL) { + ret = src->cb.f(src->ud, data, length, command); + } + else { + ret = src->cb.l(src->src, src->ud, data, length, command); + } + + if (ret < 0) { + if (command != ZIP_SOURCE_ERROR && command != ZIP_SOURCE_SUPPORTS) { + int e[2]; + + if (_zip_source_call(src, e, sizeof(e), ZIP_SOURCE_ERROR) < 0) { + zip_error_set(&src->error, ZIP_ER_INTERNAL, 0); + } + else { + zip_error_set(&src->error, e[0], e[1]); + } + } + } + + return ret; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_close.c b/ePub3/ThirdParty/libzip/zip_source_close.c new file mode 100644 index 000000000..36bc84235 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_close.c @@ -0,0 +1,58 @@ +/* + zip_source_close.c -- close zip_source (stop reading) + Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +int +zip_source_close(zip_source_t *src) +{ + if (!ZIP_SOURCE_IS_OPEN_READING(src)) { + zip_error_set(&src->error, ZIP_ER_INVAL, 0); + return -1; + } + + src->open_count--; + if (src->open_count == 0) { + _zip_source_call(src, NULL, 0, ZIP_SOURCE_CLOSE); + + if (ZIP_SOURCE_IS_LAYERED(src)) { + if (zip_source_close(src->src) < 0) { + zip_error_set(&src->error, ZIP_ER_INTERNAL, 0); + } + } + } + + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_commit_write.c b/ePub3/ThirdParty/libzip/zip_source_commit_write.c new file mode 100644 index 000000000..ba77abc34 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_commit_write.c @@ -0,0 +1,64 @@ +/* + zip_source_commit_write.c -- commit changes to file + Copyright (C) 2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +ZIP_EXTERN int +zip_source_commit_write(zip_source_t *src) +{ + if (!ZIP_SOURCE_IS_OPEN_WRITING(src)) { + zip_error_set(&src->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (src->open_count > 1) { + zip_error_set(&src->error, ZIP_ER_INUSE, 0); + return -1; + } + else if (ZIP_SOURCE_IS_OPEN_READING(src)) { + if (zip_source_close(src) < 0) { + return -1; + } + } + + if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_COMMIT_WRITE) < 0) { + src->write_state = ZIP_SOURCE_WRITE_FAILED; + return -1; + } + + src->write_state = ZIP_SOURCE_WRITE_CLOSED; + + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_crc.c b/ePub3/ThirdParty/libzip/zip_source_crc.c new file mode 100644 index 000000000..28432bd9f --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_crc.c @@ -0,0 +1,192 @@ +/* + zip_source_crc.c -- pass-through source that calculates CRC32 and size + Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include +#include +#include + +#include "zipint.h" + +struct crc_context { + int eof; + int validate; + zip_error_t error; + zip_uint64_t size; + zip_uint32_t crc; +}; + +static zip_int64_t crc_read(zip_source_t *, void *, void *, zip_uint64_t, zip_source_cmd_t); + + +zip_source_t * +zip_source_crc(zip_t *za, zip_source_t *src, int validate) +{ + struct crc_context *ctx; + + if (src == NULL) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return NULL; + } + + if ((ctx=(struct crc_context *)malloc(sizeof(*ctx))) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return NULL; + } + + ctx->eof = 0; + ctx->validate = validate; + zip_error_init(&ctx->error); + ctx->size = 0; + ctx->crc = 0; + + return zip_source_layered(za, src, crc_read, ctx); +} + + +static zip_int64_t +crc_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source_cmd_t cmd) +{ + struct crc_context *ctx; + zip_int64_t n; + + ctx = (struct crc_context *)_ctx; + + switch (cmd) { + case ZIP_SOURCE_OPEN: + ctx->eof = 0; + ctx->crc = (zip_uint32_t)crc32(0, NULL, 0); + ctx->size = 0; + + return 0; + + case ZIP_SOURCE_READ: + if (ctx->eof || len == 0) + return 0; + + if ((n=zip_source_read(src, data, len)) < 0) { + _zip_error_set_from_source(&ctx->error, src); + return -1; + } + + if (n == 0) { + ctx->eof = 1; + if (ctx->validate) { + struct zip_stat st; + + if (zip_source_stat(src, &st) < 0) { + _zip_error_set_from_source(&ctx->error, src); + return -1; + } + + if ((st.valid & ZIP_STAT_CRC) && st.crc != ctx->crc) { + zip_error_set(&ctx->error, ZIP_ER_CRC, 0); + return -1; + } + if ((st.valid & ZIP_STAT_SIZE) && st.size != ctx->size) { + zip_error_set(&ctx->error, ZIP_ER_INCONS, 0); + return -1; + } + } + } + else { + zip_uint64_t i, nn; + + for (i=0; i < (zip_uint64_t)n; i += nn) { + nn = ZIP_MIN(UINT_MAX, (zip_uint64_t)n-i); + + ctx->crc = (zip_uint32_t)crc32(ctx->crc, (const Bytef *)data+i, (uInt)nn); + } + ctx->size += (zip_uint64_t)n; + } + return n; + + case ZIP_SOURCE_CLOSE: + return 0; + + case ZIP_SOURCE_STAT: + { + zip_stat_t *st; + + st = (zip_stat_t *)data; + + if (ctx->eof) { + /* TODO: Set comp_size, comp_method, encryption_method? + After all, this only works for uncompressed data. */ + st->size = ctx->size; + st->crc = ctx->crc; + st->comp_size = ctx->size; + st->comp_method = ZIP_CM_STORE; + st->encryption_method = ZIP_EM_NONE; + st->valid |= ZIP_STAT_SIZE|ZIP_STAT_CRC|ZIP_STAT_COMP_SIZE|ZIP_STAT_COMP_METHOD|ZIP_STAT_ENCRYPTION_METHOD;; + } + return 0; + } + + case ZIP_SOURCE_ERROR: + return zip_error_to_data(&ctx->error, data, len); + + case ZIP_SOURCE_FREE: + free(ctx); + return 0; + + case ZIP_SOURCE_SEEK: + if (zip_source_supports(src)&ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK)) + return _zip_source_call(src, data, len, cmd); + zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0); + return -1; + break; + case ZIP_SOURCE_TELL: + if (zip_source_supports(src)&ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL)) + return _zip_source_call(src, data, len, cmd); + zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0); + return -1; + break; + + case ZIP_SOURCE_SUPPORTS: + { + zip_int64_t support = zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, -1); + if (src) + { + support |= zip_source_supports(src)&ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK); + support |= zip_source_supports(src)&ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL); + } + + return support; + } + + default: + zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0); + return -1; + } +} diff --git a/ePub3/ThirdParty/libzip/zip_source_deflate.c b/ePub3/ThirdParty/libzip/zip_source_deflate.c new file mode 100644 index 000000000..2574ad017 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_deflate.c @@ -0,0 +1,415 @@ +/* + zip_source_deflate.c -- deflate (de)compressoin routines + Copyright (C) 2009-2015 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include + +#include "zipint.h" + +struct deflate { + zip_error_t error; + + bool eof; + bool can_store; + bool is_stored; + int mem_level; + zip_uint64_t size; + zip_uint8_t buffer[BUFSIZE]; + z_stream zstr; +}; + +static zip_int64_t compress_read(zip_source_t *, struct deflate *, void *, zip_uint64_t); +static zip_int64_t decompress_read(zip_source_t *, struct deflate *, void *, zip_uint64_t); +static zip_int64_t deflate_compress(zip_source_t *, void *, void *, zip_uint64_t, zip_source_cmd_t); +static zip_int64_t deflate_decompress(zip_source_t *, void *, void *, zip_uint64_t, zip_source_cmd_t); +static void deflate_free(struct deflate *); + + +zip_source_t * +zip_source_deflate(zip_t *za, zip_source_t *src, zip_int32_t cm, int flags) +{ + struct deflate *ctx; + zip_source_t *s2; + + if (src == NULL || (cm != ZIP_CM_DEFLATE && !ZIP_CM_IS_DEFAULT(cm))) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return NULL; + } + + if ((ctx=(struct deflate *)malloc(sizeof(*ctx))) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return NULL; + } + + zip_error_init(&ctx->error); + ctx->eof = false; + ctx->is_stored = false; + ctx->can_store = ZIP_CM_IS_DEFAULT(cm); + if (flags & ZIP_CODEC_ENCODE) { + ctx->mem_level = MAX_MEM_LEVEL; + } + + if ((s2=zip_source_layered(za, src, + ((flags & ZIP_CODEC_ENCODE) + ? deflate_compress : deflate_decompress), + ctx)) == NULL) { + deflate_free(ctx); + return NULL; + } + + return s2; +} + + +static zip_int64_t +compress_read(zip_source_t *src, struct deflate *ctx, void *data, zip_uint64_t len) +{ + int end, ret; + zip_int64_t n; + zip_uint64_t out_offset; + uInt out_len; + + if (zip_error_code_zip(&ctx->error) != ZIP_ER_OK) + return -1; + + if (len == 0 || ctx->is_stored) { + return 0; + } + + out_offset = 0; + out_len = (uInt)ZIP_MIN(UINT_MAX, len); + ctx->zstr.next_out = (Bytef *)data; + ctx->zstr.avail_out = out_len; + + end = 0; + while (!end) { + ret = deflate(&ctx->zstr, ctx->eof ? Z_FINISH : 0); + + switch (ret) { + case Z_STREAM_END: + if (ctx->can_store && ctx->zstr.total_in <= ctx->zstr.total_out) { + ctx->is_stored = true; + ctx->size = ctx->zstr.total_in; + memcpy(data, ctx->buffer, ctx->size); + return (zip_int64_t)ctx->size; + } + /* fallthrough */ + case Z_OK: + /* all ok */ + + if (ctx->zstr.avail_out == 0) { + out_offset += out_len; + if (out_offset < len) { + out_len = (uInt)ZIP_MIN(UINT_MAX, len-out_offset); + ctx->zstr.next_out = (Bytef *)data+out_offset; + ctx->zstr.avail_out = out_len; + } + else { + ctx->can_store = false; + end = 1; + } + } + else if (ctx->eof && ctx->zstr.avail_in == 0) + end = 1; + break; + + case Z_BUF_ERROR: + if (ctx->zstr.avail_in == 0) { + if (ctx->eof) { + end = 1; + break; + } + + if ((n=zip_source_read(src, ctx->buffer, sizeof(ctx->buffer))) < 0) { + _zip_error_set_from_source(&ctx->error, src); + end = 1; + break; + } + else if (n == 0) { + ctx->eof = true; + /* TODO: check against stat of src? */ + ctx->size = ctx->zstr.total_in; + } + else { + if (ctx->zstr.total_in > 0) { + /* we overwrote a previously filled ctx->buffer */ + ctx->can_store = false; + } + ctx->zstr.next_in = (Bytef *)ctx->buffer; + ctx->zstr.avail_in = (uInt)n; + } + continue; + } + /* fallthrough */ + case Z_NEED_DICT: + case Z_DATA_ERROR: + case Z_STREAM_ERROR: + case Z_MEM_ERROR: + zip_error_set(&ctx->error, ZIP_ER_ZLIB, ret); + + end = 1; + break; + } + } + + if (ctx->zstr.avail_out < len) { + ctx->can_store = false; + return (zip_int64_t)(len - ctx->zstr.avail_out); + } + + return (zip_error_code_zip(&ctx->error) == ZIP_ER_OK) ? 0 : -1; +} + + +static zip_int64_t +decompress_read(zip_source_t *src, struct deflate *ctx, void *data, zip_uint64_t len) +{ + int end, ret; + zip_int64_t n; + zip_uint64_t out_offset; + uInt out_len; + + if (zip_error_code_zip(&ctx->error) != ZIP_ER_OK) + return -1; + + if (len == 0) + return 0; + + out_offset = 0; + out_len = (uInt)ZIP_MIN(UINT_MAX, len); + ctx->zstr.next_out = (Bytef *)data; + ctx->zstr.avail_out = out_len; + + end = 0; + while (!end) { + ret = inflate(&ctx->zstr, Z_SYNC_FLUSH); + + switch (ret) { + case Z_OK: + if (ctx->zstr.avail_out == 0) { + out_offset += out_len; + if (out_offset < len) { + out_len = (uInt)ZIP_MIN(UINT_MAX, len-out_offset); + ctx->zstr.next_out = (Bytef *)data+out_offset; + ctx->zstr.avail_out = out_len; + } + else { + end = 1; + } + } + break; + + case Z_STREAM_END: + ctx->eof = 1; + end = 1; + break; + + case Z_BUF_ERROR: + if (ctx->zstr.avail_in == 0) { + if (ctx->eof) { + end = 1; + break; + } + + if ((n=zip_source_read(src, ctx->buffer, sizeof(ctx->buffer))) < 0) { + _zip_error_set_from_source(&ctx->error, src); + end = 1; + break; + } + else if (n == 0) { + ctx->eof = 1; + } + else { + ctx->zstr.next_in = (Bytef *)ctx->buffer; + ctx->zstr.avail_in = (uInt)n; + } + continue; + } + /* fallthrough */ + case Z_NEED_DICT: + case Z_DATA_ERROR: + case Z_STREAM_ERROR: + case Z_MEM_ERROR: + zip_error_set(&ctx->error, ZIP_ER_ZLIB, ret); + end = 1; + break; + } + } + + if (ctx->zstr.avail_out < len) + return (zip_int64_t)(len - ctx->zstr.avail_out); + + return (zip_error_code_zip(&ctx->error) == ZIP_ER_OK) ? 0 : -1; +} + + +static zip_int64_t +deflate_compress(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip_source_cmd_t cmd) +{ + struct deflate *ctx; + int ret; + + ctx = (struct deflate *)ud; + + switch (cmd) { + case ZIP_SOURCE_OPEN: + ctx->zstr.zalloc = Z_NULL; + ctx->zstr.zfree = Z_NULL; + ctx->zstr.opaque = NULL; + ctx->zstr.avail_in = 0; + ctx->zstr.next_in = NULL; + ctx->zstr.avail_out = 0; + ctx->zstr.next_out = NULL; + + /* negative value to tell zlib not to write a header */ + if ((ret=deflateInit2(&ctx->zstr, Z_BEST_COMPRESSION, Z_DEFLATED, -MAX_WBITS, ctx->mem_level, Z_DEFAULT_STRATEGY)) != Z_OK) { + zip_error_set(&ctx->error, ZIP_ER_ZLIB, ret); + return -1; + } + + return 0; + + case ZIP_SOURCE_READ: + return compress_read(src, ctx, data, len); + + case ZIP_SOURCE_CLOSE: + deflateEnd(&ctx->zstr); + return 0; + + case ZIP_SOURCE_STAT: + { + zip_stat_t *st; + + st = (zip_stat_t *)data; + + st->comp_method = ctx->is_stored ? ZIP_CM_STORE : ZIP_CM_DEFLATE; + st->valid |= ZIP_STAT_COMP_METHOD; + if (ctx->eof) { + st->comp_size = ctx->size; + st->valid |= ZIP_STAT_COMP_SIZE; + } + else + st->valid &= ~ZIP_STAT_COMP_SIZE; + } + return 0; + + case ZIP_SOURCE_ERROR: + return zip_error_to_data(&ctx->error, data, len); + + case ZIP_SOURCE_FREE: + deflate_free(ctx); + return 0; + + case ZIP_SOURCE_SUPPORTS: + return ZIP_SOURCE_SUPPORTS_READABLE; + + default: + zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0); + return -1; + } +} + + +static zip_int64_t +deflate_decompress(zip_source_t *src, void *ud, void *data, + zip_uint64_t len, zip_source_cmd_t cmd) +{ + struct deflate *ctx; + zip_int64_t n; + int ret; + + ctx = (struct deflate *)ud; + + switch (cmd) { + case ZIP_SOURCE_OPEN: + if ((n=zip_source_read(src, ctx->buffer, sizeof(ctx->buffer))) < 0) { + _zip_error_set_from_source(&ctx->error, src); + return -1; + } + + ctx->zstr.zalloc = Z_NULL; + ctx->zstr.zfree = Z_NULL; + ctx->zstr.opaque = NULL; + ctx->zstr.next_in = (Bytef *)ctx->buffer; + ctx->zstr.avail_in = (uInt)n; + + /* negative value to tell zlib that there is no header */ + if ((ret=inflateInit2(&ctx->zstr, -MAX_WBITS)) != Z_OK) { + zip_error_set(&ctx->error, ZIP_ER_ZLIB, ret); + return -1; + } + return 0; + + case ZIP_SOURCE_READ: + return decompress_read(src, ctx, data, len); + + case ZIP_SOURCE_CLOSE: + inflateEnd(&ctx->zstr); + return 0; + + case ZIP_SOURCE_STAT: + { + zip_stat_t *st; + + st = (zip_stat_t *)data; + + st->comp_method = ZIP_CM_STORE; + if (st->comp_size > 0 && st->size > 0) + st->comp_size = st->size; + + return 0; + } + + case ZIP_SOURCE_ERROR: + return zip_error_to_data(&ctx->error, data, len); + + case ZIP_SOURCE_FREE: + free(ctx); + return 0; + + case ZIP_SOURCE_SUPPORTS: + return zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, -1); + + default: + zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0); + return -1; + } +} + + +static void +deflate_free(struct deflate *ctx) +{ + free(ctx); +} diff --git a/ePub3/ThirdParty/libzip/zip_ftell.c b/ePub3/ThirdParty/libzip/zip_source_error.c similarity index 84% rename from ePub3/ThirdParty/libzip/zip_ftell.c rename to ePub3/ThirdParty/libzip/zip_source_error.c index 29b4f0742..e09199bbe 100644 --- a/ePub3/ThirdParty/libzip/zip_ftell.c +++ b/ePub3/ThirdParty/libzip/zip_source_error.c @@ -1,7 +1,6 @@ /* - zip_ftell.c -- obtain location in file within zip archive - Copyright (C) 1999-2013 Dieter Baron and Thomas Klausner - Original implementation contributed by Jim Dovey. + zip_source_error.c -- get last error from zip_source + Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -32,13 +31,12 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + #include "zipint.h" -ZIP_EXTERN long -zip_ftell(struct zip_file* zf) + +zip_error_t * +zip_source_error(zip_source_t *src) { - if (!zf) - return -1; - - return zf->file_fpos; + return &src->error; } diff --git a/ePub3/ThirdParty/libzip/zip_source_file.c b/ePub3/ThirdParty/libzip/zip_source_file.c index eb1129a27..1465e1700 100644 --- a/ePub3/ThirdParty/libzip/zip_source_file.c +++ b/ePub3/ThirdParty/libzip/zip_source_file.c @@ -1,6 +1,6 @@ /* zip_source_file.c -- create data source from file - Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,25 +31,30 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include #include "zipint.h" - -ZIP_EXTERN struct zip_source * -zip_source_file(struct zip *za, const char *fname, off_t start, off_t len) +ZIP_EXTERN zip_source_t * +zip_source_file(zip_t *za, const char *fname, zip_uint64_t start, zip_int64_t len) { if (za == NULL) return NULL; + + return zip_source_file_create(fname, start, len, &za->error); +} + - if (fname == NULL || start < 0 || len < -1) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); +ZIP_EXTERN zip_source_t * +zip_source_file_create(const char *fname, zip_uint64_t start, zip_int64_t length, zip_error_t *error) +{ + if (fname == NULL || length < -1) { + zip_error_set(error, ZIP_ER_INVAL, 0); return NULL; } - return _zip_source_file_or_p(za, fname, NULL, start, len); + return _zip_source_file_or_p(fname, NULL, start, length, NULL, error); } diff --git a/ePub3/ThirdParty/libzip/zip_source_filep.c b/ePub3/ThirdParty/libzip/zip_source_filep.c index 41f1047dd..7fbf88eaf 100644 --- a/ePub3/ThirdParty/libzip/zip_source_filep.c +++ b/ePub3/ThirdParty/libzip/zip_source_filep.c @@ -1,6 +1,6 @@ /* zip_source_filep.c -- create data source from FILE * - Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,7 +31,8 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - + +#include "zipint.h" #include #include @@ -39,185 +40,462 @@ #include #include -#include "zipint.h" +#ifdef _WIN32 +/* WIN32 needs for _O_BINARY */ +#include +#endif -#if defined(_MSC_VER) -# define strdup _strdup -# define fseeko fseek -# define ftello ftell -# define fileno _fileno +/* Windows sys/types.h does not provide these */ +#ifndef S_ISREG +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#endif +#if defined(S_IXUSR) && defined(S_IRWXG) && defined(S_IRWXO) +#define _SAFE_MASK (S_IXUSR | S_IRWXG | S_IRWXO) +#elif defined(_S_IWRITE) +#define _SAFE_MASK (_S_IWRITE) +#else +#error do not know safe values for umask, please report this +#endif + +#ifdef _MSC_VER +/* MSVC doesn't have mode_t */ +typedef int mode_t; #endif struct read_file { - char *fname; /* name of file to copy from */ - FILE *f; /* file to copy from */ - off_t off; /* start offset of */ - off_t len; /* lengt of data to copy */ - off_t remain; /* bytes remaining to be copied */ - int e[2]; /* error codes */ + zip_error_t error; /* last error information */ + zip_int64_t supports; + + /* reading */ + char *fname; /* name of file to read from */ + FILE *f; /* file to read from */ + struct zip_stat st; /* stat information passed in */ + zip_uint64_t start; /* start offset of data to read */ + zip_uint64_t end; /* end offset of data to read, 0 for up to EOF */ + zip_uint64_t current; /* current offset */ + + /* writing */ + char *tmpname; + FILE *fout; }; -static ssize_t read_file(void *state, void *data, size_t len, - enum zip_source_cmd cmd); +static zip_int64_t read_file(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd); +static int create_temp_output(struct read_file *ctx); +static int _zip_fseek_u(FILE *f, zip_uint64_t offset, int whence, zip_error_t *error); +static int _zip_fseek(FILE *f, zip_int64_t offset, int whence, zip_error_t *error); - -ZIP_EXTERN struct zip_source * -zip_source_filep(struct zip *za, FILE *file, off_t start, off_t len) +ZIP_EXTERN zip_source_t * +zip_source_filep(zip_t *za, FILE *file, zip_uint64_t start, zip_int64_t len) { if (za == NULL) return NULL; + + return zip_source_filep_create(file, start, len, &za->error); +} + - if (file == NULL || start < 0 || len < -1) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); +ZIP_EXTERN zip_source_t * +zip_source_filep_create(FILE *file, zip_uint64_t start, zip_int64_t length, zip_error_t *error) +{ + if (file == NULL || length < -1) { + zip_error_set(error, ZIP_ER_INVAL, 0); return NULL; } - return _zip_source_file_or_p(za, NULL, file, start, len); + return _zip_source_file_or_p(NULL, file, start, length, NULL, error); } - -struct zip_source * -_zip_source_file_or_p(struct zip *za, const char *fname, FILE *file, - off_t start, off_t len) +zip_source_t * +_zip_source_file_or_p(const char *fname, FILE *file, zip_uint64_t start, zip_int64_t len, const zip_stat_t *st, zip_error_t *error) { - struct read_file *f; - struct zip_source *zs; - + struct read_file *ctx; + zip_source_t *zs; + if (file == NULL && fname == NULL) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); + zip_error_set(error, ZIP_ER_INVAL, 0); return NULL; } - - if ((f=(struct read_file *)malloc(sizeof(struct read_file))) == NULL) { - _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + + if ((ctx=(struct read_file *)malloc(sizeof(struct read_file))) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); return NULL; } - f->fname = NULL; + ctx->fname = NULL; if (fname) { - if ((f->fname=strdup(fname)) == NULL) { - _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); - free(f); + if ((ctx->fname=strdup(fname)) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + free(ctx); return NULL; } } - f->f = file; - f->off = start; - f->len = (len ? len : -1); + ctx->f = file; + ctx->start = start; + ctx->end = (len < 0 ? 0 : start+(zip_uint64_t)len); + if (st) { + memcpy(&ctx->st, st, sizeof(ctx->st)); + ctx->st.name = NULL; + ctx->st.valid &= ~ZIP_STAT_NAME; + } + else { + zip_stat_init(&ctx->st); + } - if ((zs=zip_source_function(za, read_file, f)) == NULL) { - free(f); + ctx->tmpname = NULL; + ctx->fout = NULL; + + zip_error_init(&ctx->error); + + ctx->supports = ZIP_SOURCE_SUPPORTS_READABLE | zip_source_make_command_bitmap(ZIP_SOURCE_SUPPORTS, ZIP_SOURCE_TELL, -1); + if (ctx->fname) { + struct stat sb; + + if (stat(ctx->fname, &sb) < 0 || S_ISREG(sb.st_mode)) { + ctx->supports = ZIP_SOURCE_SUPPORTS_WRITABLE; + } + } + else if (fseeko(ctx->f, 0, SEEK_CUR) == 0) { + ctx->supports = ZIP_SOURCE_SUPPORTS_SEEKABLE; + } + + if ((zs=zip_source_function_create(read_file, ctx, error)) == NULL) { + free(ctx->fname); + free(ctx); return NULL; } return zs; } - -static ssize_t -read_file(void *state, void *data, size_t len, enum zip_source_cmd cmd) +static int +create_temp_output(struct read_file *ctx) { - struct read_file *z; + char *temp; + int tfd; + mode_t mask; + FILE *tfp; + + if ((temp=(char *)malloc(strlen(ctx->fname)+8)) == NULL) { + zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0); + return -1; + } + sprintf(temp, "%s.XXXXXX", ctx->fname); + + mask = umask(_SAFE_MASK); + if ((tfd=mkstemp(temp)) == -1) { + zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno); + umask(mask); + free(temp); + return -1; + } + umask(mask); + + if ((tfp=fdopen(tfd, "r+b")) == NULL) { + zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno); + close(tfd); + (void)remove(temp); + free(temp); + return -1; + } + +#ifdef _WIN32 + /* + According to Pierre Joye, Windows in some environments per + default creates text files, so force binary mode. + */ + _setmode(_fileno(tfp), _O_BINARY ); +#endif + + ctx->fout = tfp; + ctx->tmpname = temp; + + return 0; +} + + +static zip_int64_t +read_file(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd) +{ + struct read_file *ctx; char *buf; - ssize_t i, n; + zip_uint64_t n; + size_t i; - z = (struct read_file *)state; + ctx = (struct read_file *)state; buf = (char *)data; switch (cmd) { - case ZIP_SOURCE_OPEN: - if (z->fname) { - if ((z->f=fopen(z->fname, "rb")) == NULL) { - z->e[0] = ZIP_ER_OPEN; - z->e[1] = errno; - return -1; - } - } - - if (fseeko(z->f, z->off, SEEK_SET) < 0) { - z->e[0] = ZIP_ER_SEEK; - z->e[1] = errno; - return -1; - } - z->remain = z->len; - return 0; - - case ZIP_SOURCE_READ: - if (z->remain != -1) - n = len > (size_t)(z->remain) ? (ssize_t)z->remain : (ssize_t)len; - else - n = (ssize_t)len; - - if ((i=(ssize_t)fread(buf, 1, n, z->f)) < 0) { - z->e[0] = ZIP_ER_READ; - z->e[1] = errno; - return -1; + case ZIP_SOURCE_BEGIN_WRITE: + if (ctx->fname == NULL) { + zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0); + return -1; + } + return create_temp_output(ctx); + + case ZIP_SOURCE_COMMIT_WRITE: { + mode_t mask; + + if (fclose(ctx->fout) < 0) { + ctx->fout = NULL; + zip_error_set(&ctx->error, ZIP_ER_WRITE, errno); + } + ctx->fout = NULL; + if (rename(ctx->tmpname, ctx->fname) < 0) { + zip_error_set(&ctx->error, ZIP_ER_RENAME, errno); + return -1; + } + mask = umask(022); + umask(mask); + /* not much we can do if chmod fails except make the whole commit fail */ + (void)chmod(ctx->fname, 0666&~mask); + free(ctx->tmpname); + ctx->tmpname = NULL; + return 0; } - - if (z->remain != -1) - z->remain -= i; - - return i; + + case ZIP_SOURCE_CLOSE: + if (ctx->fname) { + fclose(ctx->f); + ctx->f = NULL; + } + return 0; + + case ZIP_SOURCE_ERROR: + return zip_error_to_data(&ctx->error, data, len); + + case ZIP_SOURCE_FREE: + free(ctx->fname); + free(ctx->tmpname); + if (ctx->f) + fclose(ctx->f); + free(ctx); + return 0; + + case ZIP_SOURCE_OPEN: + if (ctx->fname) { + if ((ctx->f=fopen(ctx->fname, "rb")) == NULL) { + zip_error_set(&ctx->error, ZIP_ER_OPEN, errno); + return -1; + } + } + + if (ctx->start > 0) { + if (_zip_fseek_u(ctx->f, ctx->start, SEEK_SET, &ctx->error) < 0) { + return -1; + } + } + ctx->current = ctx->start; + return 0; + + case ZIP_SOURCE_READ: + if (ctx->end > 0) { + n = ctx->end-ctx->current; + if (n > len) { + n = len; + } + } + else { + n = len; + } + + if (n > SIZE_MAX) + n = SIZE_MAX; + + if ((i=fread(buf, 1, (size_t)n, ctx->f)) == 0) { + if (ferror(ctx->f)) { + zip_error_set(&ctx->error, ZIP_ER_READ, errno); + return -1; + } + } + ctx->current += i; + + return (zip_int64_t)i; + + case ZIP_SOURCE_REMOVE: + if (remove(ctx->fname) < 0) { + zip_error_set(&ctx->error, ZIP_ER_REMOVE, errno); + return -1; + } + return 0; + + case ZIP_SOURCE_ROLLBACK_WRITE: + if (ctx->fout) { + fclose(ctx->fout); + ctx->fout = NULL; + } + (void)remove(ctx->tmpname); + free(ctx->tmpname); + ctx->tmpname = NULL; + return 0; - case ZIP_SOURCE_CLOSE: - if (z->fname) { - fclose(z->f); - z->f = NULL; - } - return 0; + case ZIP_SOURCE_SEEK: { + zip_int64_t new_current; + int need_seek; + zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error); - case ZIP_SOURCE_STAT: - { - struct zip_stat *st; - struct stat fst; - int err; - - if (len < sizeof(*st)) + if (args == NULL) return -1; - - if (z->f) - err = fstat(fileno(z->f), &fst); - else - err = stat(z->fname, &fst); - - if (err != 0) { - z->e[0] = ZIP_ER_READ; /* best match */ - z->e[1] = errno; + + need_seek = 1; + + switch (args->whence) { + case SEEK_SET: + new_current = args->offset; + break; + + case SEEK_END: + if (ctx->end == 0) { + if (_zip_fseek(ctx->f, args->offset, SEEK_END, &ctx->error) < 0) { + return -1; + } + if ((new_current = ftello(ctx->f)) < 0) { + zip_error_set(&ctx->error, ZIP_ER_SEEK, errno); + return -1; + } + need_seek = 0; + } + else { + new_current = (zip_int64_t)ctx->end + args->offset; + } + break; + case SEEK_CUR: + new_current = (zip_int64_t)ctx->current + args->offset; + break; + + default: + zip_error_set(&ctx->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (new_current < 0 || (zip_uint64_t)new_current < ctx->start || (ctx->end != 0 && (zip_uint64_t)new_current > ctx->end)) { + zip_error_set(&ctx->error, ZIP_ER_INVAL, 0); + return -1; + } + + ctx->current = (zip_uint64_t)new_current; + + if (need_seek) { + if (_zip_fseek_u(ctx->f, ctx->current, SEEK_SET, &ctx->error) < 0) { + return -1; + } + } + return 0; + } + + case ZIP_SOURCE_SEEK_WRITE: { + zip_source_args_seek_t *args; + + args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error); + if (args == NULL) { + return -1; + } + + if (_zip_fseek(ctx->fout, args->offset, args->whence, &ctx->error) < 0) { + return -1; + } + return 0; + } + + case ZIP_SOURCE_STAT: { + if (len < sizeof(ctx->st)) return -1; - } - - st = (struct zip_stat *)data; - - zip_stat_init(st); - st->mtime = fst.st_mtime; - if (z->len != -1) - st->size = z->len; - else if ((fst.st_mode&S_IFMT) == S_IFREG) - st->size = fst.st_size; - return sizeof(*st); + if (ctx->st.valid != 0) + memcpy(data, &ctx->st, sizeof(ctx->st)); + else { + zip_stat_t *st; + struct stat fst; + int err; + + if (ctx->f) + err = fstat(fileno(ctx->f), &fst); + else + err = stat(ctx->fname, &fst); + + if (err != 0) { + zip_error_set(&ctx->error, ZIP_ER_READ, errno); + return -1; + } + + st = (zip_stat_t *)data; + + zip_stat_init(st); + st->mtime = fst.st_mtime; + st->valid |= ZIP_STAT_MTIME; + if (ctx->end != 0) { + st->size = ctx->end - ctx->start; + st->valid |= ZIP_STAT_SIZE; + } + else if ((fst.st_mode&S_IFMT) == S_IFREG) { + st->size = (zip_uint64_t)fst.st_size; + st->valid |= ZIP_STAT_SIZE; + } + } + return sizeof(ctx->st); } - case ZIP_SOURCE_ERROR: - if (len < sizeof(int)*2) - return -1; - - memcpy(data, z->e, sizeof(int)*2); - return sizeof(int)*2; + case ZIP_SOURCE_SUPPORTS: + return ctx->supports; + + case ZIP_SOURCE_TELL: + return (zip_int64_t)ctx->current; + + case ZIP_SOURCE_TELL_WRITE: + { + off_t ret = ftello(ctx->fout); + + if (ret < 0) { + zip_error_set(&ctx->error, ZIP_ER_TELL, errno); + return -1; + } + return ret; + } + + case ZIP_SOURCE_WRITE: + { + size_t ret; + + clearerr(ctx->fout); + ret = fwrite(data, 1, len, ctx->fout); + if (ret != len || ferror(ctx->fout)) { + zip_error_set(&ctx->error, ZIP_ER_WRITE, errno); + return -1; + } + + return (zip_int64_t)ret; + } + + default: + zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0); + return -1; + } +} - case ZIP_SOURCE_FREE: - free(z->fname); - if (z->f) - fclose(z->f); - free(z); - return 0; - default: - ; +static int +_zip_fseek_u(FILE *f, zip_uint64_t offset, int whence, zip_error_t *error) +{ + if (offset > ZIP_INT64_MAX) { + zip_error_set(error, ZIP_ER_SEEK, EOVERFLOW); + return -1; } + return _zip_fseek(f, (zip_int64_t)offset, whence, error); +} + - return -1; +static int +_zip_fseek(FILE *f, zip_int64_t offset, int whence, zip_error_t *error) +{ + //if (offset > ZIP_FSEEK_MAX || offset < ZIP_FSEEK_MIN) { + //zip_error_set(error, ZIP_ER_SEEK, EOVERFLOW); + //return -1; + //} + if (fseeko(f, (off_t)offset, whence) < 0) { + zip_error_set(error, ZIP_ER_SEEK, errno); + return -1; + } + return 0; } diff --git a/ePub3/ThirdParty/libzip/zip_source_free.c b/ePub3/ThirdParty/libzip/zip_source_free.c index 7a1632fbf..907046994 100644 --- a/ePub3/ThirdParty/libzip/zip_source_free.c +++ b/ePub3/ThirdParty/libzip/zip_source_free.c @@ -1,6 +1,6 @@ /* zip_source_free.c -- free zip data source - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,21 +31,42 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include "zipint.h" - ZIP_EXTERN void -zip_source_free(struct zip_source *source) +zip_source_free(zip_source_t *src) { - if (source == NULL) + if (src == NULL) return; - (void)source->f(source->ud, NULL, 0, ZIP_SOURCE_FREE); + if (src->refcount > 0) { + src->refcount--; + } + if (src->refcount > 0) { + return; + } + + if (ZIP_SOURCE_IS_OPEN_READING(src)) { + src->open_count = 1; /* force close */ + zip_source_close(src); + } + if (ZIP_SOURCE_IS_OPEN_WRITING(src)) { + zip_source_rollback_write(src); + } + + if (src->source_archive && !src->source_closed) { + _zip_deregister_source(src->source_archive, src); + } + + (void)_zip_source_call(src, NULL, 0, ZIP_SOURCE_FREE); + + if (src->src) { + zip_source_free(src->src); + } - free(source); + free(src); } diff --git a/ePub3/ThirdParty/libzip/zip_source_function.c b/ePub3/ThirdParty/libzip/zip_source_function.c index 91b183cb6..1d4be93c6 100644 --- a/ePub3/ThirdParty/libzip/zip_source_function.c +++ b/ePub3/ThirdParty/libzip/zip_source_function.c @@ -1,6 +1,6 @@ /* zip_source_function.c -- create zip data source from callback function - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,29 +31,69 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include "zipint.h" - -ZIP_EXTERN struct zip_source * -zip_source_function(struct zip *za, zip_source_callback zcb, void *ud) +ZIP_EXTERN zip_source_t * +zip_source_function(zip_t *za, zip_source_callback zcb, void *ud) { - struct zip_source *zs; + if (za == NULL) { + return NULL; + } + + return zip_source_function_create(zcb, ud, &za->error); +} - if (za == NULL) - return NULL; - if ((zs=(struct zip_source *)malloc(sizeof(*zs))) == NULL) { - _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); +ZIP_EXTERN zip_source_t * +zip_source_function_create(zip_source_callback zcb, void *ud, zip_error_t *error) +{ + zip_source_t *zs; + + if ((zs=_zip_source_new(error)) == NULL) return NULL; - } - zs->f = zcb; + zs->cb.f = zcb; zs->ud = ud; + zs->supports = zcb(ud, NULL, 0, ZIP_SOURCE_SUPPORTS); + if (zs->supports < 0) { + zs->supports = ZIP_SOURCE_SUPPORTS_READABLE; + } + return zs; } + + +ZIP_EXTERN void +zip_source_keep(zip_source_t *src) +{ + src->refcount++; +} + + +zip_source_t * +_zip_source_new(zip_error_t *error) +{ + zip_source_t *src; + + if ((src=(zip_source_t *)malloc(sizeof(*src))) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + return NULL; + } + + src->src = NULL; + src->cb.f = NULL; + src->ud = NULL; + src->open_count = 0; + src->write_state = ZIP_SOURCE_WRITE_CLOSED; + src->source_closed = false; + src->source_archive = NULL; + src->refcount = 1; + zip_error_init(&src->error); + + return src; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_is_deleted.c b/ePub3/ThirdParty/libzip/zip_source_is_deleted.c new file mode 100644 index 000000000..e50cdd9e3 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_is_deleted.c @@ -0,0 +1,42 @@ +/* + zip_source_is_deleted.c -- was archive was removed? + Copyright (C) 2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +ZIP_EXTERN int +zip_source_is_deleted(zip_source_t *src) +{ + return src->write_state == ZIP_SOURCE_WRITE_REMOVED; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_layered.c b/ePub3/ThirdParty/libzip/zip_source_layered.c new file mode 100644 index 000000000..94b331010 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_layered.c @@ -0,0 +1,69 @@ +/* + zip_source_layered.c -- create layered source + Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include + +#include "zipint.h" + + +zip_source_t * +zip_source_layered(zip_t *za, zip_source_t *src, zip_source_layered_callback cb, void *ud) +{ + if (za == NULL) + return NULL; + + return zip_source_layered_create(src, cb, ud, &za->error); +} + + +zip_source_t * +zip_source_layered_create(zip_source_t *src, zip_source_layered_callback cb, void *ud, zip_error_t *error) +{ + zip_source_t *zs; + + if ((zs=_zip_source_new(error)) == NULL) + return NULL; + + zip_source_keep(src); + zs->src = src; + zs->cb.l = cb; + zs->ud = ud; + + zs->supports = cb(src, ud, NULL, 0, ZIP_SOURCE_SUPPORTS); + if (zs->supports < 0) { + zs->supports = ZIP_SOURCE_SUPPORTS_READABLE; + } + + return zs; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_open.c b/ePub3/ThirdParty/libzip/zip_source_open.c new file mode 100644 index 000000000..ec5e39d54 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_open.c @@ -0,0 +1,73 @@ +/* + zip_source_open.c -- open zip_source (prepare for reading) + Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + +ZIP_EXTERN int +zip_source_open(zip_source_t *src) +{ + if (src->source_closed) { + return -1; + } + if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) { + zip_error_set(&src->error, ZIP_ER_DELETED, 0); + return -1; + } + + if (ZIP_SOURCE_IS_OPEN_READING(src)) { + if ((zip_source_supports(src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK)) == 0) { + zip_error_set(&src->error, ZIP_ER_INUSE, 0); + return -1; + } + } + else { + if (ZIP_SOURCE_IS_LAYERED(src)) { + if (zip_source_open(src->src) < 0) { + _zip_error_set_from_source(&src->error, src->src); + return -1; + } + } + + if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_OPEN) < 0) { + if (ZIP_SOURCE_IS_LAYERED(src)) { + zip_source_close(src->src); + } + return -1; + } + } + + src->open_count++; + + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_pkware.c b/ePub3/ThirdParty/libzip/zip_source_pkware.c new file mode 100644 index 000000000..ee52fc1be --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_pkware.c @@ -0,0 +1,226 @@ +/* + zip_source_pkware.c -- Traditional PKWARE de/encryption routines + Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include +#include + +#include "zipint.h" + +struct trad_pkware { + zip_error_t error; + zip_uint32_t key[3]; +}; + +#define HEADERLEN 12 +#define KEY0 305419896 +#define KEY1 591751049 +#define KEY2 878082192 + + +static void decrypt(struct trad_pkware *, zip_uint8_t *, + const zip_uint8_t *, zip_uint64_t, int); +static int decrypt_header(zip_source_t *, struct trad_pkware *); +static zip_int64_t pkware_decrypt(zip_source_t *, void *, void *, + zip_uint64_t, zip_source_cmd_t); +static void pkware_free(struct trad_pkware *); + + +zip_source_t * +zip_source_pkware(zip_t *za, zip_source_t *src, + zip_uint16_t em, int flags, const char *password) +{ + struct trad_pkware *ctx; + zip_source_t *s2; + + if (password == NULL || src == NULL || em != ZIP_EM_TRAD_PKWARE) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return NULL; + } + if (flags & ZIP_CODEC_ENCODE) { + zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0); + return NULL; + } + + if ((ctx=(struct trad_pkware *)malloc(sizeof(*ctx))) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return NULL; + } + + zip_error_init(&ctx->error); + + ctx->key[0] = KEY0; + ctx->key[1] = KEY1; + ctx->key[2] = KEY2; + decrypt(ctx, NULL, (const zip_uint8_t *)password, strlen(password), 1); + + if ((s2=zip_source_layered(za, src, pkware_decrypt, ctx)) == NULL) { + pkware_free(ctx); + return NULL; + } + + return s2; +} + + +static void +decrypt(struct trad_pkware *ctx, zip_uint8_t *out, const zip_uint8_t *in, + zip_uint64_t len, int update_only) +{ + zip_uint16_t tmp; + zip_uint64_t i; + Bytef b; + + for (i=0; ikey[2] | 2); + tmp = (zip_uint16_t)(((zip_uint32_t)tmp * (tmp ^ 1)) >> 8); + b ^= (Bytef)tmp; + } + + /* store cleartext */ + if (out) + out[i] = b; + + /* update keys */ + ctx->key[0] = (zip_uint32_t)crc32(ctx->key[0] ^ 0xffffffffUL, &b, 1) ^ 0xffffffffUL; + ctx->key[1] = (ctx->key[1] + (ctx->key[0] & 0xff)) * 134775813 + 1; + b = (Bytef)(ctx->key[1] >> 24); + ctx->key[2] = (zip_uint32_t)crc32(ctx->key[2] ^ 0xffffffffUL, &b, 1) ^ 0xffffffffUL; + } +} + + +static int +decrypt_header(zip_source_t *src, struct trad_pkware *ctx) +{ + zip_uint8_t header[HEADERLEN]; + struct zip_stat st; + zip_int64_t n; + unsigned short dostime, dosdate; + + if ((n=zip_source_read(src, header, HEADERLEN)) < 0) { + _zip_error_set_from_source(&ctx->error, src); + return -1; + } + + if (n != HEADERLEN) { + zip_error_set(&ctx->error, ZIP_ER_EOF, 0); + return -1; + } + + decrypt(ctx, header, header, HEADERLEN, 0); + + if (zip_source_stat(src, &st) < 0) { + /* stat failed, skip password validation */ + return 0; + } + + _zip_u2d_time(st.mtime, &dostime, &dosdate); + + if (header[HEADERLEN-1] != st.crc>>24 && header[HEADERLEN-1] != dostime>>8) { + zip_error_set(&ctx->error, ZIP_ER_WRONGPASSWD, 0); + return -1; + } + + return 0; +} + + +static zip_int64_t +pkware_decrypt(zip_source_t *src, void *ud, void *data, + zip_uint64_t len, zip_source_cmd_t cmd) +{ + struct trad_pkware *ctx; + zip_int64_t n; + + ctx = (struct trad_pkware *)ud; + + switch (cmd) { + case ZIP_SOURCE_OPEN: + if (decrypt_header(src, ctx) < 0) + return -1; + return 0; + + case ZIP_SOURCE_READ: + if ((n=zip_source_read(src, data, len)) < 0) { + _zip_error_set_from_source(&ctx->error, src); + return -1; + } + + decrypt((struct trad_pkware *)ud, (zip_uint8_t *)data, (zip_uint8_t *)data, (zip_uint64_t)n, 0); + return n; + + case ZIP_SOURCE_CLOSE: + return 0; + + case ZIP_SOURCE_STAT: + { + zip_stat_t *st; + + st = (zip_stat_t *)data; + + st->encryption_method = ZIP_EM_NONE; + st->valid |= ZIP_STAT_ENCRYPTION_METHOD; + /* TODO: deduce HEADERLEN from size for uncompressed */ + if (st->valid & ZIP_STAT_COMP_SIZE) + st->comp_size -= HEADERLEN; + + return 0; + } + + case ZIP_SOURCE_SUPPORTS: + return zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, -1); + + case ZIP_SOURCE_ERROR: + return zip_error_to_data(&ctx->error, data, len); + + case ZIP_SOURCE_FREE: + pkware_free(ctx); + return 0; + + default: + zip_error_set(&ctx->error, ZIP_ER_INVAL, 0); + return -1; + } +} + + +static void +pkware_free(struct trad_pkware *ctx) +{ + free(ctx); +} diff --git a/ePub3/ThirdParty/libzip/zip_source_read.c b/ePub3/ThirdParty/libzip/zip_source_read.c new file mode 100644 index 000000000..061a6f910 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_read.c @@ -0,0 +1,50 @@ +/* + zip_source_read.c -- read data from zip_source + Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +zip_int64_t +zip_source_read(zip_source_t *src, void *data, zip_uint64_t len) +{ + if (src->source_closed) { + return -1; + } + if (!ZIP_SOURCE_IS_OPEN_READING(src) || len > ZIP_INT64_MAX || (len > 0 && data == NULL)) { + zip_error_set(&src->error, ZIP_ER_INVAL, 0); + return -1; + } + + return _zip_source_call(src, data, len, ZIP_SOURCE_READ); +} diff --git a/ePub3/ThirdParty/libzip/zip_source_remove.c b/ePub3/ThirdParty/libzip/zip_source_remove.c new file mode 100644 index 000000000..470a5edaf --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_remove.c @@ -0,0 +1,61 @@ +/* + zip_source_remove.c -- remove empty archive + Copyright (C) 2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "zipint.h" + + +int +zip_source_remove(zip_source_t *src) +{ + if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) { + return 0; + } + + if (ZIP_SOURCE_IS_OPEN_READING(src)) { + if (zip_source_close(src) < 0) { + return -1; + } + } + if (src->write_state != ZIP_SOURCE_WRITE_CLOSED) { + zip_source_rollback_write(src); + } + + if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_REMOVE) < 0) { + return -1; + } + + src->write_state = ZIP_SOURCE_WRITE_REMOVED; + + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_rollback_write.c b/ePub3/ThirdParty/libzip/zip_source_rollback_write.c new file mode 100644 index 000000000..c35f30f95 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_rollback_write.c @@ -0,0 +1,47 @@ +/* + zip_source_rollback_write.c -- discard changes + Copyright (C) 2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +ZIP_EXTERN void +zip_source_rollback_write(zip_source_t *src) +{ + if (src->write_state != ZIP_SOURCE_WRITE_OPEN && src->write_state != ZIP_SOURCE_WRITE_FAILED) { + return; + } + + _zip_source_call(src, NULL, 0, ZIP_SOURCE_ROLLBACK_WRITE); + src->write_state = ZIP_SOURCE_WRITE_CLOSED; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_seek.c b/ePub3/ThirdParty/libzip/zip_source_seek.c new file mode 100644 index 000000000..c3f47036a --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_seek.c @@ -0,0 +1,92 @@ +/* + zip_source_seek.c -- seek to offset + Copyright (C) 2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +ZIP_EXTERN int +zip_source_seek(zip_source_t *src, zip_int64_t offset, int whence) +{ + zip_source_args_seek_t args; + + if (src->source_closed) { + return -1; + } + if (!ZIP_SOURCE_IS_OPEN_READING(src) || (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END)) { + zip_error_set(&src->error, ZIP_ER_INVAL, 0); + return -1; + } + + args.offset = offset; + args.whence = whence; + + return (_zip_source_call(src, &args, sizeof(args), ZIP_SOURCE_SEEK) < 0 ? -1 : 0); +} + + +zip_int64_t +zip_source_seek_compute_offset(zip_uint64_t offset, zip_uint64_t length, void *data, zip_uint64_t data_length, zip_error_t *error) +{ + zip_int64_t new_offset; + zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, data_length, error); + + if (args == NULL) { + return -1; + } + + switch (args->whence) { + case SEEK_CUR: + new_offset = (zip_int64_t)offset + args->offset; + break; + + case SEEK_END: + new_offset = (zip_int64_t)length + args->offset; + break; + + case SEEK_SET: + new_offset = args->offset; + break; + + default: + zip_error_set(error, ZIP_ER_INVAL, 0); + return -1; + } + + if (new_offset < 0 || (zip_uint64_t)new_offset > length) { + zip_error_set(error, ZIP_ER_INVAL, 0); + return -1; + } + + return new_offset; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_seek_write.c b/ePub3/ThirdParty/libzip/zip_source_seek_write.c new file mode 100644 index 000000000..666076649 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_seek_write.c @@ -0,0 +1,52 @@ +/* + zip_source_seek_write.c -- seek to offset for writing + Copyright (C) 2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +ZIP_EXTERN int +zip_source_seek_write(zip_source_t *src, zip_int64_t offset, int whence) +{ + zip_source_args_seek_t args; + + if (!ZIP_SOURCE_IS_OPEN_WRITING(src) || (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END)) { + zip_error_set(&src->error, ZIP_ER_INVAL, 0); + return -1; + } + + args.offset = offset; + args.whence = whence; + + return (_zip_source_call(src, &args, sizeof(args), ZIP_SOURCE_SEEK_WRITE) < 0 ? -1 : 0); +} diff --git a/ePub3/ThirdParty/libzip/zip_source_stat.c b/ePub3/ThirdParty/libzip/zip_source_stat.c new file mode 100644 index 000000000..34cb05f45 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_stat.c @@ -0,0 +1,63 @@ +/* + zip_source_stat.c -- get meta information from zip_source + Copyright (C) 2009-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +int +zip_source_stat(zip_source_t *src, zip_stat_t *st) +{ + if (src->source_closed) { + return -1; + } + if (st == NULL) { + zip_error_set(&src->error, ZIP_ER_INVAL, 0); + return -1; + } + + zip_stat_init(st); + + if (ZIP_SOURCE_IS_LAYERED(src)) { + if (zip_source_stat(src->src, st) < 0) { + _zip_error_set_from_source(&src->error, src->src); + return -1; + } + } + + if (_zip_source_call(src, st, sizeof(*st), ZIP_SOURCE_STAT) < 0) { + return -1; + } + + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_supports.c b/ePub3/ThirdParty/libzip/zip_source_supports.c new file mode 100644 index 000000000..3c100fb71 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_supports.c @@ -0,0 +1,68 @@ +/* + zip_source_supports.c -- check for supported functions + Copyright (C) 2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include + +#include "zipint.h" + + +zip_int64_t +zip_source_supports(zip_source_t *src) +{ + return src->supports; +} + + +zip_int64_t +zip_source_make_command_bitmap(zip_source_cmd_t cmd0, ...) +{ + zip_int64_t bitmap; + va_list ap; + + bitmap = ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd0); + + + + va_start(ap, cmd0); + for (;;) { + int cmd = va_arg(ap, int); + if (cmd < 0) { + break; + } + bitmap |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd); + } + va_end(ap); + + return bitmap; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_tell.c b/ePub3/ThirdParty/libzip/zip_source_tell.c new file mode 100644 index 000000000..f1c10b5b5 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_tell.c @@ -0,0 +1,50 @@ +/* + zip_source_tell.c -- report current offset + Copyright (C) 2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +ZIP_EXTERN zip_int64_t +zip_source_tell(zip_source_t *src) +{ + if (src->source_closed) { + return -1; + } + if (!ZIP_SOURCE_IS_OPEN_READING(src)) { + zip_error_set(&src->error, ZIP_ER_INVAL, 0); + return -1; + } + + return _zip_source_call(src, NULL, 0, ZIP_SOURCE_TELL); +} diff --git a/ePub3/ThirdParty/libzip/zip_source_tell_write.c b/ePub3/ThirdParty/libzip/zip_source_tell_write.c new file mode 100644 index 000000000..2fa150722 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_tell_write.c @@ -0,0 +1,47 @@ +/* + zip_source_tell_write.c -- report current offset for writing + Copyright (C) 2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +ZIP_EXTERN zip_int64_t +zip_source_tell_write(zip_source_t *src) +{ + if (!ZIP_SOURCE_IS_OPEN_WRITING(src)) { + zip_error_set(&src->error, ZIP_ER_INVAL, 0); + return -1; + } + + return _zip_source_call(src, NULL, 0, ZIP_SOURCE_TELL_WRITE); +} diff --git a/ePub3/ThirdParty/libzip/zip_source_win32a.c b/ePub3/ThirdParty/libzip/zip_source_win32a.c new file mode 100644 index 000000000..c20e891b0 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_win32a.c @@ -0,0 +1,125 @@ +/* +zip_source_win32a.c -- create data source from Windows file (ANSI) +Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner + +This file is part of libzip, a library to manipulate ZIP archives. +The authors can be contacted at + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in +the documentation and/or other materials provided with the +distribution. +3. The names of the authors may not be used to endorse or promote +products derived from this software without specific prior +written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include +#include + +#include "zipint.h" +#include "zipwin32.h" + +static void * _win32_strdup_a(const void *str); +static HANDLE _win32_open_a(_zip_source_win32_read_file_t *ctx); +static HANDLE _win32_create_temp_a(_zip_source_win32_read_file_t *ctx, void **temp, zip_uint32_t value, PSECURITY_ATTRIBUTES sa); +static int _win32_rename_temp_a(_zip_source_win32_read_file_t *ctx); +static int _win32_remove_a(const void *fname); + +static _zip_source_win32_file_ops_t win32_ops_a = { + .op_strdup = _win32_strdup_a, + .op_open = _win32_open_a, + .op_create_temp = _win32_create_temp_a, + .op_rename_temp = _win32_rename_temp_a, + .op_remove = _win32_remove_a +}; + +ZIP_EXTERN zip_source_t * +zip_source_win32a(zip_t *za, const char *fname, zip_uint64_t start, zip_int64_t len) +{ + if (za == NULL) + return NULL; + + return zip_source_win32a_create(fname, start, len, &za->error); +} + + +ZIP_EXTERN zip_source_t * +zip_source_win32a_create(const char *fname, zip_uint64_t start, zip_int64_t length, zip_error_t *error) +{ + if (fname == NULL || length < -1) { + zip_error_set(error, ZIP_ER_INVAL, 0); + return NULL; + } + + return _zip_source_win32_handle_or_name(fname, INVALID_HANDLE_VALUE, start, length, 1, NULL, &win32_ops_a, error); +} + + +static void * +_win32_strdup_a(const void *str) +{ + return strdup((const char *)str); +} + + +static HANDLE +_win32_open_a(_zip_source_win32_read_file_t *ctx) +{ + return CreateFileA(ctx->fname, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); +} + + +static HANDLE +_win32_create_temp_a(_zip_source_win32_read_file_t *ctx, void **temp, zip_uint32_t value, PSECURITY_ATTRIBUTES sa) +{ + int len; + + len = strlen((const char *)ctx->fname) + 10; + if (*temp == NULL) { + if ((*temp = malloc(sizeof(char) * len)) == NULL) { + zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0); + return INVALID_HANDLE_VALUE; + } + } + if (sprintf((char *)*temp, "%s.%08x", (const char *)ctx->fname, value) != len - 1) { + return INVALID_HANDLE_VALUE; + } + + return CreateFileA((const char *)*temp, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, sa, CREATE_NEW, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_TEMPORARY, NULL); +} + + +static int +_win32_rename_temp_a(_zip_source_win32_read_file_t *ctx) +{ + if (!MoveFileExA(ctx->tmpname, ctx->fname, MOVEFILE_REPLACE_EXISTING)) + return -1; + return 0; +} + + +static int +_win32_remove_a(const void *fname) +{ + DeleteFileA((const char *)fname); + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_win32handle.c b/ePub3/ThirdParty/libzip/zip_source_win32handle.c new file mode 100644 index 000000000..dd17c021b --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_win32handle.c @@ -0,0 +1,607 @@ +/* +zip_source_win32file.c -- create data source from HANDLE (Win32) +Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner + +This file is part of libzip, a library to manipulate ZIP archives. +The authors can be contacted at + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in +the documentation and/or other materials provided with the +distribution. +3. The names of the authors may not be used to endorse or promote +products derived from this software without specific prior +written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include +#include +#include +#include + +#include "zipint.h" +#include "zipwin32.h" + +static zip_int64_t _win32_read_file(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd); +static int _win32_create_temp_file(_zip_source_win32_read_file_t *ctx); +static int _zip_filetime_to_time_t(FILETIME ft, time_t *t); +static int _zip_seek_win32_u(void *h, zip_uint64_t offset, int whence, zip_error_t *error); +static int _zip_seek_win32(void *h, zip_int64_t offset, int whence, zip_error_t *error); +static int _zip_win32_error_to_errno(unsigned long win32err); +static int _zip_stat_win32(void *h, zip_stat_t *st, _zip_source_win32_read_file_t *ctx); + +ZIP_EXTERN zip_source_t * +zip_source_win32handle(zip_t *za, HANDLE h, zip_uint64_t start, zip_int64_t len) +{ + if (za == NULL) + return NULL; + + return zip_source_win32handle_create(h, start, len, &za->error); +} + + +ZIP_EXTERN zip_source_t * +zip_source_win32handle_create(HANDLE h, zip_uint64_t start, zip_int64_t length, zip_error_t *error) +{ + if (h == INVALID_HANDLE_VALUE || length < -1) { + zip_error_set(error, ZIP_ER_INVAL, 0); + return NULL; + } + + return _zip_source_win32_handle_or_name(NULL, h, start, length, 1, NULL, NULL, error); +} + + +zip_source_t * +_zip_source_win32_handle_or_name(const void *fname, HANDLE h, zip_uint64_t start, zip_int64_t len, int closep, const zip_stat_t *st, _zip_source_win32_file_ops_t *ops, zip_error_t *error) +{ + _zip_source_win32_read_file_t *ctx; + zip_source_t *zs; + + if (h == INVALID_HANDLE_VALUE && fname == NULL) { + zip_error_set(error, ZIP_ER_INVAL, 0); + return NULL; + } + + if ((ctx = (_zip_source_win32_read_file_t *)malloc(sizeof(_zip_source_win32_read_file_t))) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + return NULL; + } + + ctx->fname = NULL; + if (fname) { + if ((ctx->fname = ops->op_strdup(fname)) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + free(ctx); + return NULL; + } + } + + ctx->ops = ops; + ctx->h = h; + ctx->start = start; + ctx->end = (len < 0 ? 0 : start + (zip_uint64_t)len); + ctx->closep = ctx->fname ? 1 : closep; + if (st) { + memcpy(&ctx->st, st, sizeof(ctx->st)); + ctx->st.name = NULL; + ctx->st.valid &= ~ZIP_STAT_NAME; + } + else { + zip_stat_init(&ctx->st); + } + + ctx->tmpname = NULL; + ctx->hout = INVALID_HANDLE_VALUE; + + zip_error_init(&ctx->error); + + ctx->supports = ZIP_SOURCE_SUPPORTS_READABLE | zip_source_make_command_bitmap(ZIP_SOURCE_SUPPORTS, ZIP_SOURCE_TELL, -1); + if (ctx->fname) { + HANDLE th; + + th = ops->op_open(ctx); + if (th == INVALID_HANDLE_VALUE || GetFileType(th) == FILE_TYPE_DISK) { + ctx->supports = ZIP_SOURCE_SUPPORTS_WRITABLE; + } + if (th != INVALID_HANDLE_VALUE) { + CloseHandle(th); + } + } + else if (GetFileType(ctx->h) == FILE_TYPE_DISK) { + ctx->supports = ZIP_SOURCE_SUPPORTS_SEEKABLE; + } + + if ((zs = zip_source_function_create(_win32_read_file, ctx, error)) == NULL) { + free(ctx->fname); + free(ctx); + return NULL; + } + + return zs; +} + + +static zip_int64_t +_win32_read_file(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd) +{ + _zip_source_win32_read_file_t *ctx; + char *buf; + zip_uint64_t n; + DWORD i; + + ctx = (_zip_source_win32_read_file_t *)state; + buf = (char *)data; + + switch (cmd) { + case ZIP_SOURCE_BEGIN_WRITE: + if (ctx->fname == NULL) { + zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0); + return -1; + } + return _win32_create_temp_file(ctx); + + case ZIP_SOURCE_COMMIT_WRITE: { + if (!CloseHandle(ctx->hout)) { + ctx->hout = INVALID_HANDLE_VALUE; + zip_error_set(&ctx->error, ZIP_ER_WRITE, _zip_win32_error_to_errno(GetLastError())); + } + ctx->hout = INVALID_HANDLE_VALUE; + if (ctx->ops->op_rename_temp(ctx) < 0) { + zip_error_set(&ctx->error, ZIP_ER_RENAME, _zip_win32_error_to_errno(GetLastError())); + return -1; + } + free(ctx->tmpname); + ctx->tmpname = NULL; + return 0; + } + + case ZIP_SOURCE_CLOSE: + if (ctx->fname) { + CloseHandle(ctx->h); + ctx->h = INVALID_HANDLE_VALUE; + } + return 0; + + case ZIP_SOURCE_ERROR: + return zip_error_to_data(&ctx->error, data, len); + + case ZIP_SOURCE_FREE: + free(ctx->fname); + free(ctx->tmpname); + if (ctx->closep && ctx->h != INVALID_HANDLE_VALUE) + CloseHandle(ctx->h); + free(ctx); + return 0; + + case ZIP_SOURCE_OPEN: + if (ctx->fname) { + if ((ctx->h = ctx->ops->op_open(ctx)) == INVALID_HANDLE_VALUE) { + zip_error_set(&ctx->error, ZIP_ER_OPEN, _zip_win32_error_to_errno(GetLastError())); + return -1; + } + } + + if (ctx->closep && ctx->start > 0) { + if (_zip_seek_win32_u(ctx->h, ctx->start, SEEK_SET, &ctx->error) < 0) { + return -1; + } + } + ctx->current = ctx->start; + return 0; + + case ZIP_SOURCE_READ: + if (ctx->end > 0) { + n = ctx->end - ctx->current; + if (n > len) { + n = len; + } + } + else { + n = len; + } + + if (n > SIZE_MAX) + n = SIZE_MAX; + + if (!ctx->closep) { + if (_zip_seek_win32_u(ctx->h, ctx->current, SEEK_SET, &ctx->error) < 0) { + return -1; + } + } + + if (!ReadFile(ctx->h, buf, (DWORD)n, &i, NULL)) { + zip_error_set(&ctx->error, ZIP_ER_READ, _zip_win32_error_to_errno(GetLastError())); + return -1; + } + ctx->current += i; + + return (zip_int64_t)i; + + case ZIP_SOURCE_REMOVE: + if (ctx->ops->op_remove(ctx->fname) < 0) { + zip_error_set(&ctx->error, ZIP_ER_REMOVE, _zip_win32_error_to_errno(GetLastError())); + return -1; + } + return 0; + + case ZIP_SOURCE_ROLLBACK_WRITE: + if (ctx->hout) { + CloseHandle(ctx->hout); + ctx->hout = INVALID_HANDLE_VALUE; + } + ctx->ops->op_remove(ctx->tmpname); + free(ctx->tmpname); + ctx->tmpname = NULL; + return 0; + + case ZIP_SOURCE_SEEK: { + zip_int64_t new_current; + int need_seek; + zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error); + + if (args == NULL) + return -1; + + need_seek = ctx->closep; + + switch (args->whence) { + case SEEK_SET: + new_current = args->offset; + break; + + case SEEK_END: + if (ctx->end == 0) { + LARGE_INTEGER zero; + LARGE_INTEGER new_offset; + + if (_zip_seek_win32(ctx->h, args->offset, SEEK_END, &ctx->error) < 0) { + return -1; + } + zero.QuadPart = 0; + if (!SetFilePointerEx(ctx->h, zero, &new_offset, FILE_CURRENT)) { + zip_error_set(&ctx->error, ZIP_ER_SEEK, _zip_win32_error_to_errno(GetLastError())); + return -1; + } + new_current = new_offset.QuadPart; + need_seek = 0; + } + else { + new_current = (zip_int64_t)ctx->end + args->offset; + } + break; + case SEEK_CUR: + new_current = (zip_int64_t)ctx->current + args->offset; + break; + + default: + zip_error_set(&ctx->error, ZIP_ER_INVAL, 0); + return -1; + } + + if (new_current < 0 || (zip_uint64_t)new_current < ctx->start || (ctx->end != 0 && (zip_uint64_t)new_current > ctx->end)) { + zip_error_set(&ctx->error, ZIP_ER_INVAL, 0); + return -1; + } + + ctx->current = (zip_uint64_t)new_current; + + if (need_seek) { + if (_zip_seek_win32_u(ctx->h, ctx->current, SEEK_SET, &ctx->error) < 0) { + return -1; + } + } + return 0; + } + + case ZIP_SOURCE_SEEK_WRITE: { + zip_source_args_seek_t *args; + + args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error); + if (args == NULL) { + return -1; + } + + if (_zip_seek_win32(ctx->hout, args->offset, args->whence, &ctx->error) < 0) { + return -1; + } + return 0; + } + + case ZIP_SOURCE_STAT: { + if (len < sizeof(ctx->st)) + return -1; + + if (ctx->st.valid != 0) + memcpy(data, &ctx->st, sizeof(ctx->st)); + else { + DWORD win32err; + zip_stat_t *st; + HANDLE h; + int success; + + st = (zip_stat_t *)data; + + if (ctx->h != INVALID_HANDLE_VALUE) { + h = ctx->h; + } + else { + h = ctx->ops->op_open(ctx); + if (h == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_NOT_FOUND) { + zip_error_set(&ctx->error, ZIP_ER_READ, ENOENT); + return -1; + } + } + + success = _zip_stat_win32(h, st, ctx); + win32err = GetLastError(); + + /* We're done with the handle, so close it if we just opened it. */ + if (h != ctx->h) { + CloseHandle(h); + } + + if (success < 0) { + /* TODO: Is this the correct error to return in all cases? */ + zip_error_set(&ctx->error, ZIP_ER_READ, _zip_win32_error_to_errno(win32err)); + return -1; + } + } + return sizeof(ctx->st); + } + + case ZIP_SOURCE_SUPPORTS: + return ctx->supports; + + case ZIP_SOURCE_TELL: + return (zip_int64_t)ctx->current; + + case ZIP_SOURCE_TELL_WRITE: + { + LARGE_INTEGER zero; + LARGE_INTEGER offset; + + zero.QuadPart = 0; + if (!SetFilePointerEx(ctx->hout, zero, &offset, FILE_CURRENT)) { + zip_error_set(&ctx->error, ZIP_ER_TELL, _zip_win32_error_to_errno(GetLastError())); + return -1; + } + + return offset.QuadPart; + } + + case ZIP_SOURCE_WRITE: + { + DWORD ret; + if (!WriteFile(ctx->hout, data, (DWORD)len, &ret, NULL) || ret != len) { + zip_error_set(&ctx->error, ZIP_ER_WRITE, _zip_win32_error_to_errno(GetLastError())); + return -1; + } + + return (zip_int64_t)ret; + } + + default: + zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0); + return -1; + } +} + + +static int +_win32_create_temp_file(_zip_source_win32_read_file_t *ctx) +{ + /* + Windows has GetTempFileName(), but it closes the file after + creation, leaving it open to a horrible race condition. So + we reinvent the wheel. + */ + int i; + HANDLE th = INVALID_HANDLE_VALUE; + void *temp = NULL; + SECURITY_INFORMATION si; + SECURITY_ATTRIBUTES sa; + PSECURITY_DESCRIPTOR psd = NULL; + PSECURITY_ATTRIBUTES psa = NULL; + DWORD len; + BOOL success; + + /* + Read the DACL from the original file, so we can copy it to the temp file. + If there is no original file, or if we can't read the DACL, we'll use the + default security descriptor. + */ + if (ctx->h != INVALID_HANDLE_VALUE && GetFileType(ctx->h) == FILE_TYPE_DISK) { + si = DACL_SECURITY_INFORMATION | UNPROTECTED_DACL_SECURITY_INFORMATION; + len = 0; + success = GetUserObjectSecurity(ctx->h, &si, NULL, len, &len); + if (!success && GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + if ((psd = (PSECURITY_DESCRIPTOR)malloc(len)) == NULL) { + zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0); + return -1; + } + success = GetUserObjectSecurity(ctx->h, &si, psd, len, &len); + } + if (success) { + sa.nLength = sizeof(SECURITY_ATTRIBUTES); + sa.bInheritHandle = FALSE; + sa.lpSecurityDescriptor = psd; + psa = &sa; + } + } + + zip_uint32_t value = GetTickCount(); + for (i = 0; i < 1024 && th == INVALID_HANDLE_VALUE; i++) { + th = ctx->ops->op_create_temp(ctx, &temp, value + i, psa); + if (th == INVALID_HANDLE_VALUE && GetLastError() != ERROR_FILE_EXISTS) + break; + } + + if (th == INVALID_HANDLE_VALUE) { + free(temp); + free(psd); + zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, _zip_win32_error_to_errno(GetLastError())); + return -1; + } + + free(psd); + ctx->hout = th; + ctx->tmpname = temp; + + return 0; +} + + +static int +_zip_seek_win32_u(HANDLE h, zip_uint64_t offset, int whence, zip_error_t *error) +{ + if (offset > ZIP_INT64_MAX) { + zip_error_set(error, ZIP_ER_SEEK, EOVERFLOW); + return -1; + } + return _zip_seek_win32(h, (zip_int64_t)offset, whence, error); +} + + +static int +_zip_seek_win32(HANDLE h, zip_int64_t offset, int whence, zip_error_t *error) +{ + LARGE_INTEGER li; + DWORD method; + + switch (whence) { + case SEEK_SET: + method = FILE_BEGIN; + break; + case SEEK_END: + method = FILE_END; + break; + case SEEK_CUR: + method = FILE_CURRENT; + break; + default: + zip_error_set(error, ZIP_ER_SEEK, EINVAL); + return -1; + } + + li.QuadPart = (LONGLONG)offset; + if (!SetFilePointerEx(h, li, NULL, method)) { + zip_error_set(error, ZIP_ER_SEEK, _zip_win32_error_to_errno(GetLastError())); + return -1; + } + + return 0; +} + + +static int +_zip_win32_error_to_errno(DWORD win32err) +{ + /* + Note: This list isn't exhaustive, but should cover common cases. + */ + switch (win32err) { + case ERROR_INVALID_PARAMETER: + return EINVAL; + case ERROR_FILE_NOT_FOUND: + return ENOENT; + case ERROR_INVALID_HANDLE: + return EBADF; + case ERROR_ACCESS_DENIED: + return EACCES; + case ERROR_FILE_EXISTS: + return EEXIST; + case ERROR_TOO_MANY_OPEN_FILES: + return EMFILE; + case ERROR_DISK_FULL: + return ENOSPC; + default: + return 0; + } +} + + +static int +_zip_stat_win32(HANDLE h, zip_stat_t *st, _zip_source_win32_read_file_t *ctx) +{ + FILETIME mtimeft; + time_t mtime; + LARGE_INTEGER size; + int regularp; + + if (!GetFileTime(h, NULL, NULL, &mtimeft)) { + zip_error_set(&ctx->error, ZIP_ER_READ, _zip_win32_error_to_errno(GetLastError())); + return -1; + } + if (_zip_filetime_to_time_t(mtimeft, &mtime) < 0) { + zip_error_set(&ctx->error, ZIP_ER_READ, ERANGE); + return -1; + } + + regularp = 0; + if (GetFileType(h) == FILE_TYPE_DISK) { + regularp = 1; + } + + if (!GetFileSizeEx(h, &size)) { + zip_error_set(&ctx->error, ZIP_ER_READ, _zip_win32_error_to_errno(GetLastError())); + return -1; + } + + zip_stat_init(st); + st->mtime = mtime; + st->valid |= ZIP_STAT_MTIME; + if (ctx->end != 0) { + st->size = ctx->end - ctx->start; + st->valid |= ZIP_STAT_SIZE; + } + else if (regularp) { + st->size = (zip_uint64_t)size.QuadPart; + st->valid |= ZIP_STAT_SIZE; + } + + return 0; +} + + +static int +_zip_filetime_to_time_t(FILETIME ft, time_t *t) +{ + /* + Inspired by http://stackoverflow.com/questions/6161776/convert-windows-filetime-to-second-in-unix-linux + */ + const zip_int64_t WINDOWS_TICK = 10000000LL; + const zip_int64_t SEC_TO_UNIX_EPOCH = 11644473600LL; + ULARGE_INTEGER li; + zip_int64_t secs; + time_t temp; + + li.LowPart = ft.dwLowDateTime; + li.HighPart = ft.dwHighDateTime; + secs = (li.QuadPart / WINDOWS_TICK - SEC_TO_UNIX_EPOCH); + + temp = (time_t)secs; + if (secs != (zip_int64_t)temp) + return -1; + + *t = temp; + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_win32utf8.c b/ePub3/ThirdParty/libzip/zip_source_win32utf8.c new file mode 100644 index 000000000..e11214ba0 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_win32utf8.c @@ -0,0 +1,80 @@ +/* +zip_source_win32utf8.c -- create data source from Windows file (UTF-8) +Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner + +This file is part of libzip, a library to manipulate ZIP archives. +The authors can be contacted at + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in +the documentation and/or other materials provided with the +distribution. +3. The names of the authors may not be used to endorse or promote +products derived from this software without specific prior +written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include +#include + +#include "zipint.h" +#include "zipwin32.h" + + +ZIP_EXTERN zip_source_t * +zip_source_file(zip_t *za, const char *fname, zip_uint64_t start, zip_int64_t len) +{ + if (za == NULL) + return NULL; + + return zip_source_file_create(fname, start, len, &za->error); +} + + +ZIP_EXTERN zip_source_t * +zip_source_file_create(const char *fname, zip_uint64_t start, zip_int64_t length, zip_error_t *error) +{ + int size; + wchar_t *wfname; + zip_source_t *source; + + if (fname == NULL || length < -1) { + zip_error_set(error, ZIP_ER_INVAL, 0); + return NULL; + } + + /* Convert fname from UTF-8 to Windows-friendly UTF-16. */ + size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, fname, -1, NULL, 0); + if (size == 0) { + zip_error_set(error, ZIP_ER_INVAL, 0); + return NULL; + } + if ((wfname = (wchar_t *)malloc(sizeof(wchar_t) * size)) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + return NULL; + } + MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, fname, -1, wfname, size); + + source = zip_source_win32w_create(wfname, start, length, error); + + free(wfname); + return source; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_win32w.c b/ePub3/ThirdParty/libzip/zip_source_win32w.c new file mode 100644 index 000000000..27cdf910e --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_win32w.c @@ -0,0 +1,125 @@ +/* +zip_source_win32w.c -- create data source from Windows file (UTF-16) +Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner + +This file is part of libzip, a library to manipulate ZIP archives. +The authors can be contacted at + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in +the documentation and/or other materials provided with the +distribution. +3. The names of the authors may not be used to endorse or promote +products derived from this software without specific prior +written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include +#include + +#include "zipint.h" +#include "zipwin32.h" + +static void * _win32_strdup_w(const void *str); +static HANDLE _win32_open_w(_zip_source_win32_read_file_t *ctx); +static HANDLE _win32_create_temp_w(_zip_source_win32_read_file_t *ctx, void **temp, zip_uint32_t value, PSECURITY_ATTRIBUTES sa); +static int _win32_rename_temp_w(_zip_source_win32_read_file_t *ctx); +static int _win32_remove_w(const void *fname); + +static _zip_source_win32_file_ops_t win32_ops_w = { + .op_strdup = _win32_strdup_w, + .op_open = _win32_open_w, + .op_create_temp = _win32_create_temp_w, + .op_rename_temp = _win32_rename_temp_w, + .op_remove = _win32_remove_w +}; + +ZIP_EXTERN zip_source_t * +zip_source_win32w(zip_t *za, const wchar_t *fname, zip_uint64_t start, zip_int64_t len) +{ + if (za == NULL) + return NULL; + + return zip_source_win32w_create(fname, start, len, &za->error); +} + + +ZIP_EXTERN zip_source_t * +zip_source_win32w_create(const wchar_t *fname, zip_uint64_t start, zip_int64_t length, zip_error_t *error) +{ + if (fname == NULL || length < -1) { + zip_error_set(error, ZIP_ER_INVAL, 0); + return NULL; + } + + return _zip_source_win32_handle_or_name(fname, INVALID_HANDLE_VALUE, start, length, 1, NULL, &win32_ops_w, error); +} + + +static void * +_win32_strdup_w(const void *str) +{ + return _wcsdup((const wchar_t *)str); +} + + +static HANDLE +_win32_open_w(_zip_source_win32_read_file_t *ctx) +{ + return CreateFileW(ctx->fname, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); +} + + +static HANDLE +_win32_create_temp_w(_zip_source_win32_read_file_t *ctx, void **temp, zip_uint32_t value, PSECURITY_ATTRIBUTES sa) +{ + int len; + + len = wcslen((const wchar_t *)ctx->fname) + 10; + if (*temp == NULL) { + if ((*temp = malloc(sizeof(wchar_t) * len)) == NULL) { + zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0); + return INVALID_HANDLE_VALUE; + } + } + if (swprintf((wchar_t *)*temp, len, L"%s.%08x", (const wchar_t *)ctx->fname, value) != len - 1) { + return INVALID_HANDLE_VALUE; + } + + return CreateFileW((const wchar_t *)*temp, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, sa, CREATE_NEW, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_TEMPORARY, NULL); +} + + +static int +_win32_rename_temp_w(_zip_source_win32_read_file_t *ctx) +{ + if (!MoveFileExW(ctx->tmpname, ctx->fname, MOVEFILE_REPLACE_EXISTING)) + return -1; + return 0; +} + + +static int +_win32_remove_w(const void *fname) +{ + DeleteFileW((const wchar_t *)fname); + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_window.c b/ePub3/ThirdParty/libzip/zip_source_window.c new file mode 100644 index 000000000..f02d048c0 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_window.c @@ -0,0 +1,253 @@ +/* + zip_source_window.c -- return part of lower source + Copyright (C) 2012-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include +#include + +#include "zipint.h" + +struct window { + zip_uint64_t start; + zip_uint64_t end; + zip_uint64_t offset; + zip_stat_t stat; + zip_error_t error; + zip_int64_t supports; + bool needs_seek; +}; + +static zip_int64_t window_read(zip_source_t *, void *, void *, zip_uint64_t, zip_source_cmd_t); + + +zip_source_t * +zip_source_window(zip_t *za, zip_source_t *src, zip_uint64_t start, zip_uint64_t len) +{ + return _zip_source_window_new(src, start, len, NULL, &za->error); +} + + +zip_source_t * +_zip_source_window_new(zip_source_t *src, zip_uint64_t start, zip_uint64_t length, zip_stat_t *st, zip_error_t *error) +{ + struct window *ctx; + + if (src == NULL || start + length < start) { + zip_error_set(error, ZIP_ER_INVAL, 0); + return NULL; + } + + if ((ctx=(struct window *)malloc(sizeof(*ctx))) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + return NULL; + } + + ctx->start = start; + ctx->end = start + length; + zip_stat_init(&ctx->stat); + zip_error_init(&ctx->error); + ctx->supports = (zip_source_supports(src) & ZIP_SOURCE_SUPPORTS_SEEKABLE) | (zip_source_make_command_bitmap(ZIP_SOURCE_SUPPORTS, ZIP_SOURCE_TELL, -1)); + ctx->needs_seek = (ctx->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK)) ? true : false; + + if (st) { + if (_zip_stat_merge(&ctx->stat, st, error) < 0) { + free(ctx); + return NULL; + } + } + + return zip_source_layered_create(src, window_read, ctx, error); +} + + +int +_zip_source_set_source_archive(zip_source_t *src, zip_t *za) +{ + src->source_archive = za; + return _zip_register_source(za, src); +} + + +/* called by zip_discard to avoid operating on file from closed archive */ +void +_zip_source_invalidate(zip_source_t *src) +{ + src->source_closed = 1; + + if (zip_error_code_zip(&src->error) == ZIP_ER_OK) { + zip_error_set(&src->error, ZIP_ER_ZIPCLOSED, 0); + } +} + + +static zip_int64_t +window_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source_cmd_t cmd) +{ + struct window *ctx; + zip_int64_t ret; + zip_uint64_t n, i; + char b[8192]; + + ctx = (struct window *)_ctx; + + switch (cmd) { + case ZIP_SOURCE_CLOSE: + return 0; + + case ZIP_SOURCE_ERROR: + return zip_error_to_data(&ctx->error, data, len); + + case ZIP_SOURCE_FREE: + free(ctx); + return 0; + + case ZIP_SOURCE_OPEN: + if (!ctx->needs_seek) { + for (n=0; nstart; n+=(zip_uint64_t)ret) { + i = (ctx->start-n > sizeof(b) ? sizeof(b) : ctx->start-n); + if ((ret=zip_source_read(src, b, i)) < 0) { + _zip_error_set_from_source(&ctx->error, src); + return -1; + } + if (ret==0) { + zip_error_set(&ctx->error, ZIP_ER_EOF, 0); + return -1; + } + } + + } + ctx->offset = ctx->start; + return 0; + + case ZIP_SOURCE_READ: + if (len > ctx->end - ctx->offset) + len = ctx->end - ctx->offset; + + if (len == 0) + return 0; + + if (ctx->needs_seek) { + if (zip_source_seek(src, (zip_int64_t)ctx->offset, SEEK_SET) < 0) { + _zip_error_set_from_source(&ctx->error, src); + return -1; + } + } + + if ((ret=zip_source_read(src, data, len)) < 0) { + zip_error_set(&ctx->error, ZIP_ER_EOF, 0); + return -1; + } + + ctx->offset += (zip_uint64_t)ret; + + if (ret == 0) { + if (ctx->offset < ctx->end) { + zip_error_set(&ctx->error, ZIP_ER_EOF, 0); + return -1; + } + } + return ret; + + case ZIP_SOURCE_SEEK: + { + zip_int64_t new_offset = zip_source_seek_compute_offset(ctx->offset - ctx->start, ctx->end - ctx->start, data, len, &ctx->error); + + if (new_offset < 0) { + return -1; + } + + ctx->offset = (zip_uint64_t)new_offset + ctx->start; + return 0; + } + + case ZIP_SOURCE_STAT: + { + zip_stat_t *st; + + st = (zip_stat_t *)data; + + if (_zip_stat_merge(st, &ctx->stat, &ctx->error) < 0) { + return -1; + } + return 0; + } + + case ZIP_SOURCE_SUPPORTS: + return ctx->supports; + + case ZIP_SOURCE_TELL: + return (zip_int64_t)(ctx->offset - ctx->start); + + default: + zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0); + return -1; + } +} + + +void +_zip_deregister_source(zip_t *za, zip_source_t *src) +{ + unsigned int i; + + for (i=0; inopen_source; i++) { + if (za->open_source[i] == src) { + za->open_source[i] = za->open_source[za->nopen_source-1]; + za->nopen_source--; + break; + } + } +} + + +int +_zip_register_source(zip_t *za, zip_source_t *src) +{ + zip_source_t **open_source; + + if (za->nopen_source+1 >= za->nopen_source_alloc) { + unsigned int n; + n = za->nopen_source_alloc + 10; + open_source = (zip_source_t **)realloc(za->open_source, n*sizeof(zip_source_t *)); + if (open_source == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return -1; + } + za->nopen_source_alloc = n; + za->open_source = open_source; + } + + za->open_source[za->nopen_source++] = src; + + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_source_write.c b/ePub3/ThirdParty/libzip/zip_source_write.c new file mode 100644 index 000000000..c98f5679a --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_write.c @@ -0,0 +1,47 @@ +/* + zip_source_write.c -- start a new file for writing + Copyright (C) 2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + + +ZIP_EXTERN zip_int64_t +zip_source_write(zip_source_t *src, const void *data, zip_uint64_t length) +{ + if (!ZIP_SOURCE_IS_OPEN_WRITING(src) || length > ZIP_INT64_MAX) { + zip_error_set(&src->error, ZIP_ER_INVAL, 0); + return -1; + } + + return _zip_source_call(src, (void *)data, length, ZIP_SOURCE_WRITE); +} diff --git a/ePub3/ThirdParty/libzip/zip_source_zip.c b/ePub3/ThirdParty/libzip/zip_source_zip.c index 9e87f9d1b..e172ca208 100644 --- a/ePub3/ThirdParty/libzip/zip_source_zip.c +++ b/ePub3/ThirdParty/libzip/zip_source_zip.c @@ -1,6 +1,6 @@ /* zip_source_zip.c -- create data source from zip file - Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,158 +31,29 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include #include "zipint.h" -struct read_zip { - struct zip_file *zf; - struct zip_stat st; - off_t off, len; -}; -static ssize_t read_zip(void *st, void *data, size_t len, - enum zip_source_cmd cmd); - - - -ZIP_EXTERN struct zip_source * -zip_source_zip(struct zip *za, struct zip *srcza, int srcidx, int flags, - off_t start, off_t len) +ZIP_EXTERN zip_source_t * +zip_source_zip(zip_t *za, zip_t *srcza, zip_uint64_t srcidx, + zip_flags_t flags, zip_uint64_t start, zip_int64_t len) { - struct zip_error error; - struct zip_source *zs; - struct read_zip *p; - - /* XXX: ZIP_FL_RECOMPRESS */ - - if (za == NULL) - return NULL; - - if (srcza == NULL || start < 0 || len < -1 || srcidx < 0 || srcidx >= srcza->nentry) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); - return NULL; + if (len < -1) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return NULL; } - - if ((flags & ZIP_FL_UNCHANGED) == 0 - && ZIP_ENTRY_DATA_CHANGED(srcza->entry+srcidx)) { - _zip_error_set(&za->error, ZIP_ER_CHANGED, 0); - return NULL; - } - - if (len == 0) - len = -1; - - if (start == 0 && len == -1 && (flags & ZIP_FL_RECOMPRESS) == 0) + + if (len == -1) + len = 0; + + if (start == 0 && len == 0) flags |= ZIP_FL_COMPRESSED; else flags &= ~ZIP_FL_COMPRESSED; - if ((p=(struct read_zip *)malloc(sizeof(*p))) == NULL) { - _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); - return NULL; - } - - _zip_error_copy(&error, &srcza->error); - - if (zip_stat_index(srcza, srcidx, flags, &p->st) < 0 - || (p->zf=zip_fopen_index(srcza, srcidx, flags)) == NULL) { - free(p); - _zip_error_copy(&za->error, &srcza->error); - _zip_error_copy(&srcza->error, &error); - - return NULL; - } - p->off = start; - p->len = len; - - if ((flags & ZIP_FL_COMPRESSED) == 0) { - p->st.size = p->st.comp_size = len; - p->st.comp_method = ZIP_CM_STORE; - p->st.crc = 0; - } - - if ((zs=zip_source_function(za, read_zip, p)) == NULL) { - free(p); - return NULL; - } - - return zs; -} - - - -static ssize_t -read_zip(void *state, void *data, size_t len, enum zip_source_cmd cmd) -{ - struct read_zip *z; - char b[8192], *buf; - ssize_t i, n; - - z = (struct read_zip *)state; - buf = (char *)data; - - switch (cmd) { - case ZIP_SOURCE_OPEN: - for (n=0; noff; n+= i) { - i = (z->off-n > sizeof(b) ? sizeof(b) : ((size_t)z->off)-n); - if ((i=zip_fread(z->zf, b, i)) < 0) { - zip_fclose(z->zf); - z->zf = NULL; - return -1; - } - } - return 0; - - case ZIP_SOURCE_READ: - if (z->len != -1) - n = len > (size_t)(z->len) ? (ssize_t)z->len : (ssize_t)len; - else - n = (ssize_t)len; - - - if ((i=(ssize_t)zip_fread(z->zf, buf, n)) < 0) - return -1; - - if (z->len != -1) - z->len -= i; - - return i; - - case ZIP_SOURCE_CLOSE: - return 0; - - case ZIP_SOURCE_STAT: - if (len < sizeof(z->st)) - return -1; - len = sizeof(z->st); - - memcpy(data, &z->st, len); - return (ssize_t)len; - - case ZIP_SOURCE_ERROR: - { - int *e; - - if (len < sizeof(int)*2) - return -1; - - e = (int *)data; - zip_file_error_get(z->zf, e, e+1); - } - return sizeof(int)*2; - - case ZIP_SOURCE_FREE: - zip_fclose(z->zf); - free(z); - return 0; - - default: - ; - } - - return -1; + return _zip_source_zip_new(za, srcza, srcidx, flags, start, (zip_uint64_t)len, NULL); } diff --git a/ePub3/ThirdParty/libzip/zip_source_zip_new.c b/ePub3/ThirdParty/libzip/zip_source_zip_new.c new file mode 100644 index 000000000..40f1195f1 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_source_zip_new.c @@ -0,0 +1,173 @@ +/* + zip_source_zip_new.c -- prepare data structures for zip_fopen/zip_source_zip + Copyright (C) 2012-2015 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include + +#include "zipint.h" + + +zip_source_t * +_zip_source_zip_new(zip_t *za, zip_t *srcza, zip_uint64_t srcidx, zip_flags_t flags, zip_uint64_t start, zip_uint64_t len, const char *password) +{ + zip_compression_implementation comp_impl; + zip_encryption_implementation enc_impl; + zip_source_t *src, *s2; + zip_uint64_t offset; + struct zip_stat st; + + if (za == NULL) + return NULL; + + if (srcza == NULL || srcidx >= srcza->nentry) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return NULL; + } + + if ((flags & ZIP_FL_UNCHANGED) == 0 + && (ZIP_ENTRY_DATA_CHANGED(srcza->entry+srcidx) || srcza->entry[srcidx].deleted)) { + zip_error_set(&za->error, ZIP_ER_CHANGED, 0); + return NULL; + } + + if (zip_stat_index(srcza, srcidx, flags|ZIP_FL_UNCHANGED, &st) < 0) { + zip_error_set(&za->error, ZIP_ER_INTERNAL, 0); + return NULL; + } + + if (flags & ZIP_FL_ENCRYPTED) + flags |= ZIP_FL_COMPRESSED; + + if ((start > 0 || len > 0) && (flags & ZIP_FL_COMPRESSED)) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return NULL; + } + + /* overflow or past end of file */ + if ((start > 0 || len > 0) && (start+len < start || start+len > st.size)) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return NULL; + } + + enc_impl = NULL; + if (((flags & ZIP_FL_ENCRYPTED) == 0) && (st.encryption_method != ZIP_EM_NONE)) { + if (password == NULL) { + zip_error_set(&za->error, ZIP_ER_NOPASSWD, 0); + return NULL; + } + if ((enc_impl=_zip_get_encryption_implementation(st.encryption_method)) == NULL) { + zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0); + return NULL; + } + } + + comp_impl = NULL; + if ((flags & ZIP_FL_COMPRESSED) == 0) { + if (st.comp_method != ZIP_CM_STORE) { + if ((comp_impl=_zip_get_compression_implementation(st.comp_method)) == NULL) { + zip_error_set(&za->error, ZIP_ER_COMPNOTSUPP, 0); + return NULL; + } + } + } + + if ((offset=_zip_file_get_offset(srcza, srcidx, &za->error)) == 0) + return NULL; + + if (st.comp_size == 0) { + return zip_source_buffer(za, NULL, 0, 0); + } + + if (start+len > 0 && enc_impl == NULL && comp_impl == NULL) { + struct zip_stat st2; + + st2.size = len ? len : st.size-start; + st2.comp_size = st2.size; + st2.comp_method = ZIP_CM_STORE; + st2.mtime = st.mtime; + st2.valid = ZIP_STAT_SIZE|ZIP_STAT_COMP_SIZE|ZIP_STAT_COMP_METHOD|ZIP_STAT_MTIME; + + if ((src = _zip_source_window_new(srcza->src, offset+start, st2.size, &st2, &za->error)) == NULL) { + return NULL; + } + } + else { + if ((src = _zip_source_window_new(srcza->src, offset, st.comp_size, &st, &za->error)) == NULL) { + return NULL; + } + } + + if (_zip_source_set_source_archive(src, srcza) < 0) { + zip_source_free(src); + return NULL; + } + + /* creating a layered source calls zip_keep() on the lower layer, so we free it */ + + if (enc_impl) { + s2 = enc_impl(za, src, st.encryption_method, 0, password); + zip_source_free(src); + if (s2 == NULL) { + return NULL; + } + src = s2; + } + if (comp_impl) { + s2 = comp_impl(za, src, st.comp_method, 0); + zip_source_free(src); + if (s2 == NULL) { + return NULL; + } + src = s2; + } + if (((flags & ZIP_FL_COMPRESSED) == 0 || st.comp_method == ZIP_CM_STORE) && (len == 0 || len == st.comp_size)) { + /* when reading the whole file, check for CRC errors */ + s2 = zip_source_crc(za, src, 1); + zip_source_free(src); + if (s2 == NULL) { + return NULL; + } + src = s2; + } + + if (start+len > 0 && (comp_impl || enc_impl)) { + s2 = zip_source_window(za, src, start, len ? len : st.size-start); + zip_source_free(src); + if (s2 == NULL) { + return NULL; + } + src = s2; + } + + return src; +} diff --git a/ePub3/ThirdParty/libzip/zip_stat.c b/ePub3/ThirdParty/libzip/zip_stat.c index df1c0b50b..cf8e56613 100644 --- a/ePub3/ThirdParty/libzip/zip_stat.c +++ b/ePub3/ThirdParty/libzip/zip_stat.c @@ -1,6 +1,6 @@ /* zip_stat.c -- get information about file by name - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,19 +31,17 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "zipint.h" - ZIP_EXTERN int -zip_stat(struct zip *za, const char *fname, int flags, struct zip_stat *st) +zip_stat(zip_t *za, const char *fname, zip_flags_t flags, zip_stat_t *st) { - int idx; + zip_int64_t idx; if ((idx=zip_name_locate(za, fname, flags)) < 0) return -1; - return zip_stat_index(za, idx, flags, st); + return zip_stat_index(za, (zip_uint64_t)idx, flags, st); } diff --git a/ePub3/ThirdParty/libzip/zip_stat_index.c b/ePub3/ThirdParty/libzip/zip_stat_index.c index 60558e432..601e3f70b 100644 --- a/ePub3/ThirdParty/libzip/zip_stat_index.c +++ b/ePub3/ThirdParty/libzip/zip_stat_index.c @@ -1,6 +1,6 @@ /* zip_stat_index.c -- get information about file by index - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,21 +31,19 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "zipint.h" - ZIP_EXTERN int -zip_stat_index(struct zip *za, int index, int flags, struct zip_stat *st) +zip_stat_index(zip_t *za, zip_uint64_t index, zip_flags_t flags, + zip_stat_t *st) { const char *name; - - if (index < 0 || index >= za->nentry) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); + zip_dirent_t *de; + + if ((de=_zip_get_dirent(za, index, flags, NULL)) == NULL) return -1; - } if ((name=zip_get_name(za, index, flags)) == NULL) return -1; @@ -53,26 +51,22 @@ zip_stat_index(struct zip *za, int index, int flags, struct zip_stat *st) if ((flags & ZIP_FL_UNCHANGED) == 0 && ZIP_ENTRY_DATA_CHANGED(za->entry+index)) { - if (za->entry[index].source->f(za->entry[index].source->ud, - st, sizeof(*st), ZIP_SOURCE_STAT) < 0) { - _zip_error_set(&za->error, ZIP_ER_CHANGED, 0); + if (zip_source_stat(za->entry[index].source, st) < 0) { + zip_error_set(&za->error, ZIP_ER_CHANGED, 0); return -1; } } else { - if (za->cdir == NULL || index >= za->cdir->nentry) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); - return -1; - } - - st->crc = za->cdir->entry[index].crc; - st->size = za->cdir->entry[index].uncomp_size; - st->mtime = za->cdir->entry[index].last_mod; - st->comp_size = za->cdir->entry[index].comp_size; - st->comp_method = za->cdir->entry[index].comp_method; - if (za->cdir->entry[index].bitflags & ZIP_GPBF_ENCRYPTED) { - if (za->cdir->entry[index].bitflags & ZIP_GPBF_STRONG_ENCRYPTION) { - /* XXX */ + zip_stat_init(st); + + st->crc = de->crc; + st->size = de->uncomp_size; + st->mtime = de->last_mod; + st->comp_size = de->comp_size; + st->comp_method = (zip_uint16_t)de->comp_method; + if (de->bitflags & ZIP_GPBF_ENCRYPTED) { + if (de->bitflags & ZIP_GPBF_STRONG_ENCRYPTION) { + /* TODO */ st->encryption_method = ZIP_EM_UNKNOWN; } else @@ -80,11 +74,13 @@ zip_stat_index(struct zip *za, int index, int flags, struct zip_stat *st) } else st->encryption_method = ZIP_EM_NONE; - /* st->bitflags = za->cdir->entry[index].bitflags; */ + st->valid = ZIP_STAT_CRC|ZIP_STAT_SIZE|ZIP_STAT_MTIME + |ZIP_STAT_COMP_SIZE|ZIP_STAT_COMP_METHOD|ZIP_STAT_ENCRYPTION_METHOD; } st->index = index; st->name = name; + st->valid |= ZIP_STAT_INDEX|ZIP_STAT_NAME; return 0; } diff --git a/ePub3/ThirdParty/libzip/zip_stat_init.c b/ePub3/ThirdParty/libzip/zip_stat_init.c index 133ad304a..6b7d63374 100644 --- a/ePub3/ThirdParty/libzip/zip_stat_init.c +++ b/ePub3/ThirdParty/libzip/zip_stat_init.c @@ -1,6 +1,6 @@ /* zip_stat_init.c -- initialize struct zip_stat. - Copyright (C) 2006-2007 Dieter Baron and Thomas Klausner + Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,21 +31,55 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - +#include #include "zipint.h" - ZIP_EXTERN void -zip_stat_init(struct zip_stat *st) +zip_stat_init(zip_stat_t *st) { + st->valid = 0; st->name = NULL; - st->index = -1; + st->index = ZIP_UINT64_MAX; st->crc = 0; st->mtime = (time_t)-1; - st->size = -1; - st->comp_size = -1; + st->size = 0; + st->comp_size = 0; st->comp_method = ZIP_CM_STORE; st->encryption_method = ZIP_EM_NONE; } + + +int +_zip_stat_merge(zip_stat_t *dst, const zip_stat_t *src, zip_error_t *error) +{ + /* name is not merged, since zip_stat_t doesn't own it, and src may not be valid as long as dst */ + if (src->valid & ZIP_STAT_INDEX) { + dst->index = src->index; + } + if (src->valid & ZIP_STAT_SIZE) { + dst->size = src->size; + } + if (src->valid & ZIP_STAT_COMP_SIZE) { + dst->comp_size = src->comp_size; + } + if (src->valid & ZIP_STAT_MTIME) { + dst->mtime = src->mtime; + } + if (src->valid & ZIP_STAT_CRC) { + dst->crc = src->crc; + } + if (src->valid & ZIP_STAT_COMP_METHOD) { + dst->comp_method = src->comp_method; + } + if (src->valid & ZIP_STAT_ENCRYPTION_METHOD) { + dst->encryption_method = src->encryption_method; + } + if (src->valid & ZIP_STAT_FLAGS) { + dst->flags = src->flags; + } + dst->valid |= src->valid; + + return 0; +} diff --git a/ePub3/ThirdParty/libzip/zip_strerror.c b/ePub3/ThirdParty/libzip/zip_strerror.c index 9ebee144f..98c4f6b1c 100644 --- a/ePub3/ThirdParty/libzip/zip_strerror.c +++ b/ePub3/ThirdParty/libzip/zip_strerror.c @@ -1,6 +1,6 @@ /* zip_sterror.c -- get string representation of zip error - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,14 +31,12 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "zipint.h" - ZIP_EXTERN const char * -zip_strerror(struct zip *za) +zip_strerror(zip_t *za) { - return _zip_error_strerror(&za->error); + return zip_error_strerror(&za->error); } diff --git a/ePub3/ThirdParty/libzip/zip_string.c b/ePub3/ThirdParty/libzip/zip_string.c new file mode 100644 index 000000000..307a425f7 --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_string.c @@ -0,0 +1,188 @@ +/* + zip_string.c -- string handling (with encoding) + Copyright (C) 2012-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include +#include + +#include "zipint.h" + + +zip_uint32_t +_zip_string_crc32(const zip_string_t *s) +{ + zip_uint32_t crc; + + crc = (zip_uint32_t)crc32(0L, Z_NULL, 0); + + if (s != NULL) + crc = (zip_uint32_t)crc32(crc, s->raw, s->length); + + return crc; +} + + +int +_zip_string_equal(const zip_string_t *a, const zip_string_t *b) +{ + if (a == NULL || b == NULL) + return a == b; + + if (a->length != b->length) + return 0; + + /* TODO: encoding */ + + return (memcmp(a->raw, b->raw, a->length) == 0); +} + + +void +_zip_string_free(zip_string_t *s) +{ + if (s == NULL) + return; + + free(s->raw); + free(s->converted); + free(s); +} + + +const zip_uint8_t * +_zip_string_get(zip_string_t *string, zip_uint32_t *lenp, zip_flags_t flags, zip_error_t *error) +{ + static const zip_uint8_t empty[1] = ""; + + if (string == NULL) { + if (lenp) + *lenp = 0; + return empty; + } + + if ((flags & ZIP_FL_ENC_RAW) == 0) { + /* start guessing */ + if (string->encoding == ZIP_ENCODING_UNKNOWN) + _zip_guess_encoding(string, ZIP_ENCODING_UNKNOWN); + + if (((flags & ZIP_FL_ENC_STRICT) + && string->encoding != ZIP_ENCODING_ASCII && string->encoding != ZIP_ENCODING_UTF8_KNOWN) + || (string->encoding == ZIP_ENCODING_CP437)) { + if (string->converted == NULL) { + if ((string->converted=_zip_cp437_to_utf8(string->raw, string->length, + &string->converted_length, error)) == NULL) + return NULL; + } + if (lenp) + *lenp = string->converted_length; + return string->converted; + } + } + + if (lenp) + *lenp = string->length; + return string->raw; +} + + +zip_uint16_t +_zip_string_length(const zip_string_t *s) +{ + if (s == NULL) + return 0; + + return s->length; +} + + +zip_string_t * +_zip_string_new(const zip_uint8_t *raw, zip_uint16_t length, zip_flags_t flags, zip_error_t *error) +{ + zip_string_t *s; + zip_encoding_type_t expected_encoding; + + if (length == 0) + return NULL; + + switch (flags & ZIP_FL_ENCODING_ALL) { + case ZIP_FL_ENC_GUESS: + expected_encoding = ZIP_ENCODING_UNKNOWN; + break; + case ZIP_FL_ENC_UTF_8: + expected_encoding = ZIP_ENCODING_UTF8_KNOWN; + break; + case ZIP_FL_ENC_CP437: + expected_encoding = ZIP_ENCODING_CP437; + break; + default: + zip_error_set(error, ZIP_ER_INVAL, 0); + return NULL; + } + + if ((s=(zip_string_t *)malloc(sizeof(*s))) == NULL) { + zip_error_set(error, ZIP_ER_MEMORY, 0); + return NULL; + } + + if ((s->raw=(zip_uint8_t *)malloc((size_t)(length+1))) == NULL) { + free(s); + return NULL; + } + + memcpy(s->raw, raw, length); + s->raw[length] = '\0'; + s->length = length; + s->encoding = ZIP_ENCODING_UNKNOWN; + s->converted = NULL; + s->converted_length = 0; + + if (expected_encoding != ZIP_ENCODING_UNKNOWN) { + if (_zip_guess_encoding(s, expected_encoding) == ZIP_ENCODING_ERROR) { + _zip_string_free(s); + zip_error_set(error, ZIP_ER_INVAL, 0); + return NULL; + } + } + + return s; +} + + +int +_zip_string_write(zip_t *za, const zip_string_t *s) +{ + if (s == NULL) + return 0; + + return _zip_write(za, s->raw, s->length); +} diff --git a/ePub3/ThirdParty/libzip/zip_unchange.c b/ePub3/ThirdParty/libzip/zip_unchange.c index ed0d4de65..6c8a495c7 100644 --- a/ePub3/ThirdParty/libzip/zip_unchange.c +++ b/ePub3/ThirdParty/libzip/zip_unchange.c @@ -1,6 +1,6 @@ /* zip_unchange.c -- undo changes to file in zip archive - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,50 +31,39 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include "zipint.h" - ZIP_EXTERN int -zip_unchange(struct zip *za, int idx) +zip_unchange(zip_t *za, zip_uint64_t idx) { return _zip_unchange(za, idx, 0); } - int -_zip_unchange(struct zip *za, int idx, int allow_duplicates) +_zip_unchange(zip_t *za, zip_uint64_t idx, int allow_duplicates) { - int i; + zip_int64_t i; - if (idx < 0 || idx >= za->nentry) { - _zip_error_set(&za->error, ZIP_ER_INVAL, 0); + if (idx >= za->nentry) { + zip_error_set(&za->error, ZIP_ER_INVAL, 0); return -1; } - if (za->entry[idx].ch_filename) { - if (!allow_duplicates) { - i = _zip_name_locate(za, - _zip_get_name(za, idx, ZIP_FL_UNCHANGED, NULL), - 0, NULL); - if (i != -1 && i != idx) { - _zip_error_set(&za->error, ZIP_ER_EXISTS, 0); - return -1; - } + if (!allow_duplicates && za->entry[idx].changes && (za->entry[idx].changes->changed & ZIP_DIRENT_FILENAME)) { + i = _zip_name_locate(za, _zip_get_name(za, idx, ZIP_FL_UNCHANGED, NULL), 0, NULL); + if (i >= 0 && (zip_uint64_t)i != idx) { + zip_error_set(&za->error, ZIP_ER_EXISTS, 0); + return -1; } - - free(za->entry[idx].ch_filename); - za->entry[idx].ch_filename = NULL; } - free(za->entry[idx].ch_comment); - za->entry[idx].ch_comment = NULL; - za->entry[idx].ch_comment_len = -1; + _zip_dirent_free(za->entry[idx].changes); + za->entry[idx].changes = NULL; _zip_unchange_data(za->entry+idx); diff --git a/ePub3/ThirdParty/libzip/zip_unchange_all.c b/ePub3/ThirdParty/libzip/zip_unchange_all.c index 54a7a0d2e..60076838d 100644 --- a/ePub3/ThirdParty/libzip/zip_unchange_all.c +++ b/ePub3/ThirdParty/libzip/zip_unchange_all.c @@ -1,6 +1,6 @@ /* zip_unchange.c -- undo changes to all files in zip archive - Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,18 +31,17 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include "zipint.h" - ZIP_EXTERN int -zip_unchange_all(struct zip *za) +zip_unchange_all(zip_t *za) { - int ret, i; + int ret; + zip_uint64_t i; ret = 0; for (i=0; inentry; i++) diff --git a/ePub3/ThirdParty/libzip/zip_unchange_archive.c b/ePub3/ThirdParty/libzip/zip_unchange_archive.c index 8f9c024c3..920255cc7 100644 --- a/ePub3/ThirdParty/libzip/zip_unchange_archive.c +++ b/ePub3/ThirdParty/libzip/zip_unchange_archive.c @@ -1,6 +1,6 @@ /* zip_unchange_archive.c -- undo global changes to ZIP archive - Copyright (C) 2006-2008 Dieter Baron and Thomas Klausner + Copyright (C) 2006-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -31,21 +31,21 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include "zipint.h" - ZIP_EXTERN int -zip_unchange_archive(struct zip *za) +zip_unchange_archive(zip_t *za) { - free(za->ch_comment); - za->ch_comment = NULL; - za->ch_comment_len = -1; - + if (za->comment_changed) { + _zip_string_free(za->comment_changes); + za->comment_changes = NULL; + za->comment_changed = 0; + } + za->ch_flags = za->flags; return 0; diff --git a/ePub3/ThirdParty/libzip/zip_unchange_data.c b/ePub3/ThirdParty/libzip/zip_unchange_data.c index 6fe89f4fb..839d9a3cb 100644 --- a/ePub3/ThirdParty/libzip/zip_unchange_data.c +++ b/ePub3/ThirdParty/libzip/zip_unchange_data.c @@ -1,8 +1,6 @@ /* - $NiH: zip_unchange_data.c,v 1.14 2004/11/30 23:02:47 wiz Exp $ - zip_unchange_data.c -- undo helper function - Copyright (C) 1999, 2004 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -33,21 +31,25 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - - -#include #include "zipint.h" void -_zip_unchange_data(struct zip_entry *ze) +_zip_unchange_data(zip_entry_t *ze) { if (ze->source) { - (void)ze->source->f(ze->source->ud, NULL, 0, ZIP_SOURCE_FREE); - free(ze->source); + zip_source_free(ze->source); ze->source = NULL; } - - ze->state = ze->ch_filename ? ZIP_ST_RENAMED : ZIP_ST_UNCHANGED; + + if (ze->changes != NULL && (ze->changes->changed & ZIP_DIRENT_COMP_METHOD) && ze->changes->comp_method == ZIP_CM_REPLACED_DEFAULT) { + ze->changes->changed &= ~ZIP_DIRENT_COMP_METHOD; + if (ze->changes->changed == 0) { + _zip_dirent_free(ze->changes); + ze->changes = NULL; + } + } + + ze->deleted = 0; } diff --git a/ePub3/ThirdParty/libzip/zip_utf-8.c b/ePub3/ThirdParty/libzip/zip_utf-8.c new file mode 100644 index 000000000..f38eea04d --- /dev/null +++ b/ePub3/ThirdParty/libzip/zip_utf-8.c @@ -0,0 +1,249 @@ +/* + zip_utf-8.c -- UTF-8 support functions for libzip + Copyright (C) 2011-2014 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" + +#include + + +static const zip_uint16_t _cp437_to_unicode[256] = { + /* 0x00 - 0x0F */ + 0x2007, 0x263A, 0x263B, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022, + 0x25D8, 0x25CB, 0x25D9, 0x2642, 0x2640, 0x266A, 0x266B, 0x263C, + + /* 0x10 - 0x1F */ + 0x25BA, 0x25C4, 0x2195, 0x203C, 0x00B6, 0x00A7, 0x25AC, 0x21A8, + 0x2191, 0x2193, 0x2192, 0x2190, 0x221F, 0x2194, 0x25B2, 0x25BC, + + /* 0x20 - 0x2F */ + 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, + 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, + + /* 0x30 - 0x3F */ + 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, + 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, + + /* 0x40 - 0x4F */ + 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, + 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, + + /* 0x50 - 0x5F */ + 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, + 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F, + + /* 0x60 - 0x6F */ + 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, + 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, + + /* 0x70 - 0x7F */ + 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, + 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x2302, + + /* 0x80 - 0x8F */ + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, + 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, + + /* 0x90 - 0x9F */ + 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, + 0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192, + + /* 0xA0 - 0xAF */ + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, + 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, + + /* 0xB0 - 0xBF */ + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, + 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, + + /* 0xC0 - 0xCF */ + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, + 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + + /* 0xD0 - 0xDF */ + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, + 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + + /* 0xE0 - 0xEF */ + 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, + 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229, + + /* 0xF0 - 0xFF */ + 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, + 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 +}; + +#define UTF_8_LEN_2_MASK 0xe0 +#define UTF_8_LEN_2_MATCH 0xc0 +#define UTF_8_LEN_3_MASK 0xf0 +#define UTF_8_LEN_3_MATCH 0xe0 +#define UTF_8_LEN_4_MASK 0xf8 +#define UTF_8_LEN_4_MATCH 0xf0 +#define UTF_8_CONTINUE_MASK 0xc0 +#define UTF_8_CONTINUE_MATCH 0x80 + + +zip_encoding_type_t +_zip_guess_encoding(zip_string_t *str, zip_encoding_type_t expected_encoding) +{ + zip_encoding_type_t enc; + const zip_uint8_t *name; + zip_uint32_t i, j, ulen; + + if (str == NULL) + return ZIP_ENCODING_ASCII; + + name = str->raw; + + if (str->encoding != ZIP_ENCODING_UNKNOWN) + enc = str->encoding; + else { + enc = ZIP_ENCODING_ASCII; + for (i=0; ilength; i++) { + if ((name[i] > 31 && name[i] < 128) || name[i] == '\r' || name[i] == '\n' || name[i] == '\t') + continue; + + enc = ZIP_ENCODING_UTF8_GUESSED; + if ((name[i] & UTF_8_LEN_2_MASK) == UTF_8_LEN_2_MATCH) + ulen = 1; + else if ((name[i] & UTF_8_LEN_3_MASK) == UTF_8_LEN_3_MATCH) + ulen = 2; + else if ((name[i] & UTF_8_LEN_4_MASK) == UTF_8_LEN_4_MATCH) + ulen = 3; + else { + enc = ZIP_ENCODING_CP437; + break; + } + + if (i + ulen >= str->length) { + enc = ZIP_ENCODING_CP437; + break; + } + + for (j=1; j<=ulen; j++) { + if ((name[i+j] & UTF_8_CONTINUE_MASK) != UTF_8_CONTINUE_MATCH) { + enc = ZIP_ENCODING_CP437; + goto done; + } + } + i += ulen; + } + } + +done: + str->encoding = enc; + + if (expected_encoding != ZIP_ENCODING_UNKNOWN) { + if (expected_encoding == ZIP_ENCODING_UTF8_KNOWN && enc == ZIP_ENCODING_UTF8_GUESSED) + str->encoding = enc = ZIP_ENCODING_UTF8_KNOWN; + + if (expected_encoding != enc && enc != ZIP_ENCODING_ASCII) + return ZIP_ENCODING_ERROR; + } + + return enc; +} + + +static zip_uint32_t +_zip_unicode_to_utf8_len(zip_uint32_t codepoint) +{ + if (codepoint < 0x0080) + return 1; + if (codepoint < 0x0800) + return 2; + if (codepoint < 0x10000) + return 3; + return 4; +} + + +static zip_uint32_t +_zip_unicode_to_utf8(zip_uint32_t codepoint, zip_uint8_t *buf) +{ + if (codepoint < 0x0080) { + buf[0] = codepoint & 0xff; + return 1; + } + if (codepoint < 0x0800) { + buf[0] = (zip_uint8_t)(UTF_8_LEN_2_MATCH | ((codepoint >> 6) & 0x1f)); + buf[1] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | (codepoint & 0x3f)); + return 2; + } + if (codepoint < 0x10000) { + buf[0] = (zip_uint8_t)(UTF_8_LEN_3_MATCH | ((codepoint >> 12) & 0x0f)); + buf[1] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | ((codepoint >> 6) & 0x3f)); + buf[2] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | (codepoint & 0x3f)); + return 3; + } + buf[0] = (zip_uint8_t)(UTF_8_LEN_4_MATCH | ((codepoint >> 18) & 0x07)); + buf[1] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | ((codepoint >> 12) & 0x3f)); + buf[2] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | ((codepoint >> 6) & 0x3f)); + buf[3] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | (codepoint & 0x3f)); + return 4; +} + + +zip_uint8_t * +_zip_cp437_to_utf8(const zip_uint8_t * const _cp437buf, zip_uint32_t len, + zip_uint32_t *utf8_lenp, zip_error_t *error) +{ + zip_uint8_t *cp437buf = (zip_uint8_t *)_cp437buf; + zip_uint8_t *utf8buf; + zip_uint32_t buflen, i, offset; + + if (len == 0) { + if (utf8_lenp) + *utf8_lenp = 0; + return NULL; + } + + buflen = 1; + for (i=0; i +#elif defined(HAVE_INTTYPES_H_LIBZIP) +#include +#elif defined(HAVE_SYS_TYPES_H_LIBZIP) +#include +#endif + +#if defined(HAVE_INT8_T_LIBZIP) +typedef int8_t zip_int8_t; +#elif defined(HAVE___INT8_LIBZIP) +typedef __int8 zip_int8_t; +#else +typedef signed char zip_int8_t; +#endif +#if defined(HAVE_UINT8_T_LIBZIP) +typedef uint8_t zip_uint8_t; +#elif defined(HAVE___INT8_LIBZIP) +typedef unsigned __int8 zip_uint8_t; +#else +typedef unsigned char zip_uint8_t; +#endif +#if defined(HAVE_INT16_T_LIBZIP) +typedef int16_t zip_int16_t; +#elif defined(HAVE___INT16_LIBZIP) +typedef __int16 zip_int16_t; +#elif defined(SHORT_LIBZIP) && SHORT_LIBZIP == 2 +typedef signed short zip_int16_t; +#endif +#if defined(HAVE_UINT16_T_LIBZIP) +typedef uint16_t zip_uint16_t; +#elif defined(HAVE___INT16_LIBZIP) +typedef unsigned __int16 zip_uint16_t; +#elif defined(SHORT_LIBZIP) && SHORT_LIBZIP == 2 +typedef unsigned short zip_uint16_t; +#endif +#if defined(HAVE_INT32_T_LIBZIP) +typedef int32_t zip_int32_t; +#elif defined(HAVE___INT32_LIBZIP) +typedef __int32 zip_int32_t; +#elif defined(INT_LIBZIP) && INT_LIBZIP == 4 +typedef signed int zip_int32_t; +#elif defined(LONG_LIBZIP) && LONG_LIBZIP == 4 +typedef signed long zip_int32_t; +#endif +#if defined(HAVE_UINT32_T_LIBZIP) +typedef uint32_t zip_uint32_t; +#elif defined(HAVE___INT32_LIBZIP) +typedef unsigned __int32 zip_uint32_t; +#elif defined(INT_LIBZIP) && INT_LIBZIP == 4 +typedef unsigned int zip_uint32_t; +#elif defined(LONG_LIBZIP) && LONG_LIBZIP == 4 +typedef unsigned long zip_uint32_t; +#endif +#if defined(HAVE_INT64_T_LIBZIP) +typedef int64_t zip_int64_t; +#elif defined(HAVE___INT64_LIBZIP) +typedef __int64 zip_int64_t; +#elif defined(LONG_LIBZIP) && LONG_LIBZIP == 8 +typedef signed long zip_int64_t; +#elif defined(LONG_LONG_LIBZIP) && LONG_LONG_LIBZIP == 8 +typedef signed long long zip_int64_t; +#endif +#if defined(HAVE_UINT64_T_LIBZIP) +typedef uint64_t zip_uint64_t; +#elif defined(HAVE___INT64_LIBZIP) +typedef unsigned __int64 zip_uint64_t; +#elif defined(LONG_LIBZIP) && LONG_LONG_LIBZIP == 8 +typedef unsigned long zip_uint64_t; +#elif defined(LONG_LONG_LIBZIP) && LONG_LONG_LIBZIP == 8 +typedef unsigned long long zip_uint64_t; +#endif + +#define ZIP_INT8_MIN -0x80 +#define ZIP_INT8_MAX 0x7f +#define ZIP_UINT8_MAX 0xff + +#define ZIP_INT16_MIN -0x8000 +#define ZIP_INT16_MAX 0x7fff +#define ZIP_UINT16_MAX 0xffff + +#define ZIP_INT32_MIN -0x80000000L +#define ZIP_INT32_MAX 0x7fffffffL +#define ZIP_UINT32_MAX 0xffffffffLU + +#define ZIP_INT64_MIN -0x8000000000000000LL +#define ZIP_INT64_MAX 0x7fffffffffffffffLL +#define ZIP_UINT64_MAX 0xffffffffffffffffULL + +#endif /* zipconf.h */ diff --git a/ePub3/ThirdParty/libzip/zipint.h b/ePub3/ThirdParty/libzip/zipint.h index a4557ee1d..f7b4313e7 100644 --- a/ePub3/ThirdParty/libzip/zipint.h +++ b/ePub3/ThirdParty/libzip/zipint.h @@ -3,7 +3,7 @@ /* zipint.h -- internal declarations. - Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -34,235 +34,512 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +//#ifdef HAVE_CONFIG_H +#include "Config.h" +//#endif + +/* to have *_MAX definitions for all types when compiling with g++ */ +#define __STDC_LIMIT_MACROS + #include -#include "zip.h" -#include "Config.h" +#ifdef _WIN32 +#define ZIP_EXTERN __declspec(dllexport) +/* for dup(), close(), etc. */ +#include +#endif -#ifndef HAVE_MKSTEMP -int _zip_mkstemp(char *); -#define mkstemp _zip_mkstemp +#ifndef _ZIP_COMPILING_DEPRECATED +#define ZIP_DISABLE_DEPRECATED #endif -#ifdef HAVE_MOVEFILEEXA -#include -#define _zip_rename(s, t) \ - (!MoveFileExA((s), (t), \ - MOVEFILE_COPY_ALLOWED|MOVEFILE_REPLACE_EXISTING)) +#include "zip.h" + +#ifdef HAVE_STDBOOL_H +#include #else -#define _zip_rename rename +typedef char bool; +#define true 1 +#define false 0 +#endif + +#ifdef _WIN32 +#if defined(HAVE__CLOSE) +#define close _close +#endif +#if defined(HAVE__DUP) +#define dup _dup +#endif +/* crashes reported when using fdopen instead of _fdopen on Windows/Visual Studio 10/Win64 */ +#if defined(HAVE__FDOPEN) +#define fdopen _fdopen +#endif +#if defined(HAVE__FILENO) +#define fileno _fileno +#endif +/* Windows' open() doesn't understand Unix permissions */ +#if defined(HAVE__OPEN) +#define open(a, b, c) _open((a), (b)) +#endif +#if defined(HAVE__SNPRINTF) +#define snprintf _snprintf +#endif +#if defined(HAVE__STRDUP) +#if !defined(HAVE_STRDUP) || defined(_WIN32) +#undef strdup +#define strdup _strdup +#endif +#endif #endif #ifndef HAVE_FSEEKO #define fseeko(s, o, w) (fseek((s), (long int)(o), (w))) #endif + #ifndef HAVE_FTELLO #define ftello(s) ((long)ftell((s))) #endif - +#ifndef HAVE_MKSTEMP +int _zip_mkstemp(char *); +#define mkstemp _zip_mkstemp +#endif + +#if !defined(HAVE_STRCASECMP) +#if defined(HAVE__STRICMP) +#define strcasecmp _stricmp +#endif +#endif + +#if SIZEOF_OFF_T == 8 +#define ZIP_OFF_MAX ZIP_INT64_MAX +#define ZIP_OFF_MIN ZIP_INT64_MIN +#elif SIZEOF_OFF_T == 4 +#define ZIP_OFF_MAX ZIP_INT32_MAX +#define ZIP_OFF_MIN ZIP_INT32_MIN +#elif SIZEOF_OFF_T == 2 +#define ZIP_OFF_MAX ZIP_INT16_MAX +#define ZIP_OFF_MIN ZIP_INT16_MIN +#else +#error unsupported size of off_t +#endif + +#if defined(HAVE_FTELLO) && defined(HAVE_FSEEKO) +#define ZIP_FSEEK_MAX ZIP_OFF_MAX +#define ZIP_FSEEK_MIN ZIP_OFF_MIN +#else +#define ZIP_FSEEK_MAX LONG_MAX +#define ZIP_FSEEK_MIN LONG_MIN +#endif + +#ifndef SIZE_MAX +#if SIZEOF_SIZE_T == 8 +#define SIZE_MAX ZIP_INT64_MAX +#elif SIZEOF_SIZE_T == 4 +#define SIZE_MAX ZIP_INT32_MAX +#elif SIZEOF_SIZE_T == 2 +#define SIZE_MAX ZIP_INT16_MAX +#else +#error unsupported size of size_t +#endif +#endif #define CENTRAL_MAGIC "PK\1\2" #define LOCAL_MAGIC "PK\3\4" #define EOCD_MAGIC "PK\5\6" #define DATADES_MAGIC "PK\7\8" -#define TORRENT_SIG "TORRENTZIPPED-" -#define TORRENT_SIG_LEN 14 -#define TORRENT_CRC_LEN 8 -#define TORRENT_MEM_LEVEL 8 +#define EOCD64LOC_MAGIC "PK\6\7" +#define EOCD64_MAGIC "PK\6\6" #define CDENTRYSIZE 46u #define LENTRYSIZE 30 #define MAXCOMLEN 65536 +#define MAXEXTLEN 65536 #define EOCDLEN 22 -#define CDBUFSIZE (MAXCOMLEN+EOCDLEN) +#define EOCD64LOCLEN 20 +#define EOCD64LEN 56 +#define CDBUFSIZE (MAXCOMLEN+EOCDLEN+EOCD64LOCLEN) #define BUFSIZE 8192 +#define EFZIP64SIZE 28 + +#define ZIP_CM_REPLACED_DEFAULT (-2) + +#define ZIP_CM_IS_DEFAULT(x) ((x) == ZIP_CM_DEFAULT || (x) == ZIP_CM_REPLACED_DEFAULT) + +#define ZIP_EF_UTF_8_COMMENT 0x6375 +#define ZIP_EF_UTF_8_NAME 0x7075 +#define ZIP_EF_ZIP64 0x0001 + +#define ZIP_EF_IS_INTERNAL(id) ((id) == ZIP_EF_UTF_8_COMMENT || (id) == ZIP_EF_UTF_8_NAME || (id) == ZIP_EF_ZIP64) + +/* according to unzip-6.0's zipinfo.c, this corresponds to a regular file with rw permissions for everyone */ +#define ZIP_EXT_ATTRIB_DEFAULT (0100666u<<16) +/* according to unzip-6.0's zipinfo.c, this corresponds to a directory with rwx permissions for everyone */ +#define ZIP_EXT_ATTRIB_DEFAULT_DIR (0040777u<<16) + + +#define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b)) +#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b)) - +/* This section contains API that won't materialize like this. It's + placed in the internal section, pending cleanup. */ -/* state of change of a file in zip archive */ +/* flags for compression and encryption sources */ -enum zip_state { ZIP_ST_UNCHANGED, ZIP_ST_DELETED, ZIP_ST_REPLACED, - ZIP_ST_ADDED, ZIP_ST_RENAMED }; +#define ZIP_CODEC_DECODE 0 /* decompress/decrypt (encode flag not set) */ +#define ZIP_CODEC_ENCODE 1 /* compress/encrypt */ -/* constants for struct zip_file's member flags */ -#define ZIP_ZF_EOF 1 /* EOF reached */ -#define ZIP_ZF_DECOMP 2 /* decompress data */ -#define ZIP_ZF_CRC 4 /* compute and compare CRC */ +typedef zip_source_t *(*zip_compression_implementation)(zip_t *, zip_source_t *, zip_int32_t, int); +typedef zip_source_t *(*zip_encryption_implementation)(zip_t *, zip_source_t *, zip_uint16_t, int, const char *); + +zip_compression_implementation _zip_get_compression_implementation(zip_int32_t); +zip_encryption_implementation _zip_get_encryption_implementation(zip_uint16_t); + + + +/* This API is not final yet, but we need it internally, so it's private for now. */ + +const zip_uint8_t *zip_get_extra_field_by_id(zip_t *, int, int, zip_uint16_t, int, zip_uint16_t *); + +/* This section contains API that is of limited use until support for + user-supplied compression/encryption implementation is finished. + Thus we will keep it private for now. */ + +typedef zip_int64_t (*zip_source_layered_callback)(zip_source_t *, void *, void *, zip_uint64_t, enum zip_source_cmd); +zip_source_t *zip_source_crc(zip_t *, zip_source_t *, int); +zip_source_t *zip_source_deflate(zip_t *, zip_source_t *, zip_int32_t, int); +zip_source_t *zip_source_layered(zip_t *, zip_source_t *, zip_source_layered_callback, void *); +zip_source_t *zip_source_layered_create(zip_source_t *src, zip_source_layered_callback cb, void *ud, zip_error_t *error); +zip_source_t *zip_source_pkware(zip_t *, zip_source_t *, zip_uint16_t, int, const char *); +int zip_source_remove(zip_source_t *); +zip_int64_t zip_source_supports(zip_source_t *src); +zip_source_t *zip_source_window(zip_t *, zip_source_t *, zip_uint64_t, zip_uint64_t); + + +/* error source for layered sources */ + +enum zip_les { ZIP_LES_NONE, ZIP_LES_UPPER, ZIP_LES_LOWER, ZIP_LES_INVAL }; /* directory entry: general purpose bit flags */ #define ZIP_GPBF_ENCRYPTED 0x0001 /* is encrypted */ #define ZIP_GPBF_DATA_DESCRIPTOR 0x0008 /* crc/size after file data */ #define ZIP_GPBF_STRONG_ENCRYPTION 0x0040 /* uses strong encryption */ +#define ZIP_GPBF_ENCODING_UTF_8 0x0800 /* file name encoding is UTF-8 */ + + +/* extra fields */ +#define ZIP_EF_LOCAL ZIP_FL_LOCAL /* include in local header */ +#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL /* include in central directory */ +#define ZIP_EF_BOTH (ZIP_EF_LOCAL|ZIP_EF_CENTRAL) /* include in both */ -/* error information */ +#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */ -struct zip_error { - int zip_err; /* libzip error code (ZIP_ER_*) */ - int sys_err; /* copy of errno (E*) or zlib error code */ - char *str; /* string representation or NULL */ +#define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS|ZIP_FL_ENC_CP437|ZIP_FL_ENC_UTF_8) + + +/* encoding type */ +enum zip_encoding_type { + ZIP_ENCODING_UNKNOWN, /* not yet analyzed */ + ZIP_ENCODING_ASCII, /* plain ASCII */ + ZIP_ENCODING_UTF8_KNOWN, /* is UTF-8 */ + ZIP_ENCODING_UTF8_GUESSED, /* possibly UTF-8 */ + ZIP_ENCODING_CP437, /* Code Page 437 */ + ZIP_ENCODING_ERROR /* should be UTF-8 but isn't */ }; +typedef enum zip_encoding_type zip_encoding_type_t; + +typedef struct zip_cdir zip_cdir_t; +typedef struct zip_dirent zip_dirent_t; +typedef struct zip_entry zip_entry_t; +typedef struct zip_extra_field zip_extra_field_t; +typedef struct zip_string zip_string_t; +typedef struct zip_buffer zip_buffer_t; + + /* zip archive, part of API */ struct zip { - char *zn; /* file name */ - FILE *zp; /* file */ - struct zip_error error; /* error information */ - - unsigned int flags; /* archive global flags */ - unsigned int ch_flags; /* changed archive global flags */ - - struct zip_cdir *cdir; /* central directory */ - char *ch_comment; /* changed archive comment */ - int ch_comment_len; /* length of changed zip archive - * comment, -1 if unchanged */ - int nentry; /* number of entries */ - int nentry_alloc; /* number of entries allocated */ - struct zip_entry *entry; /* entries */ - int nfile; /* number of opened files within archive */ - int nfile_alloc; /* number of files allocated */ - struct zip_file **file; /* opened files within archive */ + zip_source_t *src; /* data source for archive */ + unsigned int open_flags; /* flags passed to zip_open */ + zip_error_t error; /* error information */ + + unsigned int flags; /* archive global flags */ + unsigned int ch_flags; /* changed archive global flags */ + + char *default_password; /* password used when no other supplied */ + + zip_string_t *comment_orig; /* archive comment */ + zip_string_t *comment_changes; /* changed archive comment */ + bool comment_changed; /* whether archive comment was changed */ + + zip_uint64_t nentry; /* number of entries */ + zip_uint64_t nentry_alloc; /* number of entries allocated */ + zip_entry_t *entry; /* entries */ + + unsigned int nopen_source; /* number of open sources using archive */ + unsigned int nopen_source_alloc; /* number of sources allocated */ + zip_source_t **open_source; /* open sources using archive */ + + char *tempdir; /* custom temp dir (needed e.g. for OS X sandboxing) */ }; /* file in zip archive, part of API */ struct zip_file { - struct zip *za; /* zip archive containing this file */ - struct zip_error error; /* error information */ - int flags; /* -1: eof, >0: error */ - - int method; /* compression method */ - off_t fpos; /* position within zip file (fread/fwrite) */ - unsigned long bytes_left; /* number of bytes left to read */ - unsigned long cbytes_left; /* number of bytes of compressed data left */ - - unsigned long crc; /* CRC so far */ - unsigned long crc_orig; /* CRC recorded in archive */ - - char *buffer; - z_stream *zstr; - - /* JCD added below */ - - int file_index; /* index of this file in the zip archive */ - off_t file_fpos; /* position within this file itself -- relative to data type being returned */ - /* i.e. if ZIP_FL_COMPRESSED, this is offset into compressed bytes, */ - /* otherwise offset is into decompressed bytes */ + zip_t *za; /* zip archive containing this file */ + zip_error_t error; /* error information */ + bool eof; + zip_source_t *src; /* data source */ }; /* zip archive directory entry (central or local) */ +#define ZIP_DIRENT_COMP_METHOD 0x0001u +#define ZIP_DIRENT_FILENAME 0x0002u +#define ZIP_DIRENT_COMMENT 0x0004u +#define ZIP_DIRENT_EXTRA_FIELD 0x0008u +#define ZIP_DIRENT_ATTRIBUTES 0x0010u +#define ZIP_DIRENT_LAST_MOD 0x0020u +#define ZIP_DIRENT_ALL 0xffffu + struct zip_dirent { - unsigned short version_madeby; /* (c) version of creator */ - unsigned short version_needed; /* (cl) version needed to extract */ - unsigned short bitflags; /* (cl) general purpose bit flag */ - unsigned short comp_method; /* (cl) compression method used */ + zip_uint32_t changed; + bool local_extra_fields_read; /* whether we already read in local header extra fields */ + bool cloned; /* whether this instance is cloned, and thus shares non-changed strings */ + + zip_uint16_t version_madeby; /* (c) version of creator */ + zip_uint16_t version_needed; /* (cl) version needed to extract */ + zip_uint16_t bitflags; /* (cl) general purpose bit flag */ + zip_int32_t comp_method; /* (cl) compression method used (uint16 and ZIP_CM_DEFAULT (-1)) */ time_t last_mod; /* (cl) time of last modification */ - unsigned int crc; /* (cl) CRC-32 of uncompressed data */ - unsigned int comp_size; /* (cl) size of commpressed data */ - unsigned int uncomp_size; /* (cl) size of uncommpressed data */ - char *filename; /* (cl) file name (NUL-terminated) */ - unsigned short filename_len; /* (cl) length of filename (w/o NUL) */ - char *extrafield; /* (cl) extra field */ - unsigned short extrafield_len; /* (cl) length of extra field */ - char *comment; /* (c) file comment */ - unsigned short comment_len; /* (c) length of file comment */ - unsigned short disk_number; /* (c) disk number start */ - unsigned short int_attrib; /* (c) internal file attributes */ - unsigned int ext_attrib; /* (c) external file attributes */ - unsigned int offset; /* (c) offset of local header */ + zip_uint32_t crc; /* (cl) CRC-32 of uncompressed data */ + zip_uint64_t comp_size; /* (cl) size of compressed data */ + zip_uint64_t uncomp_size; /* (cl) size of uncompressed data */ + zip_string_t *filename; /* (cl) file name (NUL-terminated) */ + zip_extra_field_t *extra_fields; /* (cl) extra fields, parsed */ + zip_string_t *comment; /* (c) file comment */ + zip_uint32_t disk_number; /* (c) disk number start */ + zip_uint16_t int_attrib; /* (c) internal file attributes */ + zip_uint32_t ext_attrib; /* (c) external file attributes */ + zip_uint64_t offset; /* (c) offset of local header */ }; /* zip archive central directory */ struct zip_cdir { - struct zip_dirent *entry; /* directory entries */ - int nentry; /* number of entries */ + zip_entry_t *entry; /* directory entries */ + zip_uint64_t nentry; /* number of entries */ + zip_uint64_t nentry_alloc; /* number of entries allocated */ + + zip_uint64_t size; /* size of central directory */ + zip_uint64_t offset; /* offset of central directory in file */ + zip_string_t *comment; /* zip archive comment */ +}; - unsigned int size; /* size of central direcotry */ - unsigned int offset; /* offset of central directory in file */ - char *comment; /* zip archive comment */ - unsigned short comment_len; /* length of zip archive comment */ +struct zip_extra_field { + zip_extra_field_t *next; + zip_flags_t flags; /* in local/central header */ + zip_uint16_t id; /* header id */ + zip_uint16_t size; /* data size */ + zip_uint8_t *data; }; - +enum zip_source_write_state { + ZIP_SOURCE_WRITE_CLOSED, /* write is not in progress */ + ZIP_SOURCE_WRITE_OPEN, /* write is in progress */ + ZIP_SOURCE_WRITE_FAILED, /* commit failed, only rollback allowed */ + ZIP_SOURCE_WRITE_REMOVED /* file was removed */ +}; +typedef enum zip_source_write_state zip_source_write_state_t; struct zip_source { - zip_source_callback f; + zip_source_t *src; + union { + zip_source_callback f; + zip_source_layered_callback l; + } cb; void *ud; + zip_error_t error; + zip_int64_t supports; /* supported commands */ + unsigned int open_count; /* number of times source was opened (directly or as lower layer) */ + zip_source_write_state_t write_state; /* whether source is open for writing */ + bool source_closed; /* set if source archive is closed */ + zip_t *source_archive; /* zip archive we're reading from, NULL if not from archive */ + unsigned int refcount; }; +#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0) +#define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN) +#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL) + /* entry in zip archive directory */ struct zip_entry { - enum zip_state state; - struct zip_source *source; - char *ch_filename; - char *ch_comment; - int ch_comment_len; + zip_dirent_t *orig; + zip_dirent_t *changes; + zip_source_t *source; + bool deleted; }; - + +/* file or archive comment, or filename */ + +struct zip_string { + zip_uint8_t *raw; /* raw string */ + zip_uint16_t length; /* length of raw string */ + enum zip_encoding_type encoding; /* autorecognized encoding */ + zip_uint8_t *converted; /* autoconverted string */ + zip_uint32_t converted_length; /* length of converted */ +}; + + +/* bounds checked access to memory buffer */ + +struct zip_buffer { + bool ok; + bool free_data; + + zip_uint8_t *data; + zip_uint64_t size; + zip_uint64_t offset; +}; + +/* which files to write in which order */ + +struct zip_filelist { + zip_uint64_t idx; +// TODO const char *name; +}; + +typedef struct zip_filelist zip_filelist_t; + extern const char * const _zip_err_str[]; extern const int _zip_nerr_str; extern const int _zip_err_type[]; - - -#define ZIP_ENTRY_DATA_CHANGED(x) \ - ((x)->state == ZIP_ST_REPLACED \ - || (x)->state == ZIP_ST_ADDED) - - - -int _zip_cdir_compute_crc(struct zip *, uLong *); -void _zip_cdir_free(struct zip_cdir *); -int _zip_cdir_grow(struct zip_cdir *, int, struct zip_error *); -struct zip_cdir *_zip_cdir_new(int, struct zip_error *); -int _zip_cdir_write(struct zip_cdir *, FILE *, struct zip_error *); - -void _zip_dirent_finalize(struct zip_dirent *); -void _zip_dirent_init(struct zip_dirent *); -int _zip_dirent_read(struct zip_dirent *, FILE *, unsigned char **, - unsigned int *, int, struct zip_error *); -void _zip_dirent_torrent_normalize(struct zip_dirent *); -int _zip_dirent_write(struct zip_dirent *, FILE *, int, struct zip_error *); - -void _zip_entry_free(struct zip_entry *); -void _zip_entry_init(struct zip *, int); -struct zip_entry *_zip_entry_new(struct zip *); - -void _zip_error_clear(struct zip_error *); -void _zip_error_copy(struct zip_error *, struct zip_error *); -void _zip_error_fini(struct zip_error *); -void _zip_error_get(struct zip_error *, int *, int *); -void _zip_error_init(struct zip_error *); -void _zip_error_set(struct zip_error *, int, int); -const char *_zip_error_strerror(struct zip_error *); - -int _zip_file_fillbuf(void *, size_t, struct zip_file *); -unsigned int _zip_file_get_offset(struct zip *, int); -unsigned int _zip_file_get_offset_safe(struct zip*, int); /* JCD added, resets fpos before returning */ - -int _zip_filerange_crc(FILE *, off_t, off_t, uLong *, struct zip_error *); - -struct zip_source *_zip_source_file_or_p(struct zip *, const char *, FILE *, - off_t, off_t); - -void _zip_free(struct zip *); -const char *_zip_get_name(struct zip *, int, int, struct zip_error *); -int _zip_local_header_read(struct zip *, int); -void *_zip_memdup(const void *, size_t, struct zip_error *); -int _zip_name_locate(struct zip *, const char *, int, struct zip_error *); -struct zip *_zip_new(struct zip_error *); -unsigned short _zip_read2(unsigned char **); -unsigned int _zip_read4(unsigned char **); -int _zip_replace(struct zip *, int, const char *, struct zip_source *); -int _zip_set_name(struct zip *, int, const char *); -int _zip_unchange(struct zip *, int, int); -void _zip_unchange_data(struct zip_entry *); + +#define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f))) + +#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL) + +#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY) + + +zip_int64_t _zip_add_entry(zip_t *); + +zip_uint8_t *_zip_buffer_data(zip_buffer_t *buffer); +bool _zip_buffer_eof(zip_buffer_t *buffer); +void _zip_buffer_free(zip_buffer_t *buffer); +zip_uint8_t *_zip_buffer_get(zip_buffer_t *buffer, zip_uint64_t length); +zip_uint16_t _zip_buffer_get_16(zip_buffer_t *buffer); +zip_uint32_t _zip_buffer_get_32(zip_buffer_t *buffer); +zip_uint64_t _zip_buffer_get_64(zip_buffer_t *buffer); +zip_uint8_t _zip_buffer_get_8(zip_buffer_t *buffer); +zip_uint64_t _zip_buffer_left(zip_buffer_t *buffer); +zip_buffer_t *_zip_buffer_new(zip_uint8_t *data, zip_uint64_t size); +zip_buffer_t *_zip_buffer_new_from_source(zip_source_t *src, zip_uint64_t size, zip_uint8_t *buf, zip_error_t *error); +zip_uint64_t _zip_buffer_offset(zip_buffer_t *buffer); +bool _zip_buffer_ok(zip_buffer_t *buffer); +int _zip_buffer_put(zip_buffer_t *buffer, const void *src, size_t length); +int _zip_buffer_put_16(zip_buffer_t *buffer, zip_uint16_t i); +int _zip_buffer_put_32(zip_buffer_t *buffer, zip_uint32_t i); +int _zip_buffer_put_64(zip_buffer_t *buffer, zip_uint64_t i); +int _zip_buffer_put_8(zip_buffer_t *buffer, zip_uint8_t i); +int _zip_buffer_set_offset(zip_buffer_t *buffer, zip_uint64_t offset); +zip_uint64_t _zip_buffer_size(zip_buffer_t *buffer); + +int _zip_cdir_compute_crc(zip_t *, uLong *); +void _zip_cdir_free(zip_cdir_t *); +zip_cdir_t *_zip_cdir_new(zip_uint64_t, zip_error_t *); +zip_int64_t _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivors); +void _zip_deregister_source(zip_t *za, zip_source_t *src); + +zip_dirent_t *_zip_dirent_clone(const zip_dirent_t *); +void _zip_dirent_free(zip_dirent_t *); +void _zip_dirent_finalize(zip_dirent_t *); +void _zip_dirent_init(zip_dirent_t *); +bool _zip_dirent_needs_zip64(const zip_dirent_t *, zip_flags_t); +zip_dirent_t *_zip_dirent_new(void); +zip_int64_t _zip_dirent_read(zip_dirent_t *zde, zip_source_t *src, zip_buffer_t *buffer, bool local, zip_error_t *error); +zip_int32_t _zip_dirent_size(zip_source_t *src, zip_uint16_t, zip_error_t *); +int _zip_dirent_write(zip_t *za, zip_dirent_t *dirent, zip_flags_t flags); + +zip_extra_field_t *_zip_ef_clone(const zip_extra_field_t *, zip_error_t *); +zip_extra_field_t *_zip_ef_delete_by_id(zip_extra_field_t *, zip_uint16_t, zip_uint16_t, zip_flags_t); +void _zip_ef_free(zip_extra_field_t *); +const zip_uint8_t *_zip_ef_get_by_id(const zip_extra_field_t *, zip_uint16_t *, zip_uint16_t, zip_uint16_t, zip_flags_t, zip_error_t *); +zip_extra_field_t *_zip_ef_merge(zip_extra_field_t *, zip_extra_field_t *); +zip_extra_field_t *_zip_ef_new(zip_uint16_t, zip_uint16_t, const zip_uint8_t *, zip_flags_t); +zip_extra_field_t *_zip_ef_parse(const zip_uint8_t *, zip_uint16_t, zip_flags_t, zip_error_t *); +zip_extra_field_t *_zip_ef_remove_internal(zip_extra_field_t *); +zip_uint16_t _zip_ef_size(const zip_extra_field_t *, zip_flags_t); +int _zip_ef_write(zip_t *za, const zip_extra_field_t *ef, zip_flags_t flags); + +void _zip_entry_finalize(zip_entry_t *); +void _zip_entry_init(zip_entry_t *); + +void _zip_error_clear(zip_error_t *); +void _zip_error_get(const zip_error_t *, int *, int *); + +void _zip_error_copy(zip_error_t *dst, const zip_error_t *src); +void _zip_error_set_from_source(zip_error_t *, zip_source_t *); + +const zip_uint8_t *_zip_extract_extra_field_by_id(zip_error_t *, zip_uint16_t, int, const zip_uint8_t *, zip_uint16_t, zip_uint16_t *); + +int _zip_file_extra_field_prepare_for_change(zip_t *, zip_uint64_t); +int _zip_file_fillbuf(void *, size_t, zip_file_t *); +zip_uint64_t _zip_file_get_offset(const zip_t *, zip_uint64_t, zip_error_t *); + +int _zip_filerange_crc(zip_source_t *src, zip_uint64_t offset, zip_uint64_t length, uLong *crcp, zip_error_t *error); + +zip_dirent_t *_zip_get_dirent(zip_t *, zip_uint64_t, zip_flags_t, zip_error_t *); + +enum zip_encoding_type _zip_guess_encoding(zip_string_t *, enum zip_encoding_type); +zip_uint8_t *_zip_cp437_to_utf8(const zip_uint8_t * const, zip_uint32_t, zip_uint32_t *, zip_error_t *); + +zip_t *_zip_open(zip_source_t *, unsigned int, zip_error_t *); + +int _zip_read(zip_source_t *src, zip_uint8_t *data, zip_uint64_t length, zip_error_t *error); +int _zip_read_at_offset(zip_source_t *src, zip_uint64_t offset, unsigned char *b, size_t length, zip_error_t *error); +zip_uint8_t *_zip_read_data(zip_buffer_t *buffer, zip_source_t *src, size_t length, bool nulp, zip_error_t *error); +int _zip_read_local_ef(zip_t *, zip_uint64_t); +zip_string_t *_zip_read_string(zip_buffer_t *buffer, zip_source_t *src, zip_uint16_t lenght, bool nulp, zip_error_t *error); +int _zip_register_source(zip_t *za, zip_source_t *src); + +void _zip_set_open_error(int *zep, const zip_error_t *err, int ze); + +zip_int64_t _zip_source_call(zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command); +zip_source_t *_zip_source_file_or_p(const char *, FILE *, zip_uint64_t, zip_int64_t, const zip_stat_t *, zip_error_t *error); +void _zip_source_invalidate(zip_source_t *src); +zip_source_t *_zip_source_new(zip_error_t *error); +int _zip_source_set_source_archive(zip_source_t *, zip_t *); +zip_source_t *_zip_source_window_new(zip_source_t *src, zip_uint64_t start, zip_uint64_t length, zip_stat_t *st, zip_error_t *error); +zip_source_t *_zip_source_zip_new(zip_t *, zip_t *, zip_uint64_t, zip_flags_t, zip_uint64_t, zip_uint64_t, const char *); + +int _zip_stat_merge(zip_stat_t *dst, const zip_stat_t *src, zip_error_t *error); +int _zip_string_equal(const zip_string_t *, const zip_string_t *); +void _zip_string_free(zip_string_t *); +zip_uint32_t _zip_string_crc32(const zip_string_t *); +const zip_uint8_t *_zip_string_get(zip_string_t *, zip_uint32_t *, zip_flags_t, zip_error_t *); +zip_uint16_t _zip_string_length(const zip_string_t *); +zip_string_t *_zip_string_new(const zip_uint8_t *, zip_uint16_t, zip_flags_t, zip_error_t *); +int _zip_string_write(zip_t *za, const zip_string_t *string); + +int _zip_changed(const zip_t *, zip_uint64_t *); +const char *_zip_get_name(zip_t *, zip_uint64_t, zip_flags_t, zip_error_t *); +int _zip_local_header_read(zip_t *, int); +void *_zip_memdup(const void *, size_t, zip_error_t *); +zip_int64_t _zip_name_locate(zip_t *, const char *, zip_flags_t, zip_error_t *); +zip_t *_zip_new(zip_error_t *); + +zip_int64_t _zip_file_replace(zip_t *, zip_uint64_t, const char *, zip_source_t *, zip_flags_t); +int _zip_set_name(zip_t *, zip_uint64_t, const char *, zip_flags_t); +void _zip_u2d_time(time_t, zip_uint16_t *, zip_uint16_t *); +int _zip_unchange(zip_t *, zip_uint64_t, int); +void _zip_unchange_data(zip_entry_t *); +int _zip_write(zip_t *za, const void *data, zip_uint64_t length); #endif /* zipint.h */ diff --git a/ePub3/ThirdParty/libzip/zipwin32.h b/ePub3/ThirdParty/libzip/zipwin32.h new file mode 100644 index 000000000..4fa29ccee --- /dev/null +++ b/ePub3/ThirdParty/libzip/zipwin32.h @@ -0,0 +1,80 @@ +#ifndef _HAD_ZIPWIN32_H +#define _HAD_ZIPWIN32_H + +/* + zipwin32.h -- internal declarations for Windows. + Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include + +/* context for Win32 source */ + +struct _zip_source_win32_file_ops; + +struct _zip_source_win32_read_file { + zip_error_t error; /* last error information */ + zip_int64_t supports; + + /* operations */ + struct _zip_source_win32_file_ops *ops; + + /* reading */ + void *fname; /* name of file to read from - ANSI (char *) or Unicode (wchar_t *) */ + void *h; /* HANDLE for file to read from */ + int closep; /* whether to close f on ZIP_CMD_FREE */ + struct zip_stat st; /* stat information passed in */ + zip_uint64_t start; /* start offset of data to read */ + zip_uint64_t end; /* end offset of data to read, 0 for up to EOF */ + zip_uint64_t current; /* current offset */ + + /* writing */ + void *tmpname; /* name of temp file - ANSI (char *) or Unicode (wchar_t *) */ + void *hout; /* HANDLE for output file */ +}; + +typedef struct _zip_source_win32_read_file _zip_source_win32_read_file_t; + +/* internal operations for Win32 source */ + +struct _zip_source_win32_file_ops { + void *(*op_strdup)(const void *); + void *(*op_open)(_zip_source_win32_read_file_t *); + void *(*op_create_temp)(_zip_source_win32_read_file_t *, void **, zip_uint32_t, PSECURITY_ATTRIBUTES); + int (*op_rename_temp)(_zip_source_win32_read_file_t *); + int (*op_remove)(const void *); +}; + +typedef struct _zip_source_win32_file_ops _zip_source_win32_file_ops_t; + +zip_source_t *_zip_source_win32_handle_or_name(const void *, void *, zip_uint64_t, zip_int64_t, int, const zip_stat_t *, _zip_source_win32_file_ops_t *, zip_error_t *); + +#endif /* zipwin32.h */ diff --git a/ePub3/ePub/PassThroughFilter.h b/ePub3/ePub/PassThroughFilter.h index c1c584e87..b00721d4e 100644 --- a/ePub3/ePub/PassThroughFilter.h +++ b/ePub3/ePub/PassThroughFilter.h @@ -26,7 +26,7 @@ #include #include REGEX_INCLUDE #include -#import +#include //#import EPUB3_BEGIN_NAMESPACE diff --git a/ePub3/ePub/container.h b/ePub3/ePub/container.h index e63adb4da..cabe40c46 100644 --- a/ePub3/ePub/container.h +++ b/ePub3/ePub/container.h @@ -102,6 +102,7 @@ class Container : public PointerType /// /// Creates and returns a new Container instance by calling OpenContainerAsync() and blocking. + EPUB3_EXPORT static ContainerPtr OpenContainer(const string& path); diff --git a/ePub3/ePub/filter_chain.cpp b/ePub3/ePub/filter_chain.cpp index 9cc26339c..6cd40ee5d 100644 --- a/ePub3/ePub/filter_chain.cpp +++ b/ePub3/ePub/filter_chain.cpp @@ -138,7 +138,7 @@ std::shared_ptr FilterChain::GetFilterChainByteStreamRange(ConstMani std::unique_ptr FilterChain::GetFilterChainByteStreamRange(ConstManifestItemPtr item, SeekableByteStream *rawInput) const { unique_ptr resultStream; - uint nFilters = 0; + int nFilters = 0; for (ContentFilterPtr filter : _filters) { if (filter->TypeSniffer()(item)) diff --git a/ePub3/ePub/font_obfuscation.cpp b/ePub3/ePub/font_obfuscation.cpp index 76789040c..577257b42 100644 --- a/ePub3/ePub/font_obfuscation.cpp +++ b/ePub3/ePub/font_obfuscation.cpp @@ -27,6 +27,7 @@ #elif EPUB_PLATFORM(WIN) #include #include +#include "error_handler.h" #elif EPUB_PLATFORM(WINRT) using namespace ::Platform; using namespace ::Windows::Security::Cryptography; diff --git a/ePub3/ePub/initialization.cpp b/ePub3/ePub/initialization.cpp index ab54f6f4c..57d979590 100644 --- a/ePub3/ePub/initialization.cpp +++ b/ePub3/ePub/initialization.cpp @@ -53,5 +53,35 @@ void PopulateFilterManager() }); } -EPUB3_END_NAMESPACE +SDKInitializeAndRelease g_instance; + +SDKInitializeAndRelease::SDKInitializeAndRelease() +{ + if (this != &g_instance) + throw std::logic_error("SDKInitializeAndRelease should be a global static"); + + Initialize(); +} +SDKInitializeAndRelease::~SDKInitializeAndRelease() +{ + Teardown(); +} +void SDKInitializeAndRelease::Initialize() +{ +#if EPUB_USE(LIBXML2) + xmlInitParser(); // Please check this invocation before any libxml2 parsing +#endif +} +void SDKInitializeAndRelease::Teardown() +{ +#if EPUB_USE(LIBXML2) + // One should call xmlCleanupParser() only when the process has finished using the library and all XML/HTML documents built with it. + xmlCleanupParser(); +#endif +} +SDKInitializeAndRelease& SDKInitializeAndRelease::Instance() +{ + return g_instance; // returns the global static instance (for memory debugging purposes as the example) +} +EPUB3_END_NAMESPACE diff --git a/ePub3/ePub/initialization.h b/ePub3/ePub/initialization.h index 50a4ea1c8..9cf9e6bb0 100644 --- a/ePub3/ePub/initialization.h +++ b/ePub3/ePub/initialization.h @@ -25,9 +25,23 @@ EPUB3_BEGIN_NAMESPACE -void InitializeSdk(); +EPUB3_EXPORT void InitializeSdk(); + +EPUB3_EXPORT void PopulateFilterManager(); + +// The static signleton object, to initialize and teardown the SDK +// TODO: Add your global initialization and release code into Initialize() and Teardown() methods respectively +class SDKInitializeAndRelease +{ +private: +public: + SDKInitializeAndRelease(); + ~SDKInitializeAndRelease(); + EPUB3_EXPORT void Initialize(); // helper function, can be called to initialize the SDK memory (i.e. in case of memory leak debugging) + EPUB3_EXPORT void Teardown(); // helper function, can be called to release the SDK memory (i.e. in case of memory leak debugging) + EPUB3_EXPORT static SDKInitializeAndRelease& Instance(); +}; -void PopulateFilterManager(); EPUB3_END_NAMESPACE diff --git a/ePub3/ePub/media-overlays_smil_model.h b/ePub3/ePub/media-overlays_smil_model.h index 1ef9bcffc..d4635a507 100644 --- a/ePub3/ePub/media-overlays_smil_model.h +++ b/ePub3/ePub/media-overlays_smil_model.h @@ -134,14 +134,14 @@ Parser that reads SMIL XML files into an in-memory data model const void PercentToPosition(double percent, SMILDataPtr & smilData, uint32_t & smilIndex, shared_ptr& par, uint32_t & parIndex, uint32_t & milliseconds) const; - //EPUB3_EXPORT + EPUB3_EXPORT static std::vector::size_type GetSkippablesCount() { return _Skippables.size(); } - //EPUB3_EXPORT + EPUB3_EXPORT static string GetSkippable(std::vector::size_type i) { @@ -154,14 +154,14 @@ Parser that reads SMIL XML files into an in-memory data model return str; } - //EPUB3_EXPORT + EPUB3_EXPORT static std::vector::size_type GetEscapablesCount() { return _Escapables.size(); } - //EPUB3_EXPORT + EPUB3_EXPORT static string GetEscapable(std::vector::size_type i) { @@ -174,10 +174,10 @@ Parser that reads SMIL XML files into an in-memory data model return str; } - private: + public: static const std::vector _Skippables; static const std::vector _Escapables; - + private: bool _excludeAudioDuration; void resetData(); diff --git a/ePub3/ePub/nav_point.h b/ePub3/ePub/nav_point.h index a9f1b1822..ecb3eda3e 100644 --- a/ePub3/ePub/nav_point.h +++ b/ePub3/ePub/nav_point.h @@ -60,6 +60,7 @@ class NavigationPoint : public NavigationElement, public PointerType, public OwnedBy, public const string& Idref() const { return _idref; } /// /// Obtains the manifest item corresponding to this spine item. + EPUB3_EXPORT shared_ptr ManifestItem() const; /// /// Returns `true` if this item is linear, `false` otherwise. diff --git a/ePub3/ePub/zip_archive.cpp b/ePub3/ePub/zip_archive.cpp index e49afa9dc..ae164d6d6 100644 --- a/ePub3/ePub/zip_archive.cpp +++ b/ePub3/ePub/zip_archive.cpp @@ -20,11 +20,15 @@ #include "zip_archive.h" #include +#undef open //undefine the macro because of further complation error +#undef close //undefine the macro because of further complation error + #include "byte_stream.h" #include "make_unique.h" #include #include #include + #if EPUB_OS(UNIX) #include #endif @@ -93,7 +97,7 @@ static string GetTempFilePath(const string& ext) return string(buf); #endif } - +#if 0 class ZipReader : public ArchiveReader { public: @@ -111,6 +115,39 @@ class ZipReader : public ArchiveReader struct zip_file * _file; size_t _total_size; }; +#endif +class ZipReader : public ArchiveReader +{ +public: + ZipReader(struct zip_file* file) : _file(file), _total_size(0), bytes_left(0) + { + struct zip_stat st; + if (zip_source_stat(file->src, &st) == 0) + { + _total_size = st.size; + bytes_left = _total_size; + } + } + ZipReader(ZipReader&& o) : _file(o._file) { o._file = nullptr; } + virtual ~ZipReader() { if (_file != nullptr) zip_fclose(_file); } + + virtual bool operator !() const { return _file == nullptr || bytes_left == 0; } + virtual ssize_t read(void* p, size_t len) const { + size_t curLen = zip_fread(_file, p, std::min(bytes_left, len)); + if (curLen != -1) + ((ZipReader*)this)->bytes_left -= curLen; + return curLen; + } + + virtual size_t total_size() const { return _total_size; } + virtual size_t position() const { return _total_size - bytes_left; } + +private: + struct zip_file * _file; + size_t _total_size; + size_t bytes_left; +}; + class ZipWriter : public ArchiveWriter { @@ -229,6 +266,13 @@ bool ZipArchive::CreateFolder(const string & path) } unique_ptr ZipArchive::ByteStreamAtPath(const string &path) const { + /*zip_uint64_t idx = 0; + if ((idx = zip_name_locate(_zip, path.c_str(), 0)) < 0) + return nullptr; + zip_error_t error; + zip_uint64_t val = _zip_file_get_offset(_zip, idx, &error);*/ + + return make_unique(_zip, path); } @@ -244,7 +288,8 @@ unique_ptr ZipArchive::ReaderAtPath(const string & path) const if (_zip == nullptr) return nullptr; - struct zip_file* file = zip_fopen(_zip, Sanitized(path).c_str(), 0); + const char* spath = Sanitized(path).c_str(); + struct zip_file* file = zip_fopen(_zip, spath, 0); if (file == nullptr) return nullptr; @@ -291,7 +336,9 @@ size_t ZipWriter::DataBlob::Read(void *data, size_t len) ZipWriter::ZipWriter(struct zip *zip, const string& path, bool compressed) : _compressed(compressed) { - _zsrc = zip_source_function(zip, &ZipWriter::_source_callback, reinterpret_cast(this)); + // It seems that ZipWriter is not actually used in the Readium launchers, so it is temporary commented out + assert(0); + //_zsrc = zip_source_function(zip, &ZipWriter::_source_callback, reinterpret_cast(this)); } ZipWriter::ZipWriter(ZipWriter&& o) : _compressed(o._compressed), _data(std::move(o._data)), _zsrc(o._zsrc) { diff --git a/ePub3/utilities/byte_stream.cpp b/ePub3/utilities/byte_stream.cpp index ee238c2de..7b498d1a3 100644 --- a/ePub3/utilities/byte_stream.cpp +++ b/ePub3/utilities/byte_stream.cpp @@ -638,7 +638,6 @@ bool FileByteStream::Open(const string &path, std::ios::openmode mode) return false; } } - // store the mode so we can Clone() later _mode = mode; return true; @@ -742,6 +741,7 @@ std::shared_ptr FileByteStream::Clone() const ZipFileByteStream::ZipFileByteStream(struct zip* archive, const string& path, int flags) : SeekableByteStream(), _file(nullptr), _mode(0) { + bytes_left = total_size = 0; Open(archive, path, flags); } ZipFileByteStream::~ZipFileByteStream() @@ -750,9 +750,13 @@ ZipFileByteStream::~ZipFileByteStream() } ByteStream::size_type ZipFileByteStream::BytesAvailable() _NOEXCEPT { - if ( _file == nullptr ) + //if ( _file == nullptr ) + //return 0; + //return _file->bytes_left; + + if (_file == nullptr) return 0; - return _file->bytes_left; + return bytes_left; } ByteStream::size_type ZipFileByteStream::SpaceAvailable() const _NOEXCEPT { @@ -768,8 +772,29 @@ bool ZipFileByteStream::Open(struct zip *archive, const string &path, int flags) { if ( _file != nullptr ) Close(); + + _path = path; + _openFlags = flags; _file = zip_fopen(archive, Sanitized(path).c_str(), flags); + + if (_file != nullptr) + { + zip_stat_t _st; + zip_flags_t _flags=0; + + _idx = zip_name_locate(archive, Sanitized(path).c_str(), 0); + + if (0==zip_stat_index(_file->za, _idx, _flags, &_st)) // worked + //if (zip_source_stat(_file->src, &_st) == 0) // didn't work + { + total_size = _st.size; + bytes_left = total_size; + } +// _supports = zip_source_supports(_file->src); + _supports = _file->src->supports; + } + return ( _file != nullptr ); } void ZipFileByteStream::Close() @@ -794,7 +819,22 @@ ByteStream::size_type ZipFileByteStream::ReadBytes(void *buf, size_type len) return 0; } - _eof = (_file->bytes_left == 0); + //_eof = (_file->bytes_left == 0); + bytes_left -= numRead; + _eof = (bytes_left == 0); + + + //if ((_idx = zip_name_locate(_file, path.c_str(), 0)) < 0) + // return 0; + //zip_error_t error; zip_uint64_t val = _zip_file_get_offset(_archive, _idx, &error); + ///zip_int64_t tellVal = zip_source_tell(_file->src->src->src); + //zip_int64_t tellVal = zip_source_tell(_file->src->src); + + //zip_int64_t tellVal = zip_source_tell(_file->src); + //int iRet = zip_source_seek(_file->src, tellVal-1, SEEK_SET); + //iRet = zip_source_seek(_file->src, tellVal/2, SEEK_SET); + //iRet = zip_source_seek(_file->src, 0, SEEK_SET); + return numRead; } @@ -803,41 +843,124 @@ ByteStream::size_type ZipFileByteStream::WriteBytes(const void *buf, size_type l // no write support at this moment return 0; } +int ZipFileByteStream::SeekByRewind(long pos, int whence) +{ + long abspos = 0, flen = total_size; + + if (Position() == 0 && whence == SEEK_CUR) + return 0; + + switch (whence) + { + case SEEK_CUR: + abspos = Position() + pos; + break; + case SEEK_SET: + abspos = pos; + break; + case SEEK_END: + abspos = flen + pos; + break; + default: // incorrect/unspecified 'whence' parameter + return -1; + } + + if (abspos == Position()) + return 0; // no change + + if (abspos >= flen) + { + return SeekByReading(bytes_left); // just move to the end of stream + } + else if (abspos > (long)Position()) + { + // read & decompress bytes until we reach the right position + return SeekByReading(abspos - Position()); + } + + //at this point, we're definitely moving backwards + if (abspos < 0) // can't set a negative offset + return -1; + if (!SeekToStart()) + return -1; // error already set */ + // this is a no-op for abspos == 0 * + return SeekByReading(abspos); +} + +bool ZipFileByteStream::SeekToStart() +{ + return Open(_file->za, _path, _openFlags); +} +int ZipFileByteStream::SeekByReading(size_t toread) +{ + char bytes[1024]; + while (toread > 0) + { + ssize_t numRead = ReadBytes(bytes, (toread < 1024 ? toread : 1024)); + if (numRead < 0) + return -1; // error already set + + if (numRead == 0) // avoid infinite loops + return -1; + + toread -= numRead; + } + + /* zf has been updated for us by zip_fread() already */ + return 0; +} + + ByteStream::size_type ZipFileByteStream::Seek(size_type by, std::ios::seekdir dir) { - int whence = ZIP_SEEK_SET; + int whence = SEEK_SET; switch (dir) { case std::ios::beg: break; case std::ios::cur: - whence = ZIP_SEEK_CUR; + whence = SEEK_CUR; break; case std::ios::end: - whence = ZIP_SEEK_END; + whence = SEEK_END; break; default: return Position(); } - zip_fseek(_file, long(by), whence); - _eof = (_file->bytes_left == 0); - return Position(); + if ((_file->src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK)) == 0) // if the source doesn't support seek operation + { + return SeekByRewind(by, whence); // Emulation of Seek operation by rewind + } + + // this is called if the libzip source below supports the ZIP_SOURCE_SEEK operation + if (-1 != zip_source_seek(_file->src, long(by), whence)) + { + bytes_left = total_size - by; + _eof = (bytes_left == 0); + return Position(); + } + return -1; } ByteStream::size_type ZipFileByteStream::Position() const { - return size_type(zip_ftell(_file)); + if ((_file->src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL)) == 0) // if the source doesn't support seek operation + { + return total_size - bytes_left; + } + + return zip_source_tell(_file->src); //return size_type(zip_ftell(_file)); } std::shared_ptr ZipFileByteStream::Clone() const { if (_file == nullptr) return nullptr; - struct zip_file* newFile = zip_fopen_index(_file->za, _file->file_index, _file->flags); + struct zip_file* newFile = zip_fopen_index(_file->za, _idx, _file->za->flags); if (newFile == nullptr) return nullptr; - zip_fseek(newFile, Position(), ZIP_SEEK_SET); + zip_source_seek(newFile->src, 0, SEEK_SET); auto result = std::make_shared(); if (bool(result)) diff --git a/ePub3/utilities/byte_stream.h b/ePub3/utilities/byte_stream.h index 5173d0ebf..ad1f94c8f 100644 --- a/ePub3/utilities/byte_stream.h +++ b/ePub3/utilities/byte_stream.h @@ -559,6 +559,7 @@ class FileByteStream : public SeekableByteStream class ZipFileByteStream : public SeekableByteStream { public: + /// /// Create a new unattached stream. ZipFileByteStream() : SeekableByteStream(), _file(nullptr) {} @@ -632,9 +633,23 @@ class ZipFileByteStream : public SeekableByteStream virtual std::shared_ptr Clone() const OVERRIDE; protected: + struct zip_file* _file; ///< The underlying Zip file stream. std::ios::openmode _mode; ///< The mode used to open the file (used by Clone()). + // Seek by rewind emulation support + size_type bytes_left; + size_type total_size; + uint64_t _idx; // the file index identifier inside zip file structure +private: + // helper functions to emulate seek operation if it is not supported by lower layers of libzip + int SeekByReading(size_t toread); + bool SeekToStart(); + int SeekByRewind(long pos, int whence); + + int64_t _supports; + string _path; + int _openFlags; }; #ifdef SUPPORT_ASYNC diff --git a/ePub3/utilities/integer_sequence.h b/ePub3/utilities/integer_sequence.h index d9de89231..deb4af3d1 100644 --- a/ePub3/utilities/integer_sequence.h +++ b/ePub3/utilities/integer_sequence.h @@ -1,3 +1,4 @@ +#if 1 // // integer_sequence.h // ePub3 @@ -80,3 +81,4 @@ using make_index_sequence = make_integer_sequence; EPUB3_END_NAMESPACE #endif +#endif \ No newline at end of file diff --git a/ePub3/utilities/iri.cpp b/ePub3/utilities/iri.cpp index 3fe3a6a61..8bd31ce3c 100644 --- a/ePub3/utilities/iri.cpp +++ b/ePub3/utilities/iri.cpp @@ -44,7 +44,7 @@ void IRI::AddStandardScheme(const string& scheme) url_util::AddStandardScheme(scheme.c_str()); } -IRI::IRI(const string& iriStr) : _urnComponents(), _url(make_unique(iriStr.stl_str())), _pureIRI(iriStr) +IRI::IRI(const string& iriStr) : _urnComponents(), _url(ePub3::make_unique(iriStr.stl_str())), _pureIRI(iriStr) { // is it a URN? if ( iriStr.find("urn:", 0, 4) == 0 ) @@ -64,7 +64,7 @@ IRI::IRI(const string& nameID, const string& namespacedString) : _urnComponents({gURNScheme, nameID, namespacedString}), #endif _pureIRI(_Str("urn:", nameID, ":", namespacedString)), - _url(make_unique(_pureIRI.stl_str())) + _url(ePub3::make_unique(_pureIRI.stl_str())) { #if !EPUB_COMPILER_SUPPORTS(CXX_INITIALIZER_LISTS) _urnComponents.push_back(gURNScheme); @@ -87,7 +87,7 @@ IRI::IRI(const string& scheme, const string& host, const string& path, const str if ( !fragment.empty() ) _pureIRI += _Str("#", fragment); - _url = make_unique(_pureIRI.stl_str()); + _url = ePub3::make_unique(_pureIRI.stl_str()); } IRI::~IRI() { @@ -127,7 +127,7 @@ IRI& IRI::operator=(const string& str) } } - auto newURL = make_unique(str.stl_str()); + auto newURL = ePub3::make_unique(str.stl_str()); if ( !newURL->is_valid() && !isURN ) throw std::invalid_argument(_Str("IRI: '", str, "' is not a valid URL string.")); diff --git a/ePub3/utilities/optional.h b/ePub3/utilities/optional.h index c617730a9..f4e9555b6 100644 --- a/ePub3/utilities/optional.h +++ b/ePub3/utilities/optional.h @@ -208,7 +208,7 @@ void fail(const char* expr, const char* file, unsigned line) # elif defined(__GNUC__) || EPUB_PLATFORM(ANDROID) __assert(file, line, expr); # else -# warning I dont know how to fire assertion internals on this compiler. +//# warning I dont know how to fire assertion internals on this compiler. # endif } #endif diff --git a/ePub3/utilities/ref_counted.cpp b/ePub3/utilities/ref_counted.cpp index 209cfc3f2..116b8f0ca 100644 --- a/ePub3/utilities/ref_counted.cpp +++ b/ePub3/utilities/ref_counted.cpp @@ -19,6 +19,6 @@ // Affero General Public License along with this program. If not, see . #if BUILDING_EPUB3 || !EPUB_COMPILER_SUPPORTS(CXX_CONSTEXPR) -#include -const adopt_ref_t adopt_ref = {}; +//#include +//const adopt_ref_t adopt_ref = {}; #endif diff --git a/ePub3/utilities/run_loop_windows.cpp b/ePub3/utilities/run_loop_windows.cpp index a3311d8d7..df8f17f68 100644 --- a/ePub3/utilities/run_loop_windows.cpp +++ b/ePub3/utilities/run_loop_windows.cpp @@ -572,7 +572,7 @@ RunLoop::Timer::Timer(Clock::time_point& fireDate, Clock::duration& interval, Ti } #else - _handle = CreateWaitableTimer(NULL, FALSE); + _handle = CreateWaitableTimer(NULL, FALSE, nullptr); if ( _handle == NULL ) _THROW_LAST_ERROR();