Index: Zip/include/Poco/Zip/Compress.h =================================================================== --- Zip/include/Poco/Zip/Compress.h (revision 0) +++ Zip/include/Poco/Zip/Compress.h (revision 0) @@ -0,0 +1,114 @@ +// +// Compress.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: Compress +// +// Definition of the Compress class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_Compress_INCLUDED +#define Zip_Compress_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/ZipArchive.h" +#include "Poco/FIFOEvent.h" +#include +#include + + +namespace Poco { +namespace Zip { + + +class Zip_API Compress + /// Compresses a directory or files as zip. +{ +public: + Poco::FIFOEvent EDone; + + Compress(std::ostream& out, bool seekableOut); + /// seekableOut determines how we write the zip, setting it to true is recommended for local files (smaller zip file), + /// if you are compressing directly to a network, you MUST set it to false + + ~Compress(); + + void addFile(std::istream& input, const Poco::DateTime& lastModifiedAt, const Poco::Path& fileName, ZipCommon::CompressionMethod cm = ZipCommon::CM_DEFLATE, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM); + /// Adds a single file to the Zip File. fileName must not be a directory name. + + void addFile(const Poco::Path& file, const Poco::Path& fileName, ZipCommon::CompressionMethod cm = ZipCommon::CM_DEFLATE, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM); + /// Adds a single file to the Zip File. fileName must not be a directory name. The file must exist physically! + + void addDirectory(const Poco::Path& entryName, const Poco::DateTime& lastModifiedAt); + /// Adds a directory entry excluding all children to the Zip file, entryName must not be empty. + + void addRecursive(const Poco::Path& entry, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM, bool excludeRoot = true, const Poco::Path& name = Poco::Path()); + /// Adds a directory entry recursively to the zip file, set excludeRoot to false to exclude the parent directory. + /// If excludeRoot is true you can specify an empty name to add the files as relative files + + ZipArchive close(); + /// Finalizes the ZipArchive, closes it. + +private: + enum + { + COMPRESS_CHUNK_SIZE = 8192 + }; + + Compress(const Compress&); + Compress& operator=(const Compress&); + + void addEntry(std::istream& input, const Poco::DateTime& lastModifiedAt, const Poco::Path& fileName, ZipCommon::CompressionMethod cm = ZipCommon::CM_DEFLATE, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM); + /// Either adds a file or a single directory entry (excluding subchildren) to the Zip file. the compression level will be ignored + /// for directories. + + void addFileRaw(std::istream& in, const ZipLocalFileHeader& hdr, const Poco::Path& fileName); + /// copys an already compressed ZipEntry from in + +private: + std::ostream& _out; + bool _seekableOut; + ZipArchive::FileHeaders _files; + ZipArchive::FileInfos _infos; + ZipArchive::DirectoryInfos _dirs; + Poco::UInt32 _offset; + + friend class Keep; + friend class Rename; +}; + + +} } // namespace Poco::Zip + + +#endif // Zip_Compress_INCLUDED Property changes on: Zip/include/Poco/Zip/Compress.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/ZipUtil.h =================================================================== --- Zip/include/Poco/Zip/ZipUtil.h (revision 0) +++ Zip/include/Poco/Zip/ZipUtil.h (revision 0) @@ -0,0 +1,120 @@ +// +// ZipUtil.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipUtil +// +// Definition of the ZipUtil class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_ZipUtil_INCLUDED +#define Zip_ZipUtil_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/ZipCommon.h" +#include "Poco/DateTime.h" +#include "Poco/Path.h" +#include + + +namespace Poco { +namespace Zip { + + +class ZipUtil + /// A utility class used for parsing header information inside of zip files +{ +public: + static Poco::UInt16 get16BitValue(const char* pVal, const Poco::UInt32 pos); + + static Poco::UInt32 get32BitValue(const char* pVal, const Poco::UInt32 pos); + + static void set16BitValue(const Poco::UInt16 val, char* pVal, const Poco::UInt32 pos); + + static void set32BitValue(const Poco::UInt32 val, char* pVal, const Poco::UInt32 pos); + + static Poco::DateTime parseDateTime(const char* pVal, const Poco::UInt32 timePos, const Poco::UInt32 datePos); + + static void setDateTime(const Poco::DateTime& dt, char* pVal, const Poco::UInt32 timePos, const Poco::UInt32 datePos); + + static std::string fakeZLibInitString(ZipCommon::CompressionLevel cl); + + static void sync(std::istream& in); + /// Searches the next valid header in the input stream, stops right before it + + static void verifyZipEntryFileName(const std::string& zipPath); + /// Verifies that the name of the ZipEntry is a valid path + + static std::string validZipEntryFileName(const Poco::Path& entry); + +private: + ZipUtil(); + ~ZipUtil(); + ZipUtil(const ZipUtil&); + ZipUtil& operator=(const ZipUtil&); +}; + + +inline Poco::UInt16 ZipUtil::get16BitValue(const char* pVal, const Poco::UInt32 pos) +{ + return static_cast((unsigned char)pVal[pos])+ (static_cast((unsigned char)pVal[pos+1]) << 8); +} + + +inline Poco::UInt32 ZipUtil::get32BitValue(const char* pVal, const Poco::UInt32 pos) +{ + return static_cast((unsigned char)pVal[pos])+ (static_cast((unsigned char)pVal[pos+1]) << 8)+ + (static_cast((unsigned char)pVal[pos+2]) << 16) + (static_cast((unsigned char)pVal[pos+3]) << 24); +} + + +inline void ZipUtil::set16BitValue(const Poco::UInt16 val, char* pVal, const Poco::UInt32 pos) +{ + pVal[pos] = static_cast(val); + pVal[pos+1] = static_cast(val>>8); +} + + +inline void ZipUtil::set32BitValue(const Poco::UInt32 val, char* pVal, const Poco::UInt32 pos) +{ + pVal[pos] = static_cast(val); + pVal[pos+1] = static_cast(val>>8); + pVal[pos+2] = static_cast(val>>16); + pVal[pos+3] = static_cast(val>>24); +} + + +} } // namespace Poco::Zip + + +#endif // Zip_ZipUtil_INCLUDED Property changes on: Zip/include/Poco/Zip/ZipUtil.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/Delete.h =================================================================== --- Zip/include/Poco/Zip/Delete.h (revision 0) +++ Zip/include/Poco/Zip/Delete.h (revision 0) @@ -0,0 +1,70 @@ +// +// Delete.h +// +// $Id$ +// +// Library: Zip +// Package: Manipulation +// Module: Delete +// +// Definition of the Delete class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_Delete_INCLUDED +#define Zip_Delete_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/ZipOperation.h" +#include "Poco/Zip/ZipLocalFileHeader.h" + + +namespace Poco { +namespace Zip { + + +class Zip_API Delete: public ZipOperation + /// Delete Operation removes an entry from a Zip +{ +public: + Delete(const ZipLocalFileHeader& hdr); + /// Creates the Delete. + + void execute(Compress& c, std::istream& input); + /// Throws away the ZipEntry + +private: + const ZipLocalFileHeader _hdr; +}; + + +} } // namespace Poco::Zip + + +#endif // Zip_Delete_INCLUDED Property changes on: Zip/include/Poco/Zip/Delete.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/Zip.h =================================================================== --- Zip/include/Poco/Zip/Zip.h (revision 0) +++ Zip/include/Poco/Zip/Zip.h (revision 0) @@ -0,0 +1,92 @@ +// +// Zip.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: Zip +// +// Basic definitions for the Poco Zip library. +// This file must be the first file included by every other Zip +// header file. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_Zip_INCLUDED +#define Zip_Zip_INCLUDED + + +#include "Poco/Foundation.h" + + +// +// The following block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the Zip_EXPORTS +// symbol defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// Zip_API functions as being imported from a DLL, wheras this DLL sees symbols +// defined with this macro as being exported. +// +#if defined(_WIN32) && defined(POCO_DLL) + #if defined(Zip_EXPORTS) + #define Zip_API __declspec(dllexport) + #else + #define Zip_API __declspec(dllimport) + #endif +#endif + + +#if !defined(Zip_API) + #define Zip_API +#endif + + +// +// Automatically link Zip library. +// +#if defined(_MSC_VER) + #if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(Zip_EXPORTS) + #if defined(POCO_DLL) + #if defined(_DEBUG) + #pragma comment(lib, "PocoZipd.lib") + #else + #pragma comment(lib, "PocoZip.lib") + #endif + #else + #if defined(_DEBUG) + #pragma comment(lib, "PocoZipmtd.lib") + #else + #pragma comment(lib, "PocoZipmt.lib") + #endif + #endif + #endif +#endif + + +#endif // Zip_Zip_INCLUDED Property changes on: Zip/include/Poco/Zip/Zip.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/Decompress.h =================================================================== --- Zip/include/Poco/Zip/Decompress.h (revision 0) +++ Zip/include/Poco/Zip/Decompress.h (revision 0) @@ -0,0 +1,112 @@ +// +// Decompress.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: Decompress +// +// Definition of the Decompress class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_Decompress_INCLUDED +#define Zip_Decompress_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/ParseCallback.h" +#include "Poco/Zip/ZipArchive.h" +#include "Poco/Path.h" +#include "Poco/FIFOEvent.h" + + +namespace Poco { +namespace Zip { + + +class ZipArchive; + + +class Zip_API Decompress: public ParseCallback + /// Decompress extracts files from zip files, can be used to extract single files or all files +{ +public: + typedef std::map ZipMapping; + /// Maps key of FileInfo entries to their local decompressed representation + Poco::FIFOEvent > EError; + /// Thrown whenever an error is detected when handling a ZipLocalFileHeader entry. The string contains an error message + Poco::FIFOEvent > EOk; + /// Thrown whenever a file was successfully decompressed + + Decompress(std::istream& in, const Poco::Path& outputDir, bool flattenDirs = false, bool keepIncompleteFiles = false); + /// Creates the Decompress. Note that istream must be good and at the very beginning of the file! + /// Calling decompressAllFiles will cause the stream to be in state failed once the zip file is processed. + /// outputDir must be a directory. If it doesn't exist yet, it will be automatically created. + /// If flattenDirs is set to true, the directory structure of the zip file is not recreated. + /// Instead, all files are extracted into one single directory. + + ~Decompress(); + /// Destroys the Decompress. + + ZipArchive decompressAllFiles(); + /// Decompresses all files stored in the zip File. Can only be called once per Decompress object. + /// Use mapping to retrieve the location of the decompressed files + + bool handleZipEntry(std::istream& zipStream, const ZipLocalFileHeader& hdr); + + const ZipMapping& mapping() const; + /// A ZipMapping stores as key the full name of the ZipFileInfo/ZipLocalFileHeader and as value the decompressed file + /// If for a ZipFileInfo no mapping exists, there was an error during decompression and the entry is considered to be corrupt + +private: + Decompress(const Decompress&); + Decompress& operator=(const Decompress&); + + void onOk(const void*, std::pair& val); + +private: + std::istream& _in; + Poco::Path _outDir; + bool _flattenDirs; + bool _keepIncompleteFiles; + ZipMapping _mapping; +}; + + +inline const Decompress::ZipMapping& Decompress::mapping() const +{ + return _mapping; +} + + +} } // namespace Poco::Zip + + +#endif // Zip_Decompress_INCLUDED Property changes on: Zip/include/Poco/Zip/Decompress.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/ZipArchive.h =================================================================== --- Zip/include/Poco/Zip/ZipArchive.h (revision 0) +++ Zip/include/Poco/Zip/ZipArchive.h (revision 0) @@ -0,0 +1,136 @@ +// +// ZipArchive.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipArchive +// +// Definition of the ZipArchive class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_ZipArchive_INCLUDED +#define Zip_ZipArchive_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/ZipLocalFileHeader.h" +#include "Poco/Zip/ZipFileInfo.h" +#include "Poco/Zip/ZipArchiveInfo.h" +#include +#include + + +namespace Poco { +namespace Zip { + + +class ParseCallback; +class Compress; + + +class Zip_API ZipArchive + /// A ZipArchive contains information on the content of a zip file +{ +public: + typedef std::map FileHeaders; + typedef std::map FileInfos; + typedef std::map DirectoryInfos; + + ZipArchive(std::istream& in); + /// Creates the ZipArchive from a file. Note that the in stream will be in state failed after the constructor is finished + + ZipArchive(std::istream& in, ParseCallback& callback); + /// Creates the ZipArchive from a file or network stream. Note that the in stream will be in state failed after the constructor is finished + + ~ZipArchive(); + /// Destroys the ZipArchive. + + FileInfos::const_iterator fileInfoBegin() const; + + FileInfos::const_iterator fileInfoEnd() const; + + FileHeaders::const_iterator findHeader(const std::string& fileName) const; + + FileHeaders::const_iterator headerBegin() const; + + FileHeaders::const_iterator headerEnd() const; + +private: + void parse(std::istream& in, ParseCallback& pc); + + ZipArchive(const FileHeaders& entries, const FileInfos& infos, const DirectoryInfos& dirs ); + +private: + FileHeaders _entries; + /// Info generated by parsing the data block of the zip file + FileInfos _infos; + /// Info generated by parsing the directory block of the zip file + DirectoryInfos _disks; + /// Stores directory info for all found disks + + friend class Compress; +}; + + +inline ZipArchive::FileInfos::const_iterator ZipArchive::fileInfoBegin() const +{ + return _infos.begin(); +} + + +inline ZipArchive::FileInfos::const_iterator ZipArchive::fileInfoEnd() const +{ + return _infos.end(); +} + + +inline ZipArchive::FileHeaders::const_iterator ZipArchive::findHeader(const std::string& fileName) const +{ + return _entries.find(fileName); +} + + +inline ZipArchive::FileHeaders::const_iterator ZipArchive::headerBegin() const +{ + return _entries.begin(); +} + + +inline ZipArchive::FileHeaders::const_iterator ZipArchive::headerEnd() const +{ + return _entries.end(); +} + + +} } // namespace Poco::Zip + + +#endif // Zip_ZipArchive_INCLUDED Property changes on: Zip/include/Poco/Zip/ZipArchive.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/Rename.h =================================================================== --- Zip/include/Poco/Zip/Rename.h (revision 0) +++ Zip/include/Poco/Zip/Rename.h (revision 0) @@ -0,0 +1,71 @@ +// +// Rename.h +// +// $Id$ +// +// Library: Zip +// Package: Manipulation +// Module: Rename +// +// Definition of the Rename class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_Rename_INCLUDED +#define Zip_Rename_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/ZipOperation.h" +#include "Poco/Zip/ZipLocalFileHeader.h" + + +namespace Poco { +namespace Zip { + + +class Zip_API Rename: public ZipOperation + /// Renames an existing Zip Entry +{ +public: + Rename(const ZipLocalFileHeader& hdr, const std::string& newZipEntryName); + /// Creates the Rename. + + void execute(Compress& c, std::istream& input); + /// Performs the rename operation + +private: + const ZipLocalFileHeader _hdr; + const std::string _newZipEntryName; +}; + + +} } // namespace Poco::Zip + + +#endif // Zip_Rename_INCLUDED Property changes on: Zip/include/Poco/Zip/Rename.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/ZipDataInfo.h =================================================================== --- Zip/include/Poco/Zip/ZipDataInfo.h (revision 0) +++ Zip/include/Poco/Zip/ZipDataInfo.h (revision 0) @@ -0,0 +1,160 @@ +// +// ZipDataInfo.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipDataInfo +// +// Definition of the ZipDataInfo class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_ZipDataInfo_INCLUDED +#define Zip_ZipDataInfo_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/ZipCommon.h" +#include "Poco/Zip/ZipUtil.h" + + +namespace Poco { +namespace Zip { + + +class Zip_API ZipDataInfo + /// A ZipDataInfo stores a Zip data descriptor +{ +public: + static const char HEADER[ZipCommon::HEADER_SIZE]; + + ZipDataInfo(); + /// Creates a header with all fields (except the header field) set to 0 + + ZipDataInfo(std::istream& in, bool assumeHeaderRead); + /// Creates the ZipDataInfo. + + ~ZipDataInfo(); + /// Destroys the ZipDataInfo. + + bool isValid() const; + + Poco::UInt32 getCRC32() const; + + void setCRC32(Poco::UInt32 crc); + + Poco::UInt32 getCompressedSize() const; + + void setCompressedSize(Poco::UInt32 size); + + Poco::UInt32 getUncompressedSize() const; + + void setUncompressedSize(Poco::UInt32 size); + + static Poco::UInt32 getFullHeaderSize(); + + const char* getRawHeader() const; + +private: + enum + { + HEADER_POS = 0, + CRC32_POS = HEADER_POS + ZipCommon::HEADER_SIZE, + CRC32_SIZE = 4, + COMPRESSED_POS = CRC32_POS + CRC32_SIZE, + COMPRESSED_SIZE = 4, + UNCOMPRESSED_POS = COMPRESSED_POS + COMPRESSED_SIZE, + UNCOMPRESSED_SIZE = 4, + FULLHEADER_SIZE = UNCOMPRESSED_POS + UNCOMPRESSED_SIZE + }; + + char _rawInfo[FULLHEADER_SIZE]; + bool _valid; +}; + + +inline const char* ZipDataInfo::getRawHeader() const +{ + return _rawInfo; +} + + +inline bool ZipDataInfo::isValid() const +{ + return _valid; +} + + +inline Poco::UInt32 ZipDataInfo::getCRC32() const +{ + return ZipUtil::get32BitValue(_rawInfo, CRC32_POS); +} + + +inline void ZipDataInfo::setCRC32(Poco::UInt32 crc) +{ + return ZipUtil::set32BitValue(crc, _rawInfo, CRC32_POS); +} + + +inline Poco::UInt32 ZipDataInfo::getCompressedSize() const +{ + return ZipUtil::get32BitValue(_rawInfo, COMPRESSED_POS); +} + + +inline void ZipDataInfo::setCompressedSize(Poco::UInt32 size) +{ + return ZipUtil::set32BitValue(size, _rawInfo, COMPRESSED_POS); +} + + +inline Poco::UInt32 ZipDataInfo::getUncompressedSize() const +{ + return ZipUtil::get32BitValue(_rawInfo, UNCOMPRESSED_POS); +} + + +inline void ZipDataInfo::setUncompressedSize(Poco::UInt32 size) +{ + return ZipUtil::set32BitValue(size, _rawInfo, UNCOMPRESSED_POS); +} + + +inline Poco::UInt32 ZipDataInfo::getFullHeaderSize() +{ + return FULLHEADER_SIZE; +} + + +} } // namespace Poco::Zip + + +#endif // Zip_ZipDataInfo_INCLUDED Property changes on: Zip/include/Poco/Zip/ZipDataInfo.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/PartialStream.h =================================================================== --- Zip/include/Poco/Zip/PartialStream.h (revision 0) +++ Zip/include/Poco/Zip/PartialStream.h (revision 0) @@ -0,0 +1,209 @@ +// +// PartialStream.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: PartialStream +// +// Definition of the PartialStream class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_PartialStream_INCLUDED +#define Zip_PartialStream_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/BufferedStreamBuf.h" +#include "Poco/Buffer.h" +#include +#include + + +namespace Poco { +namespace Zip { + + +class Zip_API PartialStreamBuf: public Poco::BufferedStreamBuf + /// A PartialStreamBuf is a class that limits one view on an inputstream to a selected view range +{ +public: + PartialStreamBuf(std::istream& in, std::ios::pos_type start, std::ios::pos_type end, const std::string& prefix, const std::string& postfix, bool initStream); + /// Creates the PartialStream. + /// If initStream is true the status of the stream will be cleared on the first access, and the stream will be repositioned + /// to position start + + PartialStreamBuf(std::ostream& out, std::size_t start, std::size_t end, bool initStream); + /// Creates the PartialStream. + /// If initStream is true the status of the stream will be cleared on the first access. + /// start and end acts as offset values for the written content. A start value greater than zero, + /// means that the first bytes are not written but discarded instead, + /// an end value not equal to zero means that the last end bytes are not written! + /// Examples: + /// start = 3; end = 1 + /// write("hello", 5) -> "l" + + ~PartialStreamBuf(); + /// Destroys the PartialStream. + + void close(); + /// Flushes a writing streambuf + + Poco::UInt64 bytesWritten() const; + +protected: + int readFromDevice(char* buffer, std::streamsize length); + + int writeToDevice(const char* buffer, std::streamsize length); + +private: + enum + { + STREAM_BUFFER_SIZE = 1024 + }; + + bool _initialized; + std::ios::pos_type _start; + Poco::UInt64 _numBytes; + Poco::UInt64 _bytesWritten; + std::istream* _pIstr; + std::ostream* _pOstr; + std::string _prefix; + std::string _postfix; + std::size_t _ignoreStart; + Poco::Buffer _buffer; + Poco::UInt32 _bufferOffset; +}; + + +inline Poco::UInt64 PartialStreamBuf::bytesWritten() const +{ + return _bytesWritten; +} + + +class Zip_API PartialIOS: public virtual std::ios + /// The base class for PartialInputStream and PartialOutputStream. + /// + /// This class is needed to ensure the correct initialization + /// order of the stream buffer and base classes. +{ +public: + PartialIOS(std::istream& istr, std::ios::pos_type start, std::ios::pos_type end, const std::string& prefix, const std::string& postfix, bool initStream); + /// Creates the basic stream and connects it + /// to the given input stream. + /// If initStream is true the status of the stream will be cleared on the first access, and the stream will be repositioned + /// to position start + + PartialIOS(std::ostream& ostr, std::size_t start, std::size_t end, bool initStream); + /// Creates the basic stream and connects it + /// to the given output stream. + /// If initStream is true the status of the stream will be cleared on the first access. + /// start and end acts as offset values for the written content. A start value greater than zero, + /// means that the first bytes are not written but discarded instead, + /// an end value not equal to zero means that the last end bytes are not written! + /// Examples: + /// start = 3; end = 1 + /// write("hello", 5) -> "l" + + ~PartialIOS(); + /// Destroys the stream. + + PartialStreamBuf* rdbuf(); + /// Returns a pointer to the underlying streambuf. + +protected: + PartialStreamBuf _buf; +}; + + +class Zip_API PartialInputStream: public PartialIOS, public std::istream + /// This stream copies all characters read through it + /// to one or multiple output streams. +{ +public: + PartialInputStream(std::istream& istr, std::ios::pos_type start, std::ios::pos_type end, bool initStream = true, const std::string& prefix = std::string(), const std::string& postfix = std::string()); + /// Creates the PartialInputStream and connects it + /// to the given input stream. Bytes read are guaranteed to be in the range [start, end-1] + /// If initStream is true the status of the stream will be cleared on the first access, and the stream will be repositioned + /// to position start + + ~PartialInputStream(); + /// Destroys the PartialInputStream. +}; + + +class Zip_API PartialOutputStream: public PartialIOS, public std::ostream + /// This stream copies all characters written to it + /// to one or multiple output streams. +{ +public: + PartialOutputStream(std::ostream& ostr, std::size_t start, std::size_t end, bool initStream = true); + /// Creates the PartialOutputStream and connects it + /// to the given output stream. Bytes written are guaranteed to be in the range [start, realEnd - end]. + /// If initStream is true the status of the stream will be cleared on the first access. + /// start and end acts as offset values for the written content. A start value greater than zero, + /// means that the first bytes are not written but discarded instead, + /// an end value not equal to zero means that the last end bytes are not written! + /// Examples: + /// start = 3; end = 1 + /// write("hello", 5) -> "l" + /// + /// start = 3; end = 0 + /// write("hello", 5) -> "lo" + + ~PartialOutputStream(); + /// Destroys the PartialOutputStream. + + void close(); + /// must be called for the stream to properly terminate it + + Poco::UInt64 bytesWritten() const; + /// Returns the number of bytes actually forwarded to the inner ostream +}; + + +inline void PartialOutputStream::close() +{ + flush(); + _buf.close(); +} + + +inline Poco::UInt64 PartialOutputStream::bytesWritten() const +{ + return _buf.bytesWritten(); +} + + +} } // namespace Poco::Zip + + +#endif // Zip_PartialStream_INCLUDED Property changes on: Zip/include/Poco/Zip/PartialStream.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/Replace.h =================================================================== --- Zip/include/Poco/Zip/Replace.h (revision 0) +++ Zip/include/Poco/Zip/Replace.h (revision 0) @@ -0,0 +1,72 @@ +// +// Replace.h +// +// $Id$ +// +// Library: Zip +// Package: Manipulation +// Module: Replace +// +// Definition of the Replace class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_Replace_INCLUDED +#define Zip_Replace_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/Add.h" +#include "Poco/Zip/Delete.h" +#include "Poco/Zip/ZipOperation.h" + + +namespace Poco { +namespace Zip { + + +class Zip_API Replace: public ZipOperation + /// Operation Replace replaces the content of an existing entry with a new one +{ +public: + Replace(const ZipLocalFileHeader& hdr, const std::string& localPath); + /// Creates the Replace. + + void execute(Compress& c, std::istream& input); + /// Performs the replace operation + +private: + Delete _del; + Add _add; +}; + + +} } // namespace Poco::Zip + + +#endif // Zip_Replace_INCLUDED Property changes on: Zip/include/Poco/Zip/Replace.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/ZipCommon.h =================================================================== --- Zip/include/Poco/Zip/ZipCommon.h (revision 0) +++ Zip/include/Poco/Zip/ZipCommon.h (revision 0) @@ -0,0 +1,119 @@ +// +// ZipCommon.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipCommon +// +// Definition of the ZipCommon class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_ZipCommon_INCLUDED +#define Zip_ZipCommon_INCLUDED + + +#include "Poco/Zip/Zip.h" + + +namespace Poco { +namespace Zip { + + +class Zip_API ZipCommon + /// Common enums used in the Zip project +{ +public: + enum + { + HEADER_SIZE = 4 + }; + + enum CompressionMethod + { + CM_STORE = 0, + CM_SHRUNK = 1, + CM_FACTOR1 = 2, + CM_FACTOR2 = 3, + CM_FACTOR3 = 4, + CM_FACTOR4 = 5, + CM_IMPLODE = 6, + CM_TOKENIZE= 7, + CM_DEFLATE = 8, + CM_ENHANCEDDEFLATE = 9, + CM_DATECOMPRIMPLODING = 10, + CM_UNUSED = 11 + }; + + enum CompressionLevel + { + CL_NORMAL = 0, + CL_MAXIMUM = 1, + CL_FAST = 2, + CL_SUPERFAST = 3 + }; + + enum HostSystem + { + HS_FAT = 0, // + PKZIPW 2.50 VFAT, NTFS + HS_AMIGA = 1, + HS_VMS = 2, + HS_UNIX = 3, + HS_VM_CMS = 4, + HS_ATARI = 5, + HS_HPFS = 6, + HS_MACINTOSH = 7, + HS_ZSYSTEM = 8, + HS_CP_M = 9, + HS_TOPS20 = 10, // used by pkzip2.5 to indicate ntfs + HS_NTFS = 11, + HS_SMS_QDOS = 12, + HS_ACORN = 13, + HS_VFAT = 14, + HS_MVS = 15, + HS_BEOS = 16, + HS_TANDEM = 17, + HS_UNUSED = 18 + }; + + enum FileType + { + FT_BINARY= 0, + FT_ASCII = 1 + }; + + static const std::string ILLEGAL_PATH; +}; + + +} } // namespace Poco::Zip + + +#endif // Zip_ZipCommon_INCLUDED Property changes on: Zip/include/Poco/Zip/ZipCommon.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/AutoDetectStream.h =================================================================== --- Zip/include/Poco/Zip/AutoDetectStream.h (revision 0) +++ Zip/include/Poco/Zip/AutoDetectStream.h (revision 0) @@ -0,0 +1,152 @@ +// +// AutoDetectStream.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: AutoDetectStream +// +// Definition of the AutoDetectStream class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_AutoDetectStream_INCLUDED +#define Zip_AutoDetectStream_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/BufferedStreamBuf.h" +#include +#include + + +namespace Poco { +namespace Zip { + + +class Zip_API AutoDetectStreamBuf: public Poco::BufferedStreamBuf + /// A AutoDetectStreamBuf is a class that limits one view on an inputstream to a selected view range +{ +public: + AutoDetectStreamBuf(std::istream& in, const std::string& prefix, const std::string& postfix, bool reposition, Poco::UInt32 start); + /// Creates the AutoDetectStream. + + + AutoDetectStreamBuf(std::ostream& out); + /// Creates the AutoDetectStream. + /// If initStream is true the status of the stream will be cleared on the first access, and the stream will be repositioned + /// to position start + + ~AutoDetectStreamBuf(); + /// Destroys the AutoDetectStream. + +protected: + int readFromDevice(char* buffer, std::streamsize length); + + int writeToDevice(const char* buffer, std::streamsize length); + +private: + enum + { + STREAM_BUFFER_SIZE = 1024 + }; + + std::istream* _pIstr; + std::ostream* _pOstr; + bool _eofDetected; + int _matchCnt; + std::string _prefix; + std::string _postfix; + bool _reposition; + Poco::UInt32 _start; +}; + + +class Zip_API AutoDetectIOS: public virtual std::ios + /// The base class for AutoDetectInputStream and AutoDetectOutputStream. + /// + /// This class is needed to ensure the correct initialization + /// order of the stream buffer and base classes. +{ +public: + AutoDetectIOS(std::istream& istr, const std::string& prefix, const std::string& postfix, bool reposition, Poco::UInt32 start); + /// Creates the basic stream and connects it + /// to the given input stream. + + AutoDetectIOS(std::ostream& ostr); + /// Creates the basic stream and connects it + /// to the given output stream. + + ~AutoDetectIOS(); + /// Destroys the stream. + + AutoDetectStreamBuf* rdbuf(); + /// Returns a pointer to the underlying streambuf. + +protected: + AutoDetectStreamBuf _buf; +}; + + +class Zip_API AutoDetectInputStream: public AutoDetectIOS, public std::istream + /// This stream copies all characters read through it + /// to one or multiple output streams. +{ +public: + AutoDetectInputStream(std::istream& istr, const std::string& prefix = std::string(), const std::string& postfix = std::string(), bool reposition = false, Poco::UInt32 start = 0); + /// Creates the AutoDetectInputStream and connects it + /// to the given input stream. Bytes read are guaranteed to be in the range [start, end-1] + /// If initStream is true the status of the stream will be cleared on the first access, and the stream will be repositioned + /// to position start + + ~AutoDetectInputStream(); + /// Destroys the AutoDetectInputStream. +}; + + +class Zip_API AutoDetectOutputStream: public AutoDetectIOS, public std::ostream + /// This stream copies all characters written to it + /// to one or multiple output streams. +{ +public: + AutoDetectOutputStream(std::ostream& ostr); + /// Creates the AutoDetectOutputStream and connects it + /// to the given input stream. Bytes written are guaranteed to be in the range [start, end-1] + /// If initStream is true the status of the stream will be cleared on the first access, and the stream will be repositioned + /// to position start + + ~AutoDetectOutputStream(); + /// Destroys the AutoDetectOutputStream. +}; + + +} } // namespace Poco::Zip + + +#endif // Zip_AutoDetectStream_INCLUDED Property changes on: Zip/include/Poco/Zip/AutoDetectStream.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/ZipStream.h =================================================================== --- Zip/include/Poco/Zip/ZipStream.h (revision 0) +++ Zip/include/Poco/Zip/ZipStream.h (revision 0) @@ -0,0 +1,171 @@ +// +// ZipStream.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipStream +// +// Definition of the ZipStream class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_ZipStream_INCLUDED +#define Zip_ZipStream_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/PartialStream.h" +#include "Poco/SharedPtr.h" +#include "Poco/BufferedStreamBuf.h" +#include "Poco/Checksum.h" +#include +#include + + +namespace Poco { +namespace Zip { + + +class ZipArchive; +class ZipLocalFileHeader; + + +class Zip_API ZipStreamBuf: public Poco::BufferedStreamBuf + /// ZipStreamBuf is used to decompress single files from a Zip file. +{ +public: + ZipStreamBuf(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition); + /// Creates the ZipStreamBuf. Set reposition to false, if you do on-the-fly decompression. + + ZipStreamBuf(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool reposition); + /// Creates the ZipStreamBuf. Set reposition to false, if you do on-the-fly compression. + + virtual ~ZipStreamBuf(); + /// Destroys the ZipStreamBuf. + + void close(); + /// Informs a writing outputstream that writing is done for this stream + + bool crcValid() const; + /// Call this method once all bytes were read from the input stream to determine if the CRC is valid + +protected: + int readFromDevice(char* buffer, std::streamsize length); + + int writeToDevice(const char* buffer, std::streamsize length); + +private: + enum + { + STREAM_BUFFER_SIZE = 1024 + }; + + typedef Poco::SharedPtr PtrIStream; + typedef Poco::SharedPtr PtrOStream; + std::istream* _pIstr; + std::ostream* _pOstr; + PtrIStream _ptrBuf; + PtrOStream _ptrOBuf; + PtrIStream _ptrHelper; + Poco::SharedPtr _ptrOHelper; + Poco::Checksum _crc32; + Poco::UInt32 _expectedCrc32; + bool _checkCRC; + /// Note: we do not check crc if we decompress a streaming zip file and the crc is stored in the directory header + Poco::UInt32 _bytesWritten; + ZipLocalFileHeader* _pHeader; +}; + + +class Zip_API ZipIOS: public virtual std::ios + /// The base class for ZipInputStream and ZipOutputStream. + /// + /// This class is needed to ensure the correct initialization + /// order of the stream buffer and base classes. +{ +public: + ZipIOS(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition); + /// Creates the basic stream and connects it + /// to the given input stream. + + ZipIOS(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool reposition); + /// Creates the basic stream and connects it + /// to the given output stream. + + ~ZipIOS(); + /// Destroys the stream. + + ZipStreamBuf* rdbuf(); + /// Returns a pointer to the underlying streambuf. + +protected: + ZipStreamBuf _buf; +}; + + +class Zip_API ZipInputStream: public ZipIOS, public std::istream + /// This stream copies all characters read through it + /// to one or multiple output streams. +{ +public: + ZipInputStream(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition = true); + /// Creates the ZipInputStream and connects it + /// to the given input stream. + + ~ZipInputStream(); + /// Destroys the ZipInputStream. + + bool crcValid() const; + /// Call this method once all bytes were read from the input stream to determine if the CRC is valid +}; + + + +class Zip_API ZipOutputStream: public ZipIOS, public std::ostream + /// This stream compresses all characters written through it + /// to one output stream. +{ +public: + ZipOutputStream(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool seekableOutput); + /// Creates the ZipOutputStream and connects it + /// to the given output stream. + + ~ZipOutputStream(); + /// Destroys the ZipOutputStream. + + void close(); + /// Must be called for ZipOutputStreams! +}; + + +} } // namespace Poco::Zip + + +#endif // Zip_ZipStream_INCLUDED Property changes on: Zip/include/Poco/Zip/ZipStream.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/ZipManipulator.h =================================================================== --- Zip/include/Poco/Zip/ZipManipulator.h (revision 0) +++ Zip/include/Poco/Zip/ZipManipulator.h (revision 0) @@ -0,0 +1,131 @@ +// +// ZipManipulator.h +// +// $Id$ +// +// Library: Zip +// Package: Manipulation +// Module: ZipManipulator +// +// Definition of the ZipManipulator class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_ZipManipulator_INCLUDED +#define Zip_ZipManipulator_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/ZipArchive.h" +#include "Poco/Zip/ZipCommon.h" +#include "Poco/Zip/ZipOperation.h" +#include "Poco/FIFOEvent.h" +#include "Poco/SharedPtr.h" +#include + + +namespace Poco { +namespace Zip { + + +class ZipArchive; + + +class Zip_API ZipManipulator + /// ZipManipulator allows to add/remove/update files inside zip files +{ +public: + Poco::FIFOEvent EDone; + // Fired for each entry once commit is invoked + + ZipManipulator(const std::string& zipFile, bool backupOriginalFile); + /// Creates the ZipManipulator. + + virtual ~ZipManipulator(); + /// Destroys the ZipManipulator. + + void deleteFile(const std::string& zipPath); + /// Removes the given file from the Zip archive. + + void replaceFile(const std::string& zipPath, const std::string& localPath); + /// Replaces the contents of the file in the archive with the contents + /// from the file given by localPath. + + void renameFile(const std::string& zipPath, const std::string& newZipPath); + /// Renames the file in the archive to newZipPath + + void addFile(const std::string& zipPath, const std::string& localPath, ZipCommon::CompressionMethod cm = ZipCommon::CM_DEFLATE, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM); + /// Adds a file to the zip file. + + ZipArchive commit(); + /// Commits all changes and re-creates the Zip File with the changes applied. + /// Returns the ZipArchive for the newly created archive + /// + /// Changes will be first written to a temporary file, + /// then the originalfile will be either deleted or renamed to .bak, + /// then, the temp file will be renamed to the original zip file name. + + const ZipArchive& originalArchive() const; + /// Returns the original archive information + +private: + const ZipLocalFileHeader& getForChange(const std::string& zipPath) const; + /// Searches for the entry given by the zipPath. + /// Throws an exception if the entry does not exist + /// or if an entry already exists in the Changeslist + + void addOperation(const std::string& zipPath, ZipOperation::Ptr ptrOp); + /// Adds the operation to the changes list. Throws an exception if an + /// entry for the zipPath already exists + + void onEDone(const void* pSender, const ZipLocalFileHeader& hdr); + /// Forwards the event to the EDone event + + ZipArchive compress(const std::string& outFile); + /// Compresses the new file to outFile + +private: + typedef std::map Changes; + + const std::string _zipFile; + bool _backupOriginalFile; + Changes _changes; + Poco::SharedPtr _in; +}; + + +inline const ZipArchive& ZipManipulator::originalArchive() const +{ + return *_in; +} + + +} } // namespace Poco::Zip + + +#endif // Zip_ZipManipulator_INCLUDED Property changes on: Zip/include/Poco/Zip/ZipManipulator.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/ZipFileInfo.h =================================================================== --- Zip/include/Poco/Zip/ZipFileInfo.h (revision 0) +++ Zip/include/Poco/Zip/ZipFileInfo.h (revision 0) @@ -0,0 +1,484 @@ +// +// ZipFileInfo.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipFileInfo +// +// Definition of the ZipFileInfo class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_ZipFileInfo_INCLUDED +#define Zip_ZipFileInfo_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/ZipCommon.h" +#include "Poco/Zip/ZipUtil.h" + + +namespace Poco { +namespace Zip { + + +class ZipLocalFileHeader; + + +class Zip_API ZipFileInfo + /// Stores a Zip directory entry of a file +{ +public: + static const char HEADER[ZipCommon::HEADER_SIZE]; + + ZipFileInfo(const ZipLocalFileHeader& header); + /// Creates a ZipFileInfo from a ZipLocalFileHeader + + ZipFileInfo(std::istream& in, bool assumeHeaderRead); + /// Creates the ZipFileInfo by parsing the input stream. + /// If assumeHeaderRead is true we assume that the first 4 bytes were already read outside. + + ~ZipFileInfo(); + /// Destroys the ZipFileInfo. + + Poco::UInt32 getRelativeOffsetOfLocalHeader() const; + /// Where on the disk starts the localheader. Combined with the disk number gives the exact location of the header + + ZipCommon::CompressionMethod getCompressionMethod() const; + + bool isEncrypted() const; + + const Poco::DateTime& lastModifiedAt() const; + + Poco::UInt32 getCRC() const; + + Poco::UInt32 getHeaderSize() const; + /// Returns the total size of the header including filename + other additional fields + + Poco::UInt32 getCompressedSize() const; + + Poco::UInt32 getUncompressedSize() const; + + const std::string& getFileName() const; + + bool isFile() const; + + bool isDirectory() const; + + bool hasExtraField() const; + + const std::string& getExtraField() const; + + const std::string& getFileComment() const; + + void getVersionMadeBy(int& major, int& minor); + /// The ZIP version used to create the file + + void getRequiredVersion(int& major, int& minor); + /// The minimum version required to extract the data + + ZipCommon::HostSystem getHostSystem() const; + + Poco::UInt16 getDiskNumberStart() const; + /// The number of the disk on which this file begins (multidisk archives) + + ZipCommon::FileType getFileType() const; + /// Binary or ASCII file? + + std::string createHeader() const; + + void setOffset(Poco::UInt32 val); + +private: + void setCRC(Poco::UInt32 val); + + void setCompressedSize(Poco::UInt32 val); + + void setUncompressedSize(Poco::UInt32 val); + + void setCompressionMethod(ZipCommon::CompressionMethod cm); + + void setCompressionLevel(ZipCommon::CompressionLevel cl); + + void setRequiredVersion(int major, int minor); + + void setHostSystem(ZipCommon::HostSystem hs); + + void setLastModifiedAt(const Poco::DateTime& dt); + + void setEncryption(bool val); + + void setFileNameLength(Poco::UInt16 size); + + void setFileName(const std::string& str); + + void setExternalFileAttributes(Poco::UInt32 attrs); + + void parse(std::istream& in, bool assumeHeaderRead); + + void parseDateTime(); + + Poco::UInt32 getCRCFromHeader() const; + + Poco::UInt32 getCompressedSizeFromHeader() const; + + Poco::UInt32 getUncompressedSizeFromHeader() const; + + Poco::UInt16 getFileNameLength() const; + + Poco::UInt16 getExtraFieldLength() const; + + Poco::UInt16 getFileCommentLength() const; + + Poco::UInt32 getExternalFileAttributes() const; + + void setUnixAttributes(); + +private: + enum + { + HEADER_POS = 0, + VERSIONMADEBY_POS = HEADER_POS + ZipCommon::HEADER_SIZE, + VERSIONMADEBY_SIZE = 2, + VERSION_NEEDED_POS = VERSIONMADEBY_POS + VERSIONMADEBY_SIZE, + VERSION_NEEDED_SIZE = 2, + GENERAL_PURPOSE_POS = VERSION_NEEDED_POS + VERSION_NEEDED_SIZE, + GENERAL_PURPOSE_SIZE = 2, + COMPR_METHOD_POS = GENERAL_PURPOSE_POS + GENERAL_PURPOSE_SIZE, + COMPR_METHOD_SIZE = 2, + LASTMODFILETIME_POS = COMPR_METHOD_POS + COMPR_METHOD_SIZE, + LASTMODFILETIME_SIZE = 2, + LASTMODFILEDATE_POS = LASTMODFILETIME_POS + LASTMODFILETIME_SIZE, + LASTMODFILEDATE_SIZE = 2, + CRC32_POS = LASTMODFILEDATE_POS + LASTMODFILEDATE_SIZE, + CRC32_SIZE = 4, + COMPRESSED_SIZE_POS = CRC32_POS + CRC32_SIZE, + COMPRESSED_SIZE_SIZE = 4, + UNCOMPRESSED_SIZE_POS = COMPRESSED_SIZE_POS + COMPRESSED_SIZE_SIZE, + UNCOMPRESSED_SIZE_SIZE = 4, + FILENAME_LENGTH_POS = UNCOMPRESSED_SIZE_POS + UNCOMPRESSED_SIZE_SIZE, + FILENAME_LENGTH_SIZE = 2, + EXTRAFIELD_LENGTH_POS = FILENAME_LENGTH_POS + FILENAME_LENGTH_SIZE, + EXTRAFIELD_LENGTH_SIZE = 2, + FILECOMMENT_LENGTH_POS = EXTRAFIELD_LENGTH_POS + EXTRAFIELD_LENGTH_SIZE, + FILECOMMENT_LENGTH_SIZE = 2, + DISKNUMBERSTART_POS = FILECOMMENT_LENGTH_POS + FILECOMMENT_LENGTH_SIZE, + DISKNUMBERSTART_SIZE = 2, + INTERNALFILE_ATTR_POS = DISKNUMBERSTART_POS + DISKNUMBERSTART_SIZE, + INTERNALFILE_ATTR_SIZE = 2, + EXTERNALFILE_ATTR_POS = INTERNALFILE_ATTR_POS + INTERNALFILE_ATTR_SIZE, + EXTERNALFILE_ATTR_SIZE = 4, + RELATIVEOFFSETLOCALHEADER_POS = EXTERNALFILE_ATTR_POS + EXTERNALFILE_ATTR_SIZE, + RELATIVEOFFSETLOCALHEADER_SIZE = 4, + FULLHEADER_SIZE = 46 + }; + + enum + { + DEFAULT_UNIX_FILE_MODE = 0640, + DEFAULT_UNIX_DIR_MODE = 0755 + }; + + char _rawInfo[FULLHEADER_SIZE]; + Poco::UInt32 _crc32; + Poco::UInt32 _compressedSize; + Poco::UInt32 _uncompressedSize; + std::string _fileName; + Poco::DateTime _lastModifiedAt; + std::string _extraField; + std::string _fileComment; +}; + + +inline Poco::UInt32 ZipFileInfo::getRelativeOffsetOfLocalHeader() const +{ + return ZipUtil::get32BitValue(_rawInfo, RELATIVEOFFSETLOCALHEADER_POS); +} + + +inline Poco::UInt32 ZipFileInfo::getCRCFromHeader() const +{ + return ZipUtil::get32BitValue(_rawInfo, CRC32_POS); +} + + +inline Poco::UInt32 ZipFileInfo::getCompressedSizeFromHeader() const +{ + return ZipUtil::get32BitValue(_rawInfo, COMPRESSED_SIZE_POS); +} + + +inline Poco::UInt32 ZipFileInfo::getUncompressedSizeFromHeader() const +{ + return ZipUtil::get32BitValue(_rawInfo, UNCOMPRESSED_SIZE_POS); +} + + +inline void ZipFileInfo::parseDateTime() +{ + _lastModifiedAt = ZipUtil::parseDateTime(_rawInfo, LASTMODFILETIME_POS, LASTMODFILEDATE_POS); +} + + +inline ZipCommon::CompressionMethod ZipFileInfo::getCompressionMethod() const +{ + return static_cast(ZipUtil::get16BitValue(_rawInfo, COMPR_METHOD_POS)); +} + + +inline bool ZipFileInfo::isEncrypted() const +{ + // bit 0 indicates encryption + return ((ZipUtil::get16BitValue(_rawInfo, GENERAL_PURPOSE_POS) & 0x0001) != 0); +} + + +inline const Poco::DateTime& ZipFileInfo::lastModifiedAt() const +{ + return _lastModifiedAt; +} + + +inline Poco::UInt32 ZipFileInfo::getCRC() const +{ + return _crc32; +} + + +inline Poco::UInt32 ZipFileInfo::getCompressedSize() const +{ + return _compressedSize; +} + + +inline Poco::UInt32 ZipFileInfo::getUncompressedSize() const +{ + return _uncompressedSize; +} + + +inline const std::string& ZipFileInfo::getFileName() const +{ + return _fileName; +} + + +inline bool ZipFileInfo::isFile() const +{ + return !isDirectory(); +} + + +inline bool ZipFileInfo::isDirectory() const +{ + poco_assert_dbg(!_fileName.empty()); + return getUncompressedSize() == 0 && getCompressionMethod() == ZipCommon::CM_STORE && _fileName[_fileName.length()-1] == '/'; +} + + +inline Poco::UInt16 ZipFileInfo::getFileNameLength() const +{ + return ZipUtil::get16BitValue(_rawInfo, FILENAME_LENGTH_POS); +} + + +inline Poco::UInt16 ZipFileInfo::getExtraFieldLength() const +{ + return ZipUtil::get16BitValue(_rawInfo, EXTRAFIELD_LENGTH_POS); +} + + +inline bool ZipFileInfo::hasExtraField() const +{ + return getExtraFieldLength() > 0; +} + + +inline const std::string& ZipFileInfo::getExtraField() const +{ + return _extraField; +} + + +inline const std::string& ZipFileInfo::getFileComment() const +{ + return _fileComment; +} + + +inline Poco::UInt16 ZipFileInfo::getFileCommentLength() const +{ + return ZipUtil::get16BitValue(_rawInfo, FILECOMMENT_LENGTH_POS); +} + + +inline void ZipFileInfo::getVersionMadeBy(int& major, int& minor) +{ + major = (_rawInfo[VERSIONMADEBY_POS]/10); + minor = (_rawInfo[VERSIONMADEBY_POS]%10); +} + + +inline void ZipFileInfo::getRequiredVersion(int& major, int& minor) +{ + major = (_rawInfo[VERSION_NEEDED_POS]/10); + minor = (_rawInfo[VERSION_NEEDED_POS]%10); +} + + +inline ZipCommon::HostSystem ZipFileInfo::getHostSystem() const +{ + return static_cast(_rawInfo[VERSION_NEEDED_POS + 1]); +} + + +inline Poco::UInt16 ZipFileInfo::getDiskNumberStart() const +{ + return ZipUtil::get16BitValue(_rawInfo, DISKNUMBERSTART_POS); +} + + +inline ZipCommon::FileType ZipFileInfo::getFileType() const +{ + return static_cast(_rawInfo[INTERNALFILE_ATTR_POS] & 0x01); +} + + +inline Poco::UInt32 ZipFileInfo::getExternalFileAttributes() const +{ + return ZipUtil::get32BitValue(_rawInfo, EXTERNALFILE_ATTR_POS); +} + + +inline Poco::UInt32 ZipFileInfo::getHeaderSize() const +{ + return FULLHEADER_SIZE + getFileNameLength() + getExtraFieldLength() + getFileCommentLength(); +} + + +inline void ZipFileInfo::setCRC(Poco::UInt32 val) +{ + _crc32 = val; + ZipUtil::set32BitValue(val, _rawInfo, CRC32_POS); +} + + +inline void ZipFileInfo::setOffset(Poco::UInt32 val) +{ + ZipUtil::set32BitValue(val, _rawInfo, RELATIVEOFFSETLOCALHEADER_POS); +} + + +inline void ZipFileInfo::setCompressedSize(Poco::UInt32 val) +{ + _compressedSize = val; + ZipUtil::set32BitValue(val, _rawInfo, COMPRESSED_SIZE_POS); +} + + +inline void ZipFileInfo::setUncompressedSize(Poco::UInt32 val) +{ + _uncompressedSize = val; + ZipUtil::set32BitValue(val, _rawInfo, UNCOMPRESSED_SIZE_POS); +} + + +inline void ZipFileInfo::setCompressionMethod(ZipCommon::CompressionMethod cm) +{ + ZipUtil::set16BitValue(static_cast(cm), _rawInfo, COMPR_METHOD_POS); +} + + +inline void ZipFileInfo::setCompressionLevel(ZipCommon::CompressionLevel cl) +{ + // bit 1 and 2 indicate the level + Poco::UInt16 val = static_cast(cl); + val <<= 1; + Poco::UInt16 mask = 0xfff9; + _rawInfo[GENERAL_PURPOSE_POS] = ((_rawInfo[GENERAL_PURPOSE_POS] & mask) | val); +} + + +inline void ZipFileInfo::setFileNameLength(Poco::UInt16 size) +{ + ZipUtil::set16BitValue(size, _rawInfo, FILENAME_LENGTH_POS); +} + + +inline void ZipFileInfo::setHostSystem(ZipCommon::HostSystem hs) +{ + _rawInfo[VERSIONMADEBY_POS + 1] = static_cast(hs); + _rawInfo[VERSION_NEEDED_POS + 1] = static_cast(hs); +} + + +inline void ZipFileInfo::setRequiredVersion(int major, int minor) +{ + poco_assert (minor < 10); + poco_assert (major < 24); + Poco::UInt8 val = static_cast(major)*10+static_cast(minor); + _rawInfo[VERSIONMADEBY_POS] = static_cast(val); + _rawInfo[VERSION_NEEDED_POS] = static_cast(val); +} + + +inline void ZipFileInfo::setLastModifiedAt(const Poco::DateTime& dt) +{ + _lastModifiedAt = dt; + ZipUtil::setDateTime(dt, _rawInfo, LASTMODFILETIME_POS, LASTMODFILEDATE_POS); +} + + +inline void ZipFileInfo::setEncryption(bool val) +{ + if (val) + _rawInfo[GENERAL_PURPOSE_POS] |= 0x01; + else + _rawInfo[GENERAL_PURPOSE_POS] &= 0xfe; +} + + +inline void ZipFileInfo::setFileName(const std::string& str) +{ + _fileName = str; + setFileNameLength(static_cast(str.size())); +} + + +inline void ZipFileInfo::setExternalFileAttributes(Poco::UInt32 attrs) +{ + ZipUtil::set32BitValue(attrs, _rawInfo, EXTERNALFILE_ATTR_POS); +} + + +} } // namespace Poco::Zip + + +#endif // Zip_ZipFileInfo_INCLUDED Property changes on: Zip/include/Poco/Zip/ZipFileInfo.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/ZipArchiveInfo.h =================================================================== --- Zip/include/Poco/Zip/ZipArchiveInfo.h (revision 0) +++ Zip/include/Poco/Zip/ZipArchiveInfo.h (revision 0) @@ -0,0 +1,210 @@ +// +// ZipArchiveInfo.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipArchiveInfo +// +// Definition of the ZipArchiveInfo class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_ZipArchiveInfo_INCLUDED +#define Zip_ZipArchiveInfo_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/ZipCommon.h" +#include "Poco/Zip/ZipUtil.h" + + +namespace Poco { +namespace Zip { + + +class Zip_API ZipArchiveInfo + /// A ZipArchiveInfo stores central directory info +{ +public: + static const char HEADER[ZipCommon::HEADER_SIZE]; + + ZipArchiveInfo(); + /// Default constructor, everything set to zero or empty + + ZipArchiveInfo(std::istream& in, bool assumeHeaderRead); + /// Creates the ZipArchiveInfo by parsing the input stream. + /// If assumeHeaderRead is true we assume that the first 4 bytes were already read outside. + + ~ZipArchiveInfo(); + /// Destroys the ZipArchiveInfo. + + Poco::UInt16 getDiskNumber() const; + /// Get the number of the disk where this header can be found + + Poco::UInt16 getFirstDiskForDirectoryHeader() const; + /// Returns the number of the disk that contains the start of the directory header + + Poco::UInt16 getNumberOfEntries() const; + /// Returns the number of entries on this disk + + Poco::UInt16 getTotalNumberOfEntries() const; + /// Returns the total number of entries on all disks + + Poco::UInt32 getCentralDirectorySize() const; + /// Returns the size of the central directory in bytes + + std::streamoff getHeaderOffset() const; + /// Returns the offset of the header in relation to the begin of this disk + + const std::string& getZipComment() const; + /// Returns the (optional) Zip Comment + + void setNumberOfEntries(Poco::UInt16 val); + /// Returns the number of entries on this disk + + void setTotalNumberOfEntries(Poco::UInt16 val); + /// Returns the total number of entries on all disks + + void setCentralDirectorySize(Poco::UInt32 val); + /// Returns the size of the central directory in bytes + + void setHeaderOffset(Poco::UInt32 val); + + std::string createHeader() const; + /// Creates a header + +private: + void parse(std::istream& inp, bool assumeHeaderRead); + + Poco::UInt16 getZipCommentSize() const; + +private: + enum + { + HEADER_POS = 0, + NUMBEROFTHISDISK_POS = HEADER_POS + ZipCommon::HEADER_SIZE, + NUMBEROFTHISDISK_SIZE = 2, + NUMBEROFCENTRALDIRDISK_POS = NUMBEROFTHISDISK_POS + NUMBEROFTHISDISK_SIZE, + NUMBEROFCENTRALDIRDISK_SIZE = 2, + NUMENTRIESTHISDISK_POS = NUMBEROFCENTRALDIRDISK_POS + NUMBEROFCENTRALDIRDISK_SIZE, + NUMENTRIESTHISDISK_SIZE = 2, + TOTALNUMENTRIES_POS = NUMENTRIESTHISDISK_POS + NUMENTRIESTHISDISK_SIZE, + TOTALNUMENTRIES_SIZE = 2, + CENTRALDIRSIZE_POS = TOTALNUMENTRIES_POS + TOTALNUMENTRIES_SIZE, + CENTRALDIRSIZE_SIZE = 4, + CENTRALDIRSTARTOFFSET_POS = CENTRALDIRSIZE_POS + CENTRALDIRSIZE_SIZE, + CENTRALDIRSTARTOFFSET_SIZE = 4, + ZIPCOMMENT_LENGTH_POS = CENTRALDIRSTARTOFFSET_POS + CENTRALDIRSTARTOFFSET_SIZE, + ZIPCOMMENT_LENGTH_SIZE = 2, + FULLHEADER_SIZE = 22 + }; + + char _rawInfo[FULLHEADER_SIZE]; + std::streamoff _startPos; + std::string _comment; +}; + + +inline Poco::UInt16 ZipArchiveInfo::getDiskNumber() const +{ + return ZipUtil::get16BitValue(_rawInfo, NUMBEROFTHISDISK_POS); +} + + +inline Poco::UInt16 ZipArchiveInfo::getFirstDiskForDirectoryHeader() const +{ + return ZipUtil::get16BitValue(_rawInfo, NUMBEROFCENTRALDIRDISK_POS); +} + + +inline Poco::UInt16 ZipArchiveInfo::getNumberOfEntries() const +{ + return ZipUtil::get16BitValue(_rawInfo, NUMENTRIESTHISDISK_POS); +} + + +inline Poco::UInt16 ZipArchiveInfo::getTotalNumberOfEntries() const +{ + return ZipUtil::get16BitValue(_rawInfo, TOTALNUMENTRIES_POS); +} + + +inline Poco::UInt32 ZipArchiveInfo::getCentralDirectorySize() const +{ + return ZipUtil::get32BitValue(_rawInfo, CENTRALDIRSIZE_POS); +} + + +inline std::streamoff ZipArchiveInfo::getHeaderOffset() const +{ + return _startPos; +} + + +inline Poco::UInt16 ZipArchiveInfo::getZipCommentSize() const +{ + return ZipUtil::get16BitValue(_rawInfo, ZIPCOMMENT_LENGTH_POS); +} + + +inline const std::string& ZipArchiveInfo::getZipComment() const +{ + return _comment; +} + + +inline void ZipArchiveInfo::setNumberOfEntries(Poco::UInt16 val) +{ + ZipUtil::set16BitValue(val, _rawInfo, NUMENTRIESTHISDISK_POS); +} + + +inline void ZipArchiveInfo::setTotalNumberOfEntries(Poco::UInt16 val) +{ + ZipUtil::set16BitValue(val, _rawInfo, TOTALNUMENTRIES_POS); +} + + +inline void ZipArchiveInfo::setCentralDirectorySize(Poco::UInt32 val) +{ + ZipUtil::set32BitValue(val, _rawInfo, CENTRALDIRSIZE_POS); +} + + +inline void ZipArchiveInfo::setHeaderOffset(Poco::UInt32 val) +{ + ZipUtil::set32BitValue(val, _rawInfo, CENTRALDIRSTARTOFFSET_POS); +} + + +} } // namespace Poco::Zip + + +#endif // Zip_ZipArchiveInfo_INCLUDED Property changes on: Zip/include/Poco/Zip/ZipArchiveInfo.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/ZipException.h =================================================================== --- Zip/include/Poco/Zip/ZipException.h (revision 0) +++ Zip/include/Poco/Zip/ZipException.h (revision 0) @@ -0,0 +1,58 @@ +// +// ZipException.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipException +// +// Definition of the ZipException class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_ZipException_INCLUDED +#define Zip_ZipException_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Exception.h" + + +namespace Poco { +namespace Zip { + + +POCO_DECLARE_EXCEPTION(Zip_API, ZipException, Poco::RuntimeException) +POCO_DECLARE_EXCEPTION(Zip_API, ZipManipulationException, ZipException) + + +} } // namespace Poco::Zip + + +#endif // Zip_ZipException_INCLUDED Property changes on: Zip/include/Poco/Zip/ZipException.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/SkipCallback.h =================================================================== --- Zip/include/Poco/Zip/SkipCallback.h (revision 0) +++ Zip/include/Poco/Zip/SkipCallback.h (revision 0) @@ -0,0 +1,68 @@ +// +// SkipCallback.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: SkipCallback +// +// Definition of the SkipCallback class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_SkipCallback_INCLUDED +#define Zip_SkipCallback_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/ParseCallback.h" + + +namespace Poco { +namespace Zip { + + +class Zip_API SkipCallback: public ParseCallback + /// A SkipCallback simply skips over the data +{ +public: + SkipCallback(); + /// Creates the SkipCallback. + + virtual ~SkipCallback(); + /// Destroys the SkipCallback. + + bool handleZipEntry(std::istream& zipStream, const ZipLocalFileHeader& hdr); +}; + + +} } // namespace Poco::Zip + + +#endif // Zip_SkipCallback_INCLUDED Property changes on: Zip/include/Poco/Zip/SkipCallback.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/ZipOperation.h =================================================================== --- Zip/include/Poco/Zip/ZipOperation.h (revision 0) +++ Zip/include/Poco/Zip/ZipOperation.h (revision 0) @@ -0,0 +1,78 @@ +// +// ZipOperation.h +// +// $Id$ +// +// Library: Zip +// Package: Manipulation +// Module: ZipOperation +// +// Definition of the ZipOperation class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_ZipOperation_INCLUDED +#define Zip_ZipOperation_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/RefCountedObject.h" +#include "Poco/AutoPtr.h" +#include +#include + + +namespace Poco { +namespace Zip { + + +class Compress; + + +class Zip_API ZipOperation: public Poco::RefCountedObject + /// Abstract super class for operations on individual zip entries +{ +public: + typedef Poco::AutoPtr Ptr; + + ZipOperation(); + /// Creates the ZipOperation. + + virtual void execute(Compress& c, std::istream& input) = 0; + /// Executes the operation + +protected: + virtual ~ZipOperation(); + /// Destroys the ZipOperation. +}; + + +} } // namespace Poco::Zip + + +#endif // Zip_ZipOperation_INCLUDED Property changes on: Zip/include/Poco/Zip/ZipOperation.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/Keep.h =================================================================== --- Zip/include/Poco/Zip/Keep.h (revision 0) +++ Zip/include/Poco/Zip/Keep.h (revision 0) @@ -0,0 +1,71 @@ +// +// Keep.h +// +// $Id$ +// +// Library: Zip +// Package: Manipulation +// Module: Keep +// +// Definition of the Keep class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_Keep_INCLUDED +#define Zip_Keep_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/ZipOperation.h" +#include "Poco/Zip/ZipLocalFileHeader.h" + + +namespace Poco { +namespace Zip { + + +class Zip_API Keep: public ZipOperation + /// Keep simply forwards the compressed data stream from the input ZipArchive + /// to the output zip archive +{ +public: + Keep(const ZipLocalFileHeader& hdr); + /// Creates the Keep object. + + void execute(Compress& c, std::istream& input); + ///Adds a copy of the compressed input file to the ZipArchive + +private: + const ZipLocalFileHeader _hdr; +}; + + +} } // namespace Poco::Zip + + +#endif // Zip_Keep_INCLUDED Property changes on: Zip/include/Poco/Zip/Keep.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/ZipLocalFileHeader.h =================================================================== --- Zip/include/Poco/Zip/ZipLocalFileHeader.h (revision 0) +++ Zip/include/Poco/Zip/ZipLocalFileHeader.h (revision 0) @@ -0,0 +1,486 @@ +// +// ZipLocalFileHeader.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipLocalFileHeader +// +// Definition of the ZipLocalFileHeader class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_ZipLocalFileHeader_INCLUDED +#define Zip_ZipLocalFileHeader_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/ZipUtil.h" +#include "Poco/Zip/ZipCommon.h" +#include "Poco/DateTime.h" +#include "Poco/Path.h" +#include + + +namespace Poco { +namespace Zip { + + +class ParseCallback; + + +class Zip_API ZipLocalFileHeader + /// Stores a Zip local file header +{ +public: + static const char HEADER[ZipCommon::HEADER_SIZE]; + + ZipLocalFileHeader(const Poco::Path& fileName, const Poco::DateTime& lastModifiedAt, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl); + /// Creates a zip file header from an absoluteFile. fileName is the name of the file in the zip, outputIsSeekable determines if we write + /// CRC and file sizes to the LocalFileHeader or after data compression into a ZipDataInfo + + ZipLocalFileHeader(std::istream& inp, bool assumeHeaderRead, ParseCallback& callback); + /// Creates the ZipLocalFileHeader by parsing the input stream. + /// If assumeHeaderRead is true we assume that the first 4 bytes were already read outside. + /// If skipOverDataBlock is true we position the stream after the data block (either at the next FileHeader or the Directory Entry) + + virtual ~ZipLocalFileHeader(); + /// Destroys the ZipLocalFileHeader. + + ZipCommon::HostSystem getHostSystem() const; + + int getMajorVersionNumber() const; + + int getMinorVersionNumber() const; + + void getRequiredVersion(int& major, int& minor); + /// The minimum version required to extract the data + + Poco::UInt32 getHeaderSize() const; + /// Returns the total size of the header including filename + extra field size + + void setStartPos(std::streamoff start); + /// Sets the start position to start and the end position to start+compressedSize + + std::streamoff getStartPos() const; + /// Returns the position of the first byte of the header in the file stream + + std::streamoff getEndPos() const; + /// Points past the last byte of the file entry (ie. either the first byte of the next header, or the directory) + + std::streamoff getDataStartPos() const; + /// Returns the streamoffset for the very first byte of data. Will be equal to DataEndPos if no data present + + std::streamoff getDataEndPos() const; + + ZipCommon::CompressionMethod getCompressionMethod() const; + + ZipCommon::CompressionLevel getCompressionLevel() const; + /// Returns the compression level used. Only valid when the compression method is CM_DEFLATE + + bool isEncrypted() const; + + const Poco::DateTime& lastModifiedAt() const; + + Poco::UInt32 getCRC() const; + + Poco::UInt32 getCompressedSize() const; + + Poco::UInt32 getUncompressedSize() const; + + void setCRC(Poco::UInt32 val); + + void setCompressedSize(Poco::UInt32 val); + + void setUncompressedSize(Poco::UInt32 val); + + const std::string& getFileName() const; + + bool isFile() const; + + bool isDirectory() const; + + bool hasExtraField() const; + + const std::string& getExtraField() const; + + bool hasData() const; + + bool searchCRCAndSizesAfterData() const; + + void setSearchCRCAndSizesAfterData(bool val); + + void setFileName(const std::string& fileName, bool isDirectory); + + std::string createHeader() const; + /// Creates a header + +private: + void parse(std::istream& inp, bool assumeHeaderRead); + + void parseDateTime(); + + void init(const Poco::Path& fileName, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl); + + Poco::UInt16 getFileNameLength() const; + + Poco::UInt16 getExtraFieldLength() const; + + Poco::UInt32 getCRCFromHeader() const; + + Poco::UInt32 getCompressedSizeFromHeader() const; + + Poco::UInt32 getUncompressedSizeFromHeader() const; + + void setRequiredVersion(int major, int minor); + + void setHostSystem(ZipCommon::HostSystem hs); + + void setLastModifiedAt(const Poco::DateTime& dt); + + void setEncryption(bool val); + + void setFileNameLength(Poco::UInt16 size); + + void setExtraFieldSize(Poco::UInt16 size); + + void setCompressionMethod(ZipCommon::CompressionMethod cm); + + void setCompressionLevel(ZipCommon::CompressionLevel cl); + +private: + enum + { + HEADER_POS = 0, + VERSION_SIZE = 2, + VERSION_POS = HEADER_POS+ZipCommon::HEADER_SIZE, + GENERAL_PURPOSE_SIZE = 2, + GENERAL_PURPOSE_POS = VERSION_POS + VERSION_SIZE, + COMPR_METHOD_SIZE = 2, + COMPR_METHOD_POS = GENERAL_PURPOSE_POS + GENERAL_PURPOSE_SIZE, + LASTMODEFILETIME_SIZE = 2, + LASTMODEFILETIME_POS = COMPR_METHOD_POS + COMPR_METHOD_SIZE, + LASTMODEFILEDATE_SIZE = 2, + LASTMODEFILEDATE_POS = LASTMODEFILETIME_POS + LASTMODEFILETIME_SIZE, + CRC32_SIZE = 4, + CRC32_POS = LASTMODEFILEDATE_POS + LASTMODEFILEDATE_SIZE, + COMPRESSEDSIZE_SIZE = 4, + COMPRESSEDSIZE_POS = CRC32_POS + CRC32_SIZE, + UNCOMPRESSEDSIZE_SIZE = 4, + UNCOMPRESSEDSIZE_POS = COMPRESSEDSIZE_POS + COMPRESSEDSIZE_SIZE, + FILELENGTH_SIZE = 2, + FILELENGTH_POS = UNCOMPRESSEDSIZE_POS + UNCOMPRESSEDSIZE_SIZE, + EXTRAFIELD_LENGTH = 2, + EXTRAFIELD_POS = FILELENGTH_POS + FILELENGTH_SIZE, + FULLHEADER_SIZE = 30 + }; + + char _rawHeader[FULLHEADER_SIZE]; + std::streamoff _startPos; + std::streamoff _endPos; + std::string _fileName; + Poco::DateTime _lastModifiedAt; + std::string _extraField; + Poco::UInt32 _crc32; + Poco::UInt32 _compressedSize; + Poco::UInt32 _uncompressedSize; +}; + + +inline void ZipLocalFileHeader::setFileNameLength(Poco::UInt16 size) +{ + ZipUtil::set16BitValue(size, _rawHeader, FILELENGTH_POS); +} + + +inline void ZipLocalFileHeader::setExtraFieldSize(Poco::UInt16 size) +{ + ZipUtil::set16BitValue(size, _rawHeader, EXTRAFIELD_POS); +} + + +inline ZipCommon::HostSystem ZipLocalFileHeader::getHostSystem() const +{ + return static_cast(_rawHeader[VERSION_POS + 1]); +} + + +inline void ZipLocalFileHeader::setHostSystem(ZipCommon::HostSystem hs) +{ + _rawHeader[VERSION_POS + 1] = static_cast(hs); +} + + +inline int ZipLocalFileHeader::getMajorVersionNumber() const +{ + return (_rawHeader[VERSION_POS]/10); +} + + +inline int ZipLocalFileHeader::getMinorVersionNumber() const +{ + return (_rawHeader[VERSION_POS]%10); +} + + +inline void ZipLocalFileHeader::getRequiredVersion(int& major, int& minor) +{ + major = getMajorVersionNumber(); + minor = getMinorVersionNumber(); +} + + +inline void ZipLocalFileHeader::setRequiredVersion(int major, int minor) +{ + poco_assert (minor < 10); + poco_assert (major < 24); + _rawHeader[VERSION_POS] = static_cast(static_cast(major)*10+static_cast(minor)); +} + +inline Poco::UInt16 ZipLocalFileHeader::getFileNameLength() const +{ + return ZipUtil::get16BitValue(_rawHeader, FILELENGTH_POS); +} + + +inline Poco::UInt16 ZipLocalFileHeader::getExtraFieldLength() const +{ + return ZipUtil::get16BitValue(_rawHeader, EXTRAFIELD_POS); +} + + +inline Poco::UInt32 ZipLocalFileHeader::getHeaderSize() const +{ + return FULLHEADER_SIZE+getExtraFieldLength()+getFileNameLength(); +} + + +inline std::streamoff ZipLocalFileHeader::getStartPos() const +{ + return _startPos; +} + + +inline void ZipLocalFileHeader::setStartPos(std::streamoff start) +{ + _startPos = start; + _endPos = start + getHeaderSize()+getCompressedSize(); +} + + +inline std::streamoff ZipLocalFileHeader::getEndPos() const +{ + return _endPos; +} + + +inline void ZipLocalFileHeader::parseDateTime() +{ + _lastModifiedAt = ZipUtil::parseDateTime(_rawHeader, LASTMODEFILETIME_POS, LASTMODEFILEDATE_POS); +} + + +inline void ZipLocalFileHeader::setLastModifiedAt(const Poco::DateTime& dt) +{ + _lastModifiedAt = dt; + ZipUtil::setDateTime(dt, _rawHeader, LASTMODEFILETIME_POS, LASTMODEFILEDATE_POS); +} + + +inline ZipCommon::CompressionMethod ZipLocalFileHeader::getCompressionMethod() const +{ + return static_cast(ZipUtil::get16BitValue(_rawHeader, COMPR_METHOD_POS)); +} + + +inline ZipCommon::CompressionLevel ZipLocalFileHeader::getCompressionLevel() const +{ + // bit 1 and 2 indicate the level + return static_cast((ZipUtil::get16BitValue(_rawHeader, GENERAL_PURPOSE_POS)>>1) & 0x0003); +} + + +inline void ZipLocalFileHeader::setCompressionMethod(ZipCommon::CompressionMethod cm) +{ + ZipUtil::set16BitValue(static_cast(cm), _rawHeader, COMPR_METHOD_POS); +} + + +inline void ZipLocalFileHeader::setCompressionLevel(ZipCommon::CompressionLevel cl) +{ + // bit 1 and 2 indicate the level + Poco::UInt16 val = static_cast(cl); + val <<= 1; + Poco::UInt16 mask = 0xfff9; + _rawHeader[GENERAL_PURPOSE_POS] = ((_rawHeader[GENERAL_PURPOSE_POS] & mask) | val); +} + + +inline bool ZipLocalFileHeader::isEncrypted() const +{ + // bit 0 indicates encryption + return ((ZipUtil::get16BitValue(_rawHeader, GENERAL_PURPOSE_POS) & 0x0001) != 0); +} + + +inline void ZipLocalFileHeader::setEncryption(bool val) +{ + if (val) + _rawHeader[GENERAL_PURPOSE_POS] |= 0x01; + else + _rawHeader[GENERAL_PURPOSE_POS] &= 0xfe; +} + + +inline void ZipLocalFileHeader::setSearchCRCAndSizesAfterData(bool val) +{ + //set bit 3 of general purpose reg + if (val) + _rawHeader[GENERAL_PURPOSE_POS] |= 0x08; + else + _rawHeader[GENERAL_PURPOSE_POS] &= 0xf7; +} + + +inline const Poco::DateTime& ZipLocalFileHeader::lastModifiedAt() const +{ + return _lastModifiedAt; +} + + +inline Poco::UInt32 ZipLocalFileHeader::getCRC() const +{ + return _crc32; +} + + +inline Poco::UInt32 ZipLocalFileHeader::getCompressedSize() const +{ + return _compressedSize; +} + + +inline Poco::UInt32 ZipLocalFileHeader::getUncompressedSize() const +{ + return _uncompressedSize; +} + + +inline void ZipLocalFileHeader::setCRC(Poco::UInt32 val) +{ + _crc32 = val; + ZipUtil::set32BitValue(val, _rawHeader, CRC32_POS); +} + + +inline void ZipLocalFileHeader::setCompressedSize(Poco::UInt32 val) +{ + _compressedSize = val; + ZipUtil::set32BitValue(val, _rawHeader, COMPRESSEDSIZE_POS); +} + + +inline void ZipLocalFileHeader::setUncompressedSize(Poco::UInt32 val) +{ + _uncompressedSize = val; + ZipUtil::set32BitValue(val, _rawHeader, UNCOMPRESSEDSIZE_POS); +} + + +inline Poco::UInt32 ZipLocalFileHeader::getCRCFromHeader() const +{ + return ZipUtil::get32BitValue(_rawHeader, CRC32_POS); +} + + +inline Poco::UInt32 ZipLocalFileHeader::getCompressedSizeFromHeader() const +{ + return ZipUtil::get32BitValue(_rawHeader, COMPRESSEDSIZE_POS); +} + + +inline Poco::UInt32 ZipLocalFileHeader::getUncompressedSizeFromHeader() const +{ + return ZipUtil::get32BitValue(_rawHeader, UNCOMPRESSEDSIZE_POS); +} + + +inline const std::string& ZipLocalFileHeader::getFileName() const +{ + return _fileName; +} + + +inline bool ZipLocalFileHeader::isFile() const +{ + return !isDirectory(); +} + + +inline bool ZipLocalFileHeader::isDirectory() const +{ + poco_assert_dbg(!_fileName.empty()); + return getUncompressedSize() == 0 && getCompressionMethod() == ZipCommon::CM_STORE && _fileName[_fileName.length()-1] == '/'; +} + + +inline bool ZipLocalFileHeader::hasExtraField() const +{ + return getExtraFieldLength() > 0; +} + + +inline const std::string& ZipLocalFileHeader::getExtraField() const +{ + return _extraField; +} + + +inline bool ZipLocalFileHeader::hasData() const +{ + return (getCompressedSize() > 0); +} + + +inline std::streamoff ZipLocalFileHeader::getDataStartPos() const +{ + return getStartPos() + getHeaderSize(); +} + + +inline std::streamoff ZipLocalFileHeader::getDataEndPos() const +{ + return getDataStartPos()+getCompressedSize(); +} + + +} } // namespace Poco::Zip + + +#endif // Zip_ZipLocalFileHeader_INCLUDED Property changes on: Zip/include/Poco/Zip/ZipLocalFileHeader.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/ParseCallback.h =================================================================== --- Zip/include/Poco/Zip/ParseCallback.h (revision 0) +++ Zip/include/Poco/Zip/ParseCallback.h (revision 0) @@ -0,0 +1,76 @@ +// +// ParseCallback.h +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ParseCallback +// +// Definition of the ParseCallback class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_ParseCallback_INCLUDED +#define Zip_ParseCallback_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include + + +namespace Poco { +namespace Zip { + + +class ZipLocalFileHeader; + + +class Zip_API ParseCallback + /// Interface for callbacks to handle ZipData +{ +public: + ParseCallback(); + /// Creates the ParseCallback. + + virtual ~ParseCallback(); + /// Destroys the ParseCallback. + + virtual bool handleZipEntry(std::istream& zipStream, const ZipLocalFileHeader& hdr) = 0; + /// Handles parsing of the data of a single Zip Entry. zipStream is guaranteed to be at the very first data byte. + /// Note that a callback class SHOULD consume all data inside a zip file, ie. after + /// processing the next 4 bytes point the next ZipLocalFileHeader or the ZipDirectory. + /// If it fails to do so, it must return false, otherwise true. + +}; + + +} } // namespace Poco::Zip + + +#endif // Zip_ParseCallback_INCLUDED Property changes on: Zip/include/Poco/Zip/ParseCallback.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/include/Poco/Zip/Add.h =================================================================== --- Zip/include/Poco/Zip/Add.h (revision 0) +++ Zip/include/Poco/Zip/Add.h (revision 0) @@ -0,0 +1,73 @@ +// +// Add.h +// +// $Id$ +// +// Library: Zip +// Package: Manipulation +// Module: Add +// +// Definition of the Add class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Zip_Add_INCLUDED +#define Zip_Add_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/ZipOperation.h" +#include "Poco/Zip/ZipCommon.h" + + +namespace Poco { +namespace Zip { + + +class Zip_API Add: public ZipOperation + /// Operation Add adds a new file entry to an existing Zip File +{ +public: + Add(const std::string& zipPath, const std::string& localPath, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl); + /// Creates the Add. + + void execute(Compress& c, std::istream& input); + /// Performs the add operation + +private: + const std::string _zipPath; + const std::string _localPath; + const ZipCommon::CompressionMethod _cm; + const ZipCommon::CompressionLevel _cl; +}; + + +} } // namespace Poco::Zip + + +#endif // Zip_Add_INCLUDED Property changes on: Zip/include/Poco/Zip/Add.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/ZipUtil.cpp =================================================================== --- Zip/src/ZipUtil.cpp (revision 0) +++ Zip/src/ZipUtil.cpp (revision 0) @@ -0,0 +1,212 @@ +// +// ZipUtil.cpp +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipUtil +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/ZipUtil.h" +#include "Poco/Zip/ZipException.h" +#include "Poco/Zip/ZipLocalFileHeader.h" +#include "Poco/Zip/ZipFileInfo.h" +#include "Poco/Zip/ZipDataInfo.h" +#include "Poco/Zip/ZipArchiveInfo.h" +#include + + +namespace Poco { +namespace Zip { + + +Poco::DateTime ZipUtil::parseDateTime(const char* pVal, const Poco::UInt32 timePos, const Poco::UInt32 datePos) +{ + Poco::UInt16 time = ZipUtil::get16BitValue(pVal, timePos); + Poco::UInt16 date = ZipUtil::get16BitValue(pVal, datePos); + //TIME: second 0-4, minute 5-10, hour 11-15, second resolution is 2! + int sec = 2*(time & 0x001fu); // 0000 0000 0001 1111 + int min = ((time & 0x07e0u) >> 5); // 0000 0111 1110 0000 + int hour= ((time & 0xf800u) >> 11); // 1111 1000 0000 0000 + + //DATE: day 0-4, month 5-8, year (starting with 1980): 9-16 + int day = (date & 0x001fu); // 0000 0000 0001 1111 + int mon = ((date & 0x01e0u) >> 5); // 0000 0001 1110 0000 + int year= 1980+((date & 0xfe00u) >> 9); // 1111 1110 0000 0000 + return Poco::DateTime(year, mon, day, hour, min, sec); +} + + +void ZipUtil::setDateTime(const Poco::DateTime& dt, char* pVal, const Poco::UInt32 timePos, const Poco::UInt32 datePos) +{ + //TIME: second 0-4, minute 5-10, hour 11-15 + Poco::UInt16 time = static_cast((dt.second()/2) + (dt.minute()<<5) + (dt.hour()<<11)); + //DATE: day 0-4, month 5-8, year (starting with 1980): 9-16 + int year = dt.year() - 1980; + if (year<0) + year = 0; + Poco::UInt16 date = static_cast(dt.day() + (dt.month()<<5) + (year<<9)); + ZipUtil::set16BitValue(time, pVal, timePos); + ZipUtil::set16BitValue(date, pVal, datePos); + +} + + +std::string ZipUtil::fakeZLibInitString(ZipCommon::CompressionLevel cl) +{ + std::string init(2, ' '); + + // compression info: + // deflate is used, bit 0-3: 0x08 + // dictionary size is always 32k: calc ld2(32k)-8 = ld2(2^15) - 8 = 15 - 8 = 7 --> bit 4-7: 0x70 + init[0] = '\x78'; + + // now fake flags + // bits 0-4 check bits: set them so that init[0]*256+init[1] % 31 == 0 + // bit 5: preset dictionary? always no for us, set to 0 + // bits 6-7: compression level: 00 very fast, 01 fast, 10 normal, 11 best + if (cl == ZipCommon::CL_SUPERFAST) + init[1] = '\x00'; + else if (cl == ZipCommon::CL_FAST) + init[1] = '\x40'; + else if (cl == ZipCommon::CL_NORMAL) + init[1] = '\x80'; + else + init[1] = '\xc0'; + // now set the last 5 bits + Poco::UInt16 tmpVal = ((Poco::UInt16)init[0])*256+((unsigned char)init[1]); + char checkBits = (31 - (char)(tmpVal%31)); + init[1] |= checkBits; // set the lower 5 bits + tmpVal = ((Poco::UInt16)init[0])*256+((unsigned char)init[1]); + poco_assert_dbg ((tmpVal % 31) == 0); + return init; +} + + +void ZipUtil::sync(std::istream& in) +{ + enum + { + PREFIX = 2, + BUFFER_SIZE = 1024 + }; + char temp[BUFFER_SIZE]; + in.read(temp, PREFIX); + std::size_t tempPos = PREFIX; + + while (in.good() && !in.eof()) + { + // all zip headers start withe same 2byte prefix + if(std::memcmp(ZipLocalFileHeader::HEADER, &temp[tempPos - PREFIX], PREFIX) == 0) + { + // we have a possible header! + // read the next 2 bytes + in.read(temp+tempPos, PREFIX); + tempPos += PREFIX; + if (std::memcmp(ZipLocalFileHeader::HEADER+PREFIX, &temp[tempPos - PREFIX], PREFIX) == 0 || + std::memcmp(ZipArchiveInfo::HEADER+PREFIX, &temp[tempPos - PREFIX], PREFIX) == 0 || + std::memcmp(ZipFileInfo::HEADER+PREFIX, &temp[tempPos - PREFIX], PREFIX) == 0 || + std::memcmp(ZipDataInfo::HEADER+PREFIX, &temp[tempPos - PREFIX], PREFIX) == 0) + { + if (std::memcmp(ZipLocalFileHeader::HEADER+PREFIX, &temp[tempPos - PREFIX], PREFIX) == 0) + { + in.putback(ZipLocalFileHeader::HEADER[3]); + in.putback(ZipLocalFileHeader::HEADER[2]); + in.putback(ZipLocalFileHeader::HEADER[1]); + in.putback(ZipLocalFileHeader::HEADER[0]); + } + else if (std::memcmp(ZipArchiveInfo::HEADER+PREFIX, &temp[tempPos - PREFIX], PREFIX) == 0) + { + in.putback(ZipArchiveInfo::HEADER[3]); + in.putback(ZipArchiveInfo::HEADER[2]); + in.putback(ZipArchiveInfo::HEADER[1]); + in.putback(ZipArchiveInfo::HEADER[0]); + } + else if (std::memcmp(ZipFileInfo::HEADER+PREFIX, &temp[tempPos - PREFIX], PREFIX) == 0) + { + in.putback(ZipFileInfo::HEADER[3]); + in.putback(ZipFileInfo::HEADER[2]); + in.putback(ZipFileInfo::HEADER[1]); + in.putback(ZipFileInfo::HEADER[0]); + } + else + { + in.putback(ZipDataInfo::HEADER[3]); + in.putback(ZipDataInfo::HEADER[2]); + in.putback(ZipDataInfo::HEADER[1]); + in.putback(ZipDataInfo::HEADER[0]); + } + return; + } + else + { + // we have read 2 bytes, should only be one: putback the last char + in.putback(temp[tempPos - 1]); + --tempPos; + } + } + else + { + // read one byte + in.read(temp + tempPos, 1); + ++tempPos; + } + + if (tempPos > (BUFFER_SIZE - ZipCommon::HEADER_SIZE)) + { + std::memcpy(temp, &temp[tempPos - ZipCommon::HEADER_SIZE], ZipCommon::HEADER_SIZE); + tempPos = ZipCommon::HEADER_SIZE; + } + } +} + + +void ZipUtil::verifyZipEntryFileName(const std::string& fn) +{ + if (fn.find("\\") != std::string::npos) + throw ZipException("Illegal entry name " + fn + " containing \\"); + if (fn == "/") + throw ZipException("Illegal entry name /"); + if (fn.empty()) + throw ZipException("Illegal empty entry name"); + if (fn.find(ZipCommon::ILLEGAL_PATH) != std::string::npos) + throw ZipException("Illegal entry name " + fn + " containing " + ZipCommon::ILLEGAL_PATH); +} + + +std::string ZipUtil::validZipEntryFileName(const Poco::Path& entry) +{ + std::string fn = entry.toString(Poco::Path::PATH_UNIX); + verifyZipEntryFileName(fn); + return fn; +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/ZipUtil.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/Delete.cpp =================================================================== --- Zip/src/Delete.cpp (revision 0) +++ Zip/src/Delete.cpp (revision 0) @@ -0,0 +1,56 @@ +// +// Delete.cpp +// +// $Id$ +// +// Library: Zip +// Package: Manipulation +// Module: Delete +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/Delete.h" + + +namespace Poco { +namespace Zip { + + +Delete::Delete(const ZipLocalFileHeader& hdr): + _hdr(hdr) +{ +} + + +void Delete::execute(Compress& c, std::istream& input) +{ + // due to absolute positioning in compress we don't need to do anything +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/Delete.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/Decompress.cpp =================================================================== --- Zip/src/Decompress.cpp (revision 0) +++ Zip/src/Decompress.cpp (revision 0) @@ -0,0 +1,193 @@ +// +// Decompress.cpp +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: Decompress +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/Decompress.h" +#include "Poco/Zip/ZipLocalFileHeader.h" +#include "Poco/Zip/ZipArchive.h" +#include "Poco/Zip/ZipStream.h" +#include "Poco/Zip/ZipException.h" +#include "Poco/File.h" +#include "Poco/Exception.h" +#include "Poco/StreamCopier.h" +#include "Poco/Delegate.h" +#include + + +namespace Poco { +namespace Zip { + + +Decompress::Decompress(std::istream& in, const Poco::Path& outputDir, bool flattenDirs, bool keepIncompleteFiles): + _in(in), + _outDir(outputDir), + _flattenDirs(flattenDirs), + _keepIncompleteFiles(keepIncompleteFiles), + _mapping() +{ + _outDir.makeAbsolute(); + _outDir.makeDirectory(); + poco_assert (_in.good()); + Poco::File tmp(_outDir); + if (!tmp.exists()) + { + tmp.createDirectories(); + } + if (!tmp.isDirectory()) + throw Poco::IOException("Failed to create/open directory: " + _outDir.toString()); + EOk += Poco::Delegate >(this, &Decompress::onOk); + +} + + +Decompress::~Decompress() +{ + EOk -= Poco::Delegate >(this, &Decompress::onOk); +} + + +ZipArchive Decompress::decompressAllFiles() +{ + poco_assert (_mapping.empty()); + ZipArchive arch(_in, *this); + return arch; +} + + +bool Decompress::handleZipEntry(std::istream& zipStream, const ZipLocalFileHeader& hdr) +{ + if (hdr.isDirectory()) + { + // directory have 0 size, nth to read + if (!_flattenDirs) + { + std::string dirName = hdr.getFileName(); + if (dirName.find(ZipCommon::ILLEGAL_PATH) != std::string::npos) + throw ZipException("Illegal entry name " + dirName + " containing " + ZipCommon::ILLEGAL_PATH); + Poco::Path dir(_outDir, dirName); + dir.makeDirectory(); + Poco::File aFile(dir); + aFile.createDirectories(); + } + return true; + } + try + { + std::string fileName = hdr.getFileName(); + if (_flattenDirs) + { + // remove path info + Poco::Path p(fileName); + p.makeFile(); + fileName = p.getFileName(); + } + + if (fileName.find(ZipCommon::ILLEGAL_PATH) != std::string::npos) + throw ZipException("Illegal entry name " + fileName + " containing " + ZipCommon::ILLEGAL_PATH); + + Poco::Path file(fileName); + file.makeFile(); + Poco::Path dest(_outDir, file); + dest.makeFile(); + if (dest.depth() > 0) + { + Poco::File aFile(dest.parent()); + aFile.createDirectories(); + } + std::ofstream out(dest.toString().c_str(), std::ios::binary); + if (!out) + { + std::pair tmp = std::make_pair(hdr, "Failed to open output stream " + dest.toString()); + EError.notify(this, tmp); + return false; + } + ZipInputStream inp(zipStream, hdr, false); + Poco::StreamCopier::copyStream(inp, out); + out.close(); + Poco::File aFile(file); + if (!aFile.exists() || !aFile.isFile()) + { + std::pair tmp = std::make_pair(hdr, "Failed to create output stream " + dest.toString()); + EError.notify(this, tmp); + return false; + } + + if (!inp.crcValid()) + { + if (!_keepIncompleteFiles) + aFile.remove(); + std::pair tmp = std::make_pair(hdr, "CRC mismatch. Corrupt file: " + dest.toString()); + EError.notify(this, tmp); + return false; + } + + // cannot check against hdr.getUnCompressedSize if CRC and size are not set in hdr but in a ZipDataInfo + // crc is typically enough to detect errors + if (aFile.getSize() != hdr.getUncompressedSize() && !hdr.searchCRCAndSizesAfterData()) + { + if (!_keepIncompleteFiles) + aFile.remove(); + std::pair tmp = std::make_pair(hdr, "Filesizes do not match. Corrupt file: " + dest.toString()); + EError.notify(this, tmp); + return false; + } + + std::pair tmp = std::make_pair(hdr, file); + EOk.notify(this, tmp); + } + catch (Poco::Exception& e) + { + std::pair tmp = std::make_pair(hdr, std::string("Exception: " + e.displayText())); + EError.notify(this, tmp); + return false; + } + catch (...) + { + std::pair tmp = std::make_pair(hdr, std::string("Unknown Exception")); + EError.notify(this, tmp); + return false; + } + + return true; +} + + +void Decompress::onOk(const void*, std::pair& val) +{ + _mapping.insert(std::make_pair(val.first.getFileName(), val.second)); +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/Decompress.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/ZipArchive.cpp =================================================================== --- Zip/src/ZipArchive.cpp (revision 0) +++ Zip/src/ZipArchive.cpp (revision 0) @@ -0,0 +1,121 @@ +// +// ZipArchive.cpp +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipArchive +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/ZipArchive.h" +#include "Poco/Zip/SkipCallback.h" +#include "Poco/Exception.h" +#include + + +namespace Poco { +namespace Zip { + + +ZipArchive::ZipArchive(std::istream& in): + _entries(), + _infos(), + _disks() +{ + poco_assert_dbg (in); + SkipCallback skip; + parse(in, skip); +} + + +ZipArchive::ZipArchive(const FileHeaders& entries, const FileInfos& infos, const DirectoryInfos& dirs): + _entries(entries), + _infos(infos), + _disks(dirs) +{ +} + + +ZipArchive::ZipArchive(std::istream& in, ParseCallback& pc): + _entries(), + _infos(), + _disks() +{ + poco_assert_dbg (in); + parse(in, pc); +} + + +ZipArchive::~ZipArchive() +{ +} + + +void ZipArchive::parse(std::istream& in, ParseCallback& pc) +{ + // read 4 bytes + while (in.good() && !in.eof()) + { + char header[ZipCommon::HEADER_SIZE]={'\x00', '\x00', '\x00', '\x00'}; + in.read(header, ZipCommon::HEADER_SIZE); + if (in.eof()) + return; + if (std::memcmp(header, ZipLocalFileHeader::HEADER, ZipCommon::HEADER_SIZE) == 0) + { + ZipLocalFileHeader entry(in, true, pc); + poco_assert (_entries.insert(std::make_pair(entry.getFileName(), entry)).second); + } + else if (std::memcmp(header, ZipFileInfo::HEADER, ZipCommon::HEADER_SIZE) == 0) + { + ZipFileInfo info(in, true); + FileHeaders::iterator it = _entries.find(info.getFileName()); + if (it != _entries.end()) + { + it->second.setStartPos(info.getRelativeOffsetOfLocalHeader()); + } + poco_assert (_infos.insert(std::make_pair(info.getFileName(), info)).second); + } + else if (std::memcmp(header, ZipArchiveInfo::HEADER, ZipCommon::HEADER_SIZE) == 0) + { + ZipArchiveInfo nfo(in, true); + poco_assert (_disks.insert(std::make_pair(nfo.getDiskNumber(), nfo)).second); + } + else + { + if (_disks.empty()) + throw Poco::IllegalStateException("Illegal header in zip file"); + else + throw Poco::IllegalStateException("Garbage after directory header"); + } + } +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/ZipArchive.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/Rename.cpp =================================================================== --- Zip/src/Rename.cpp (revision 0) +++ Zip/src/Rename.cpp (revision 0) @@ -0,0 +1,58 @@ +// +// Rename.cpp +// +// $Id$ +// +// Library: Zip +// Package: Manipulation +// Module: Rename +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/Rename.h" +#include "Poco/Zip/Compress.h" + + +namespace Poco { +namespace Zip { + + +Rename::Rename(const ZipLocalFileHeader& hdr, const std::string& newZipEntryName): + _hdr(hdr), + _newZipEntryName(newZipEntryName) +{ +} + + +void Rename::execute(Compress& c, std::istream& input) +{ + c.addFileRaw(input, _hdr, _newZipEntryName); +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/Rename.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/PartialStream.cpp =================================================================== --- Zip/src/PartialStream.cpp (revision 0) +++ Zip/src/PartialStream.cpp (revision 0) @@ -0,0 +1,269 @@ +// +// PartialStream.cpp +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: PartialStream +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/PartialStream.h" +#include "Poco/Exception.h" +#include + + +namespace Poco { +namespace Zip { + + +PartialStreamBuf::PartialStreamBuf(std::istream& in, std::ios::pos_type start, std::ios::pos_type end, const std::string& pre, const std::string& post, bool initStream): + Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in), + _initialized(!initStream), + _start(start), + _numBytes(end-start), + _bytesWritten(0), + _pIstr(&in), + _pOstr(0), + _prefix(pre), + _postfix(post), + _ignoreStart(0), + _buffer(0), + _bufferOffset(0) +{ +} + + +PartialStreamBuf::PartialStreamBuf(std::ostream& out, std::size_t start, std::size_t end, bool initStream): + Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out), + _initialized(!initStream), + _start(0), + _numBytes(0), + _bytesWritten(0), + _pIstr(0), + _pOstr(&out), + _ignoreStart(start), + _buffer(end), + _bufferOffset(0) +{ +} + + +PartialStreamBuf::~PartialStreamBuf() +{ +} + + +int PartialStreamBuf::readFromDevice(char* buffer, std::streamsize length) +{ + if (_pIstr == 0 ||length == 0) return -1; + if (!_initialized) + { + _initialized = true; + _pIstr->clear(); + _pIstr->seekg(_start, std::ios_base::beg); + if (_pIstr->fail()) + throw Poco::IOException("Failed to reposition in stream"); + } + if (!_prefix.empty()) + { + std::streamsize tmp = (_prefix.size() > length)? length: static_cast(_prefix.size()); + std::memcpy(buffer, _prefix.c_str(), tmp); + _prefix = _prefix.substr(tmp); + return tmp; + } + + if (_numBytes == 0) + { + if (!_postfix.empty()) + { + std::streamsize tmp = (_postfix.size() > length)? length: static_cast(_postfix.size()); + std::memcpy(buffer, _postfix.c_str(), tmp); + _postfix = _postfix.substr(tmp); + return tmp; + } + else + return -1; + } + + if (!_pIstr->good()) + return -1; + + if (_numBytes < length) + length = static_cast(_numBytes); + + _pIstr->read(buffer, length); + std::streamsize bytesRead = _pIstr->gcount(); + _numBytes -= bytesRead; + return bytesRead; + +} + + +int PartialStreamBuf::writeToDevice(const char* buffer, std::streamsize length) +{ + if (_pOstr == 0 || length == 0) return -1; + if (!_initialized) + { + _initialized = true; + _pOstr->clear(); + if (_pOstr->fail()) + throw Poco::IOException("Failed to clear stream status"); + } + + if (_ignoreStart > 0) + { + if (_ignoreStart > length) + { + _ignoreStart -= length; + // fake return values + return length; + } + else + { + std::streamsize cnt = static_cast(length - _ignoreStart - _buffer.size()); + if (cnt > 0) + { + _pOstr->write(buffer+_ignoreStart, cnt); + _bytesWritten += cnt; + } + + // copy the rest into buffer + cnt += static_cast(_ignoreStart); + _ignoreStart = 0; + poco_assert (cnt < length); + _bufferOffset = length - cnt; + std::memcpy(_buffer.begin(), buffer + cnt, _bufferOffset); + + return length; + } + } + if (_buffer.size() > 0) + { + // always treat each write as the potential last one + // thus first fill the buffer with the last n bytes of the msg + + // how much of the already cached data do we need to write? + Poco::Int32 cache = _bufferOffset + length - _buffer.size(); + if (cache > 0) + { + if (cache > _bufferOffset) + cache = _bufferOffset; + _pOstr->write(_buffer.begin(), cache); + _bytesWritten += cache; + _bufferOffset -= cache; + if (_bufferOffset > 0) + std::memmove(_buffer.begin(), _buffer.begin()+cache, _bufferOffset); + } + + // now fill up _buffer with the last bytes from buffer + Poco::Int32 pos = static_cast(length - static_cast(_buffer.size()) + _bufferOffset); + if (pos <= 0) + { + // all of the message goes to _buffer + std::memcpy(_buffer.begin() + _bufferOffset, buffer, length); + } + else + { + poco_assert (_bufferOffset == 0); + std::memcpy(_buffer.begin(), buffer+pos, _buffer.size()); + _bufferOffset = static_cast(_buffer.size()); + // the rest is written + _pOstr->write(buffer, static_cast(length - _buffer.size())); + _bytesWritten += (length - _buffer.size()); + } + } + else + { + _pOstr->write(buffer, length); + _bytesWritten += length; + } + + if (_pOstr->good()) + return length; + + throw Poco::IOException("Failed to write to output stream"); +} + + +void PartialStreamBuf::close() +{ + // DONT write data from _buffer! +} + + +PartialIOS::PartialIOS(std::istream& istr, std::ios::pos_type start, std::ios::pos_type end, const std::string& pre, const std::string& post, bool initStream): _buf(istr, start, end, pre, post, initStream) +{ + poco_ios_init(&_buf); +} + + +PartialIOS::PartialIOS(std::ostream& ostr, std::size_t start, std::size_t end, bool initStream): _buf(ostr, start, end, initStream) +{ + poco_ios_init(&_buf); +} + + +PartialIOS::~PartialIOS() +{ +} + + +PartialStreamBuf* PartialIOS::rdbuf() +{ + return &_buf; +} + + +PartialInputStream::PartialInputStream(std::istream& istr, std::ios::pos_type start, std::ios::pos_type end, bool initStream, const std::string& pre, const std::string& post): + PartialIOS(istr, start, end, pre, post, initStream), + std::istream(&_buf) +{ +} + + +PartialInputStream::~PartialInputStream() +{ +} + + +PartialOutputStream::PartialOutputStream(std::ostream& ostr, std::size_t start, std::size_t end, bool initStream): + PartialIOS(ostr, start, end, initStream), + std::ostream(&_buf) +{ +} + + +PartialOutputStream::~PartialOutputStream() +{ + close(); +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/PartialStream.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/ZipDataInfo.cpp =================================================================== --- Zip/src/ZipDataInfo.cpp (revision 0) +++ Zip/src/ZipDataInfo.cpp (revision 0) @@ -0,0 +1,79 @@ +// +// ZipDataInfo.cpp +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipDataInfo +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/ZipDataInfo.h" +#include +#include + + +namespace Poco { +namespace Zip { + + +const char ZipDataInfo::HEADER[ZipCommon::HEADER_SIZE] = {'\x50', '\x4b', '\x07', '\x08'}; + + +ZipDataInfo::ZipDataInfo(): + _rawInfo(), + _valid(true) +{ + std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE); + std::memset(_rawInfo+ZipCommon::HEADER_SIZE, 0, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE); + _valid = true; +} + + +ZipDataInfo::ZipDataInfo(std::istream& in, bool assumeHeaderRead): + _rawInfo(), + _valid(false) +{ + if (assumeHeaderRead) + std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE); + else + in.read(_rawInfo, ZipCommon::HEADER_SIZE); + poco_assert (std::memcmp(_rawInfo, HEADER, ZipCommon::HEADER_SIZE) == 0); + // now copy the rest of the header + in.read(_rawInfo+ZipCommon::HEADER_SIZE, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE); + _valid = (!in.eof() && in.good()); +} + + +ZipDataInfo::~ZipDataInfo() +{ +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/ZipDataInfo.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/Replace.cpp =================================================================== --- Zip/src/Replace.cpp (revision 0) +++ Zip/src/Replace.cpp (revision 0) @@ -0,0 +1,59 @@ +// +// Replace.cpp +// +// $Id$ +// +// Library: Zip +// Package: Manipulation +// Module: Replace +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/Replace.h" +#include "Poco/Zip/Compress.h" + + +namespace Poco { +namespace Zip { + + +Replace::Replace(const ZipLocalFileHeader& hdr, const std::string& localPath): + _del(hdr), + _add(hdr.getFileName(), localPath, hdr.getCompressionMethod(), hdr.getCompressionLevel()) +{ +} + + +void Replace::execute(Compress& c, std::istream& input) +{ + _del.execute(c, input); + _add.execute(c, input); +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/Replace.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/ZipCommon.cpp =================================================================== --- Zip/src/ZipCommon.cpp (revision 0) +++ Zip/src/ZipCommon.cpp (revision 0) @@ -0,0 +1,47 @@ +// +// ZipCommon.cpp +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipCommon +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/ZipCommon.h" + + +namespace Poco { +namespace Zip { + + +const std::string ZipCommon::ILLEGAL_PATH(".."); + + +} } // namespace Poco::Zip Property changes on: Zip/src/ZipCommon.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/AutoDetectStream.cpp =================================================================== --- Zip/src/AutoDetectStream.cpp (revision 0) +++ Zip/src/AutoDetectStream.cpp (revision 0) @@ -0,0 +1,252 @@ +// +// AutoDetectStream.cpp +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: AutoDetectStream +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/AutoDetectStream.h" +#include "Poco/Zip/ZipLocalFileHeader.h" +#include "Poco/Zip/ZipArchiveInfo.h" +#include "Poco/Zip/ZipDataInfo.h" +#include "Poco/Zip/ZipFileInfo.h" +#include "Poco/Exception.h" +#include + + +namespace Poco { +namespace Zip { + + +AutoDetectStreamBuf::AutoDetectStreamBuf(std::istream& in, const std::string& pre, const std::string& post, bool reposition, Poco::UInt32 start): + Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in), + _pIstr(&in), + _pOstr(0), + _eofDetected(false), + _matchCnt(0), + _prefix(pre), + _postfix(post), + _reposition(reposition), + _start(start) +{ +} + + +AutoDetectStreamBuf::AutoDetectStreamBuf(std::ostream& out): + Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out), + _pIstr(0), + _pOstr(&out), + _eofDetected(false), + _matchCnt(0), + _prefix(), + _postfix(), + _reposition(false), + _start(0u) +{ +} + + +AutoDetectStreamBuf::~AutoDetectStreamBuf() +{ +} + + +int AutoDetectStreamBuf::readFromDevice(char* buffer, std::streamsize length) +{ + poco_assert_dbg(length >= 8); + if (_pIstr == 0 ||length == 0) return -1; + + if (_reposition) + { + _pIstr->seekg(_start, std::ios_base::beg); + _reposition = false; + } + + if (!_prefix.empty()) + { + std::streamsize tmp = (_prefix.size() > length)? length: static_cast(_prefix.size()); + std::memcpy(buffer, _prefix.c_str(), tmp); + _prefix = _prefix.substr(tmp); + return tmp; + } + + if (_eofDetected) + { + if (!_postfix.empty()) + { + std::streamsize tmp = (_postfix.size() > length)? length: static_cast(_postfix.size()); + std::memcpy(buffer, _postfix.c_str(), tmp); + _postfix = _postfix.substr(tmp); + return tmp; + } + else + return -1; + } + + if (!_pIstr->good()) + return -1; + + char byte3('\x00'); + std::streamsize tempPos = 0; + static std::istream::int_type eof = std::istream::traits_type::eof(); + while (_pIstr->good() && !_pIstr->eof() && (tempPos+4) < length) + { + std::istream::int_type c = _pIstr->get(); + if (c != eof) + { + // all zip headers start with the same 2byte prefix + if (_matchCnt<2) + { + if (c == ZipLocalFileHeader::HEADER[_matchCnt]) + ++_matchCnt; + else + { + // matchcnt was either 0 or 1 the headers have all unique chars -> safe to set to 0 + if (_matchCnt == 1) + { + buffer[tempPos++] = ZipLocalFileHeader::HEADER[0]; + } + _matchCnt = 0; + + buffer[tempPos++] = static_cast(c); + } + } + else + { + //the upper 2 bytes differ: the lower one must be in range 1,3,5,7, the upper must be one larger: 2,4,6,8 + if (_matchCnt == 2) + { + if (ZipLocalFileHeader::HEADER[2] == c || + ZipArchiveInfo::HEADER[2] == c || + ZipFileInfo::HEADER[2] == c || + ZipDataInfo::HEADER[2] == c) + { + byte3 = static_cast(c);; + _matchCnt++; + } + else + { + buffer[tempPos++] = ZipLocalFileHeader::HEADER[0]; + buffer[tempPos++] = ZipLocalFileHeader::HEADER[1]; + buffer[tempPos++] = static_cast(c); + _matchCnt = 0; + } + } + else if (_matchCnt == 3) + { + if (c-1 == byte3) + { + // a match, pushback + _pIstr->putback(c); + _pIstr->putback(byte3); + _pIstr->putback(ZipLocalFileHeader::HEADER[1]); + _pIstr->putback(ZipLocalFileHeader::HEADER[0]); + _eofDetected = true; + return tempPos; + } + else + { + buffer[tempPos++] = ZipLocalFileHeader::HEADER[0]; + buffer[tempPos++] = ZipLocalFileHeader::HEADER[1]; + buffer[tempPos++] = byte3; + buffer[tempPos++] = c; + _matchCnt = 0; //the headers have all unique chars -> safe to set to 0 + } + } + } + } + } + + return tempPos; + +} + + +int AutoDetectStreamBuf::writeToDevice(const char* buffer, std::streamsize length) +{ + if (_pOstr == 0 || length == 0) return -1; + _pOstr->write(buffer, length); + if (_pOstr->good()) + return length; + throw Poco::IOException("Failed to write to output stream"); +} + + +AutoDetectIOS::AutoDetectIOS(std::istream& istr, const std::string& pre, const std::string& post, bool reposition, Poco::UInt32 start): + _buf(istr, pre, post, reposition, start) +{ + poco_ios_init(&_buf); +} + + +AutoDetectIOS::AutoDetectIOS(std::ostream& ostr): _buf(ostr) +{ + poco_ios_init(&_buf); +} + + +AutoDetectIOS::~AutoDetectIOS() +{ +} + + +AutoDetectStreamBuf* AutoDetectIOS::rdbuf() +{ + return &_buf; +} + + +AutoDetectInputStream::AutoDetectInputStream(std::istream& istr, const std::string& pre, const std::string& post, bool reposition, Poco::UInt32 start): + AutoDetectIOS(istr, pre, post, reposition, start), + std::istream(&_buf) +{ +} + + +AutoDetectInputStream::~AutoDetectInputStream() +{ +} + + +AutoDetectOutputStream::AutoDetectOutputStream(std::ostream& ostr): + AutoDetectIOS(ostr), + std::ostream(&_buf) +{ +} + + +AutoDetectOutputStream::~AutoDetectOutputStream() +{ +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/AutoDetectStream.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/ZipStream.cpp =================================================================== --- Zip/src/ZipStream.cpp (revision 0) +++ Zip/src/ZipStream.cpp (revision 0) @@ -0,0 +1,318 @@ +// +// ZipStream.cpp +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipStream +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/ZipStream.h" +#include "Poco/zlib.h" +#include "Poco/Zip/ZipArchive.h" +#include "Poco/Zip/AutoDetectStream.h" +#include "Poco/Zip/PartialStream.h" +#include "Poco/Zip/ZipDataInfo.h" +#include "Poco/Zip/ZipException.h" +#include "Poco/Exception.h" +#include "Poco/InflatingStream.h" +#include "Poco/DeflatingStream.h" + + +namespace Poco { +namespace Zip { + + +ZipStreamBuf::ZipStreamBuf(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition): + Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in), + _pIstr(&istr), + _pOstr(0), + _ptrBuf(), + _ptrOBuf(), + _ptrHelper(), + _ptrOHelper(), + _crc32(Poco::Checksum::TYPE_CRC32), + _expectedCrc32(0), + _checkCRC(true), + _bytesWritten(0), + _pHeader(0) +{ + if (fileEntry.isDirectory()) + return; + _expectedCrc32 = fileEntry.getCRC(); + std::streamoff start = fileEntry.getDataStartPos(); + std::streamoff end = fileEntry.getDataEndPos(); + _checkCRC = !fileEntry.searchCRCAndSizesAfterData(); + if (fileEntry.getCompressionMethod() == ZipCommon::CM_DEFLATE) + { + // Fake init bytes at beginning of stream + std::string init = ZipUtil::fakeZLibInitString(fileEntry.getCompressionLevel()); + + // Fake adler at end of stream: just some dummy value, not checked anway + std::string crc(4, ' '); + if (fileEntry.searchCRCAndSizesAfterData()) + { + _ptrHelper = new AutoDetectInputStream(istr, init, crc, reposition, start); + } + else + _ptrHelper = new PartialInputStream(istr, start, end, reposition, init, crc); + _ptrBuf = new Poco::InflatingInputStream(*_ptrHelper, Poco::InflatingStreamBuf::STREAM_ZIP); + } + else if (fileEntry.getCompressionMethod() == ZipCommon::CM_STORE) + { + if (fileEntry.searchCRCAndSizesAfterData()) + { + _ptrBuf = new AutoDetectInputStream(istr, "", "", reposition, start); + } + else + _ptrBuf = new PartialInputStream(istr, start, end, reposition); + } + else + { + throw Poco::NotImplementedException("Unsupported compression method"); + } +} + + +ZipStreamBuf::ZipStreamBuf(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool reposition): + Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out), + _pIstr(0), + _pOstr(&ostr), + _ptrBuf(), + _ptrOBuf(), + _ptrHelper(), + _ptrOHelper(), + _crc32(Poco::Checksum::TYPE_CRC32), + _expectedCrc32(0), + _checkCRC(false), + _bytesWritten(0), + _pHeader(&fileEntry) +{ + if (fileEntry.isEncrypted()) + throw Poco::NotImplementedException("Encryption not supported"); + + if (fileEntry.isDirectory()) + { + // only header, no payload, zero crc + fileEntry.setSearchCRCAndSizesAfterData(false); + fileEntry.setCompressedSize(0); + fileEntry.setUncompressedSize(0); + fileEntry.setCRC(0); + std::string header = fileEntry.createHeader(); + ostr.write(header.c_str(), static_cast(header.size())); + } + else + { + fileEntry.setSearchCRCAndSizesAfterData(!reposition); + if (fileEntry.getCompressionMethod() == ZipCommon::CM_DEFLATE) + { + int level = Z_DEFAULT_COMPRESSION; + if (fileEntry.getCompressionLevel() == ZipCommon::CL_FAST || fileEntry.getCompressionLevel() == ZipCommon::CL_SUPERFAST) + level = Z_BEST_SPEED; + else if (fileEntry.getCompressionLevel() == ZipCommon::CL_MAXIMUM) + level = Z_BEST_COMPRESSION; + // ignore the zlib init string which is of size 2 and also ignore the 4 byte adler32 value at the end of the stream! + _ptrOHelper = new PartialOutputStream(*_pOstr, 2, 4, false); + _ptrOBuf = new Poco::DeflatingOutputStream(*_ptrOHelper, DeflatingStreamBuf::STREAM_ZLIB, level); + } + else if (fileEntry.getCompressionMethod() == ZipCommon::CM_STORE) + { + _ptrOBuf = &ostr; + } + else + { + throw Poco::NotImplementedException("Unsupported compression method"); + } + // now write the header to the ostr! + std::string header = fileEntry.createHeader(); + ostr.write(header.c_str(), static_cast(header.size())); + } +} + + +ZipStreamBuf::~ZipStreamBuf() +{ +} + + +int ZipStreamBuf::readFromDevice(char* buffer, std::streamsize length) +{ + if (!_ptrBuf) return 0; // directory entry + _ptrBuf->read(buffer, length); + int cnt = _ptrBuf->gcount(); + if (cnt > 0) + { + _crc32.update(buffer, cnt); + } + else + { + if (_crc32.checksum() != _expectedCrc32) + { + if (_checkCRC) + throw ZipException("CRC failure"); + else + { + // the CRC value is written directly after the data block + // parse it directly from the input stream + ZipDataInfo nfo(*_pIstr, false); + // now push back the header to the stream, so that the ZipLocalFileHeader can read it + Poco::Int32 size = static_cast(nfo.getFullHeaderSize()); + _expectedCrc32 = nfo.getCRC32(); + const char* rawHeader = nfo.getRawHeader(); + for (Poco::Int32 i = size-1; i >= 0; --i) + _pIstr->putback(rawHeader[i]); + if (!crcValid()) + throw ZipException("CRC failure"); + } + } + } + return cnt; +} + + +int ZipStreamBuf::writeToDevice(const char* buffer, std::streamsize length) +{ + if (!_ptrOBuf) return 0; // directory entry + if (length == 0) + return 0; + _bytesWritten += length; + _ptrOBuf->write(buffer, length); + _crc32.update(buffer, length); + return length; +} + + +void ZipStreamBuf::close() +{ + if (_ptrOBuf && _pHeader) + { + _ptrOBuf->flush(); + DeflatingOutputStream* pDO = dynamic_cast(_ptrOBuf.get()); + if (pDO) + pDO->close(); + if (_ptrOHelper) + { + _ptrOHelper->flush(); + _ptrOHelper->close(); + } + _ptrOBuf = 0; + poco_assert (*_pOstr); + // write an extra datablock if required + // or fix the crc entries + if (_pHeader->searchCRCAndSizesAfterData()) + { + ZipDataInfo info; + info.setCRC32(_crc32.checksum()); + info.setUncompressedSize(_bytesWritten); + info.setCompressedSize(static_cast(_ptrOHelper->bytesWritten())); + _pOstr->write(info.getRawHeader(), static_cast(info.getFullHeaderSize())); + } + else + { + poco_check_ptr (_pHeader); + _pHeader->setCRC(_crc32.checksum()); + _pHeader->setUncompressedSize(_bytesWritten); + _pHeader->setCompressedSize(static_cast(_ptrOHelper->bytesWritten())); + _pOstr->seekp(_pHeader->getStartPos(), std::ios_base::beg); + poco_assert (*_pOstr); + std::string header = _pHeader->createHeader(); + _pOstr->write(header.c_str(), static_cast(header.size())); + _pOstr->seekp(0, std::ios_base::end); + poco_assert (*_pOstr); + } + _pHeader = 0; + } +} + + +bool ZipStreamBuf::crcValid() const +{ + if (!_ptrBuf) return true; // directory entry + return _crc32.checksum() == _expectedCrc32; +} + + +ZipIOS::ZipIOS(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition): _buf(istr, fileEntry, reposition) +{ + poco_ios_init(&_buf); +} + + +ZipIOS::ZipIOS(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool reposition): _buf(ostr, fileEntry, reposition) +{ + poco_ios_init(&_buf); +} + + +ZipIOS::~ZipIOS() +{ +} + + +ZipStreamBuf* ZipIOS::rdbuf() +{ + return &_buf; +} + + +ZipInputStream::ZipInputStream(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition): ZipIOS(istr, fileEntry, reposition), std::istream(&_buf) +{ +} + + +ZipInputStream::~ZipInputStream() +{ +} + + +bool ZipInputStream::crcValid() const +{ + return _buf.crcValid(); +} + + +ZipOutputStream::ZipOutputStream(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool seekableOutput): ZipIOS(ostr, fileEntry, seekableOutput), std::ostream(&_buf) +{ +} + + +ZipOutputStream::~ZipOutputStream() +{ +} + + +void ZipOutputStream::close() +{ + flush(); + _buf.close(); +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/ZipStream.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/ZipManipulator.cpp =================================================================== --- Zip/src/ZipManipulator.cpp (revision 0) +++ Zip/src/ZipManipulator.cpp (revision 0) @@ -0,0 +1,194 @@ +// +// ZipManipulator.cpp +// +// $Id$ +// +// Library: Zip +// Package: Manipulation +// Module: ZipManipulator +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/ZipManipulator.h" +#include "Poco/Zip/ZipException.h" +#include "Poco/Zip/ZipUtil.h" +#include "Poco/Zip/Add.h" +#include "Poco/Zip/Delete.h" +#include "Poco/Zip/Keep.h" +#include "Poco/Zip/Rename.h" +#include "Poco/Zip/Replace.h" +#include "Poco/Zip/Compress.h" +#include "Poco/Delegate.h" +#include "Poco/File.h" +#include "Poco/FileStream.h" +#include + + +namespace Poco { +namespace Zip { + + +ZipManipulator::ZipManipulator(const std::string& zipFile, bool backupOriginalFile): + _zipFile(zipFile), + _backupOriginalFile(backupOriginalFile), + _changes(), + _in(0) +{ + std::ifstream in(zipFile.c_str(), std::ios::binary); + _in = new ZipArchive(in); +} + + +ZipManipulator::~ZipManipulator() +{ +} + + +void ZipManipulator::deleteFile(const std::string& zipPath) +{ + const ZipLocalFileHeader& entry = getForChange(zipPath); + addOperation(zipPath, new Delete(entry)); +} + + +void ZipManipulator::replaceFile(const std::string& zipPath, const std::string& localPath) +{ + const ZipLocalFileHeader& entry = getForChange(zipPath); + addOperation(zipPath, new Replace(entry, localPath)); +} + + +void ZipManipulator::renameFile(const std::string& zipPath, const std::string& newZipPath) +{ + const ZipLocalFileHeader& entry = getForChange(zipPath); + // checked later in Compress too but the earlier one gets the error the better + std::string fn = ZipUtil::validZipEntryFileName(newZipPath); + addOperation(zipPath, new Rename(entry, fn)); +} + + +void ZipManipulator::addFile(const std::string& zipPath, const std::string& localPath, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl) +{ + addOperation(zipPath, new Add(zipPath, localPath, cm, cl)); +} + + +ZipArchive ZipManipulator::commit() +{ + // write to a tmp file + std::string outFile(_zipFile + ".tmp"); + ZipArchive retVal(compress(outFile)); + //renaming + { + Poco::File aFile(_zipFile); + if (_backupOriginalFile) + { + Poco::File tmp(_zipFile+".bak"); + if (tmp.exists()) + tmp.remove(); + aFile.renameTo(_zipFile+".bak"); + } + else + aFile.remove(); + } + + { + Poco::File resFile(outFile); + Poco::File zipFile(_zipFile); + if (zipFile.exists()) + zipFile.remove(); + resFile.renameTo(_zipFile); + } + return retVal; +} + + +const ZipLocalFileHeader& ZipManipulator::getForChange(const std::string& zipPath) const +{ + ZipArchive::FileHeaders::const_iterator it = _in->findHeader(zipPath); + if (it == _in->headerEnd()) + throw ZipManipulationException("entry not found: " + zipPath); + + if (_changes.find(zipPath) != _changes.end()) + throw ZipManipulationException("A change request exists already for entry " + zipPath); + + return it->second; +} + + +void ZipManipulator::addOperation(const std::string& zipPath, ZipOperation::Ptr ptrOp) +{ + std::pair result = _changes.insert(std::make_pair(zipPath, ptrOp)); + if (!result.second) + throw ZipManipulationException("A change request exists already for entry " + zipPath); +} + + +void ZipManipulator::onEDone(const void*, const ZipLocalFileHeader& hdr) +{ + EDone(this, hdr); +} + + +ZipArchive ZipManipulator::compress(const std::string& outFile) +{ + // write to a tmp file + Poco::FileInputStream in(_zipFile); + Poco::FileOutputStream out(outFile); + Compress c(out, true); + c.EDone += Poco::Delegate(this, &ZipManipulator::onEDone); + + ZipArchive::FileHeaders::const_iterator it = _in->headerBegin(); + for (; it != _in->headerEnd(); ++it) + { + Changes::iterator itC = _changes.find(it->first); + if (itC != _changes.end()) + { + itC->second->execute(c, in); + _changes.erase(itC); + } + else + { + Keep k(it->second); + k.execute(c, in); + } + } + //Remaining files are add operations! + Changes::iterator itC = _changes.begin(); + for (; itC != _changes.end(); ++itC) + { + itC->second->execute(c, in); + } + _changes.clear(); + c.EDone -= Poco::Delegate(this, &ZipManipulator::onEDone); + in.close(); + return c.close(); +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/ZipManipulator.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/ZipFileInfo.cpp =================================================================== --- Zip/src/ZipFileInfo.cpp (revision 0) +++ Zip/src/ZipFileInfo.cpp (revision 0) @@ -0,0 +1,159 @@ +// +// ZipFileInfo.cpp +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipFileInfo +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/ZipFileInfo.h" +#include "Poco/Zip/ZipLocalFileHeader.h" +#include "Poco/Buffer.h" +#include +#include + + +namespace Poco { +namespace Zip { + + +const char ZipFileInfo::HEADER[ZipCommon::HEADER_SIZE] = {'\x50', '\x4b', '\x01', '\x02'}; + + +ZipFileInfo::ZipFileInfo(const ZipLocalFileHeader& header): + _rawInfo(), + _crc32(0), + _compressedSize(0), + _uncompressedSize(0), + _fileName(), + _lastModifiedAt(), + _extraField() +{ + std::memset(_rawInfo, 0, FULLHEADER_SIZE); + std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE); + setCompressedSize(header.getCompressedSize()); + setUncompressedSize(header.getUncompressedSize()); + setCRC(header.getCRC()); + setCompressionMethod(header.getCompressionMethod()); + setCompressionLevel(header.getCompressionLevel()); + setRequiredVersion(header.getMajorVersionNumber(), header.getMinorVersionNumber()); + setHostSystem(header.getHostSystem()); + setLastModifiedAt(header.lastModifiedAt()); + setEncryption(false); + setFileName(header.getFileName()); + + if (getHostSystem() == ZipCommon::HS_UNIX) + setUnixAttributes(); +} + + +ZipFileInfo::ZipFileInfo(std::istream& in, bool assumeHeaderRead): + _rawInfo(), + _crc32(0), + _compressedSize(0), + _uncompressedSize(0), + _fileName(), + _lastModifiedAt(), + _extraField() +{ + // sanity check + poco_assert_dbg (RELATIVEOFFSETLOCALHEADER_POS + RELATIVEOFFSETLOCALHEADER_SIZE == FULLHEADER_SIZE); + parse(in, assumeHeaderRead); +} + + +ZipFileInfo::~ZipFileInfo() +{ +} + + +void ZipFileInfo::parse(std::istream& inp, bool assumeHeaderRead) +{ + if (!assumeHeaderRead) + { + inp.read(_rawInfo, ZipCommon::HEADER_SIZE); + } + else + { + std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE); + } + poco_assert (std::memcmp(_rawInfo, HEADER, ZipCommon::HEADER_SIZE) == 0); + // read the rest of the header + inp.read(_rawInfo + ZipCommon::HEADER_SIZE, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE); + _crc32 = getCRCFromHeader(); + _compressedSize = getCompressedSizeFromHeader(); + _uncompressedSize = getUncompressedSizeFromHeader(); + parseDateTime(); + Poco::UInt16 len = getFileNameLength(); + Poco::Buffer buf(len); + inp.read(buf.begin(), len); + _fileName = std::string(buf.begin(), len); + if (hasExtraField()) + { + len = getExtraFieldLength(); + Poco::Buffer xtra(len); + inp.read(xtra.begin(), len); + _extraField = std::string(xtra.begin(), len); + } + len = getFileCommentLength(); + if (len > 0) + { + Poco::Buffer buf2(len); + inp.read(buf2.begin(), len); + _fileComment = std::string(buf2.begin(), len); + } +} + + +std::string ZipFileInfo::createHeader() const +{ + std::string result(_rawInfo, FULLHEADER_SIZE); + result.append(_fileName); + result.append(_extraField); + result.append(_fileComment); + return result; +} + + +void ZipFileInfo::setUnixAttributes() +{ + bool isDir = isDirectory(); + int mode; + if (isDir) + mode = DEFAULT_UNIX_DIR_MODE; + else + mode = DEFAULT_UNIX_FILE_MODE; + Poco::UInt32 attrs = (mode << 16) | (isDir ? 0x10 : 0); + setExternalFileAttributes(attrs); +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/ZipFileInfo.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/ZipArchiveInfo.cpp =================================================================== --- Zip/src/ZipArchiveInfo.cpp (revision 0) +++ Zip/src/ZipArchiveInfo.cpp (revision 0) @@ -0,0 +1,106 @@ +// +// ZipArchiveInfo.cpp +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipArchiveInfo +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/ZipArchiveInfo.h" +#include "Poco/Buffer.h" +#include +#include + + +namespace Poco { +namespace Zip { + + +const char ZipArchiveInfo::HEADER[ZipCommon::HEADER_SIZE] = {'\x50', '\x4b', '\x05', '\x06'}; + + +ZipArchiveInfo::ZipArchiveInfo(std::istream& in, bool assumeHeaderRead): + _rawInfo(), + _startPos(in.tellg()), + _comment() +{ + if (assumeHeaderRead) + _startPos -= ZipCommon::HEADER_SIZE; + parse(in, assumeHeaderRead); +} + +ZipArchiveInfo::ZipArchiveInfo(): + _rawInfo(), + _startPos(0), + _comment() +{ + std::memset(_rawInfo, 0, FULLHEADER_SIZE); + std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE); +} + + +ZipArchiveInfo::~ZipArchiveInfo() +{ +} + + +void ZipArchiveInfo::parse(std::istream& inp, bool assumeHeaderRead) +{ + if (!assumeHeaderRead) + { + inp.read(_rawInfo, ZipCommon::HEADER_SIZE); + } + else + { + std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE); + } + poco_assert (std::memcmp(_rawInfo, HEADER, ZipCommon::HEADER_SIZE) == 0); + // read the rest of the header + inp.read(_rawInfo + ZipCommon::HEADER_SIZE, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE); + Poco::UInt16 len = getZipCommentSize(); + if (len > 0) + { + Poco::Buffer buf(len); + inp.read(buf.begin(), len); + _comment = std::string(buf.begin(), len); + } +} + + +std::string ZipArchiveInfo::createHeader() const +{ + std::string result(_rawInfo, FULLHEADER_SIZE); + result.append(_comment); + return result; +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/ZipArchiveInfo.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/ZipException.cpp =================================================================== --- Zip/src/ZipException.cpp (revision 0) +++ Zip/src/ZipException.cpp (revision 0) @@ -0,0 +1,49 @@ +// +// ZipException.cpp +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipException +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/ZipException.h" +#include + + +namespace Poco { +namespace Zip { + + +POCO_IMPLEMENT_EXCEPTION(ZipException, Poco::RuntimeException, "ZIP Exception") +POCO_IMPLEMENT_EXCEPTION(ZipManipulationException, ZipException, "ZIP Manipulation Exception") + + +} } // namespace Poco::Zip Property changes on: Zip/src/ZipException.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/SkipCallback.cpp =================================================================== --- Zip/src/SkipCallback.cpp (revision 0) +++ Zip/src/SkipCallback.cpp (revision 0) @@ -0,0 +1,66 @@ +// +// SkipCallback.cpp +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: SkipCallback +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/SkipCallback.h" +#include "Poco/Zip/ZipLocalFileHeader.h" +#include "Poco/Zip/ZipUtil.h" + + +namespace Poco { +namespace Zip { + + +SkipCallback::SkipCallback() +{ +} + + +SkipCallback::~SkipCallback() +{ +} + + +bool SkipCallback::handleZipEntry(std::istream& zipStream, const ZipLocalFileHeader& hdr) +{ + if (!hdr.searchCRCAndSizesAfterData()) + zipStream.seekg(hdr.getCompressedSize(), std::ios_base::cur); + else + ZipUtil::sync(zipStream); + return true; +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/SkipCallback.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/ZipOperation.cpp =================================================================== --- Zip/src/ZipOperation.cpp (revision 0) +++ Zip/src/ZipOperation.cpp (revision 0) @@ -0,0 +1,54 @@ +// +// ZipOperation.cpp +// +// $Id$ +// +// Library: Zip +// Package: Manipulation +// Module: ZipOperation +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/ZipOperation.h" + + +namespace Poco { +namespace Zip { + + +ZipOperation::ZipOperation() +{ +} + + +ZipOperation::~ZipOperation() +{ +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/ZipOperation.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/Keep.cpp =================================================================== --- Zip/src/Keep.cpp (revision 0) +++ Zip/src/Keep.cpp (revision 0) @@ -0,0 +1,59 @@ +// +// Keep.cpp +// +// $Id$ +// +// Library: Zip +// Package: Manipulation +// Module: Keep +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/Keep.h" +#include "Poco/Zip/Compress.h" +#include "Poco/Buffer.h" +#include "Poco/StreamCopier.h" + + +namespace Poco { +namespace Zip { + + +Keep::Keep(const ZipLocalFileHeader& hdr): + _hdr(hdr) +{ +} + + +void Keep::execute(Compress& c, std::istream& input) +{ + c.addFileRaw(input, _hdr, _hdr.getFileName()); +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/Keep.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/ZipLocalFileHeader.cpp =================================================================== --- Zip/src/ZipLocalFileHeader.cpp (revision 0) +++ Zip/src/ZipLocalFileHeader.cpp (revision 0) @@ -0,0 +1,238 @@ +// +// ZipLocalFileHeader.cpp +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ZipLocalFileHeader +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/ZipLocalFileHeader.h" +#include "Poco/Zip/ZipDataInfo.h" +#include "Poco/Zip/ParseCallback.h" +#include "Poco/Buffer.h" +#include "Poco/Exception.h" +#include "Poco/File.h" +#include + + +namespace Poco { +namespace Zip { + + +const char ZipLocalFileHeader::HEADER[ZipCommon::HEADER_SIZE] = {'\x50', '\x4b', '\x03', '\x04'}; + + +ZipLocalFileHeader::ZipLocalFileHeader(const Poco::Path& fileName, + const Poco::DateTime& lastModifiedAt, + ZipCommon::CompressionMethod cm, + ZipCommon::CompressionLevel cl): + _rawHeader(), + _startPos(-1), + _endPos(-1), + _fileName(), + _lastModifiedAt(), + _extraField(), + _crc32(0), + _compressedSize(0), + _uncompressedSize(0) +{ + std::memcpy(_rawHeader, HEADER, ZipCommon::HEADER_SIZE); + std::memset(_rawHeader+ZipCommon::HEADER_SIZE, 0, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE); + ZipCommon::HostSystem hs = ZipCommon::HS_FAT; + +#if (POCO_OS == POCO_OS_CYGWIN) + hs = ZipCommon::HS_UNIX; +#endif +#if (POCO_OS == POCO_OS_VMS) + hs = ZipCommon::HS_VMS; +#endif +#if defined(POCO_OS_FAMILY_UNIX) + hs = ZipCommon::HS_UNIX; +#endif + setHostSystem(hs); + setEncryption(false); + setExtraFieldSize(0); + setLastModifiedAt(lastModifiedAt); + init(fileName, cm, cl); +} + + +ZipLocalFileHeader::ZipLocalFileHeader(std::istream& inp, bool assumeHeaderRead, ParseCallback& callback): + _rawHeader(), + _startPos(inp.tellg()), + _endPos(-1), + _fileName(), + _lastModifiedAt(), + _extraField(), + _crc32(0), + _compressedSize(0), + _uncompressedSize(0) +{ + poco_assert_dbg( (EXTRAFIELD_POS+EXTRAFIELD_LENGTH) == FULLHEADER_SIZE); + + if (assumeHeaderRead) + _startPos -= ZipCommon::HEADER_SIZE; + + parse(inp, assumeHeaderRead); + + bool ok = callback.handleZipEntry(inp, *this); + + if (ok) + { + if (searchCRCAndSizesAfterData()) + { + ZipDataInfo nfo(inp, false); + setCRC(nfo.getCRC32()); + setCompressedSize(nfo.getCompressedSize()); + setUncompressedSize(nfo.getUncompressedSize()); + } + } + else + { + poco_assert_dbg(!searchCRCAndSizesAfterData()); + ZipUtil::sync(inp); + } + _endPos = _startPos + getHeaderSize() + _compressedSize; // exclude the data block! +} + + +ZipLocalFileHeader::~ZipLocalFileHeader() +{ +} + + +void ZipLocalFileHeader::parse(std::istream& inp, bool assumeHeaderRead) +{ + if (!assumeHeaderRead) + { + inp.read(_rawHeader, ZipCommon::HEADER_SIZE); + } + else + { + std::memcpy(_rawHeader, HEADER, ZipCommon::HEADER_SIZE); + } + poco_assert (std::memcmp(_rawHeader, HEADER, ZipCommon::HEADER_SIZE) == 0); + // read the rest of the header + inp.read(_rawHeader + ZipCommon::HEADER_SIZE, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE); + poco_assert (_rawHeader[VERSION_POS + 1]>= ZipCommon::HS_FAT && _rawHeader[VERSION_POS + 1] < ZipCommon::HS_UNUSED); + poco_assert (getMajorVersionNumber() <= 2); + poco_assert (ZipUtil::get16BitValue(_rawHeader, COMPR_METHOD_POS) < ZipCommon::CM_UNUSED); + parseDateTime(); + Poco::UInt16 len = getFileNameLength(); + Poco::Buffer buf(len); + inp.read(buf.begin(), len); + _fileName = std::string(buf.begin(), len); + if (hasExtraField()) + { + len = getExtraFieldLength(); + Poco::Buffer xtra(len); + inp.read(xtra.begin(), len); + _extraField = std::string(xtra.begin(), len); + } + if (!searchCRCAndSizesAfterData()) + { + _crc32 = getCRCFromHeader(); + _compressedSize = getCompressedSizeFromHeader(); + _uncompressedSize = getUncompressedSizeFromHeader(); + } +} + + +bool ZipLocalFileHeader::searchCRCAndSizesAfterData() const +{ + if (getCompressionMethod() == ZipCommon::CM_DEFLATE) + { + // check bit 3 + return ((ZipUtil::get16BitValue(_rawHeader, GENERAL_PURPOSE_POS) & 0x0008) != 0); + } + return false; +} + + +void ZipLocalFileHeader::setFileName(const std::string& fileName, bool isDirectory) +{ + poco_assert (!fileName.empty()); + Poco::Path aPath(fileName); + + if (isDirectory) + { + aPath.makeDirectory(); + setCRC(0); + setCompressedSize(0); + setUncompressedSize(0); + setCompressionMethod(ZipCommon::CM_STORE); + setCompressionLevel(ZipCommon::CL_NORMAL); + } + else + { + aPath.makeFile(); + } + _fileName = aPath.toString(Poco::Path::PATH_UNIX); + if (_fileName[0] == '/') + _fileName = _fileName.substr(1); + if (isDirectory) + { + poco_assert_dbg (_fileName[_fileName.size()-1] == '/'); + } + setFileNameLength(static_cast(_fileName.size())); +} + + +void ZipLocalFileHeader::init( const Poco::Path& fName, + ZipCommon::CompressionMethod cm, + ZipCommon::CompressionLevel cl) +{ + poco_assert (_fileName.empty()); + setSearchCRCAndSizesAfterData(false); + Poco::Path fileName(fName); + fileName.setDevice(""); // clear device! + setFileName(fileName.toString(Poco::Path::PATH_UNIX), fileName.isDirectory()); + setRequiredVersion(2, 0); + if (fileName.isFile()) + { + setCompressionMethod(cm); + setCompressionLevel(cl); + } + else + setCompressionMethod(ZipCommon::CM_STORE); +} + + +std::string ZipLocalFileHeader::createHeader() const +{ + std::string result(_rawHeader, FULLHEADER_SIZE); + result.append(_fileName); + result.append(_extraField); + return result; +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/ZipLocalFileHeader.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/ParseCallback.cpp =================================================================== --- Zip/src/ParseCallback.cpp (revision 0) +++ Zip/src/ParseCallback.cpp (revision 0) @@ -0,0 +1,54 @@ +// +// ParseCallback.cpp +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: ParseCallback +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/ParseCallback.h" + + +namespace Poco { +namespace Zip { + + +ParseCallback::ParseCallback() +{ +} + + +ParseCallback::~ParseCallback() +{ +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/ParseCallback.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/Add.cpp =================================================================== --- Zip/src/Add.cpp (revision 0) +++ Zip/src/Add.cpp (revision 0) @@ -0,0 +1,60 @@ +// +// Add.cpp +// +// $Id$ +// +// Library: Zip +// Package: Manipulation +// Module: Add +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/Add.h" +#include "Poco/Zip/Compress.h" + + +namespace Poco { +namespace Zip { + + +Add::Add(const std::string& zipPath, const std::string& localPath, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl): + _zipPath(zipPath), + _localPath(localPath), + _cm(cm), + _cl(cl) +{ +} + + +void Add::execute(Compress& c, std::istream& input) +{ + c.addFile(Poco::Path(_localPath), Poco::Path(_zipPath), _cm, _cl); +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/Add.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/src/Compress.cpp =================================================================== --- Zip/src/Compress.cpp (revision 0) +++ Zip/src/Compress.cpp (revision 0) @@ -0,0 +1,315 @@ +// +// Compress.cpp +// +// $Id$ +// +// Library: Zip +// Package: Zip +// Module: Compress +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Zip/Compress.h" +#include "Poco/Zip/ZipLocalFileHeader.h" +#include "Poco/Zip/ZipStream.h" +#include "Poco/Zip/ZipArchiveInfo.h" +#include "Poco/Zip/ZipDataInfo.h" +#include "Poco/Zip/ZipException.h" +#include "Poco/StreamCopier.h" +#include "Poco/File.h" +#include + + +namespace Poco { +namespace Zip { + + +Compress::Compress(std::ostream& out, bool seekableOut): + _out(out), + _seekableOut(seekableOut), + _files(), + _infos(), + _dirs(), + _offset(0) +{ +} + + +Compress::~Compress() +{ +} + + +void Compress::addEntry(std::istream& in, const Poco::DateTime& lastModifiedAt, const Poco::Path& fileName, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl) +{ + std::string fn = ZipUtil::validZipEntryFileName(fileName); + + if (_files.size() >= 65535) + throw ZipException("Maximum number of entries for a ZIP file reached: 65535"); + if (!in.good()) + throw ZipException("Invalid input stream"); + + std::streamoff localHeaderOffset = _offset; + ZipLocalFileHeader hdr(fileName, lastModifiedAt, cm, cl); + hdr.setStartPos(localHeaderOffset); + + ZipOutputStream zipOut(_out, hdr, _seekableOut); + Poco::StreamCopier::copyStream(in, zipOut); + zipOut.close(); + hdr.setStartPos(localHeaderOffset); // reset again now that compressed Size is known + _offset = hdr.getEndPos(); + if (hdr.searchCRCAndSizesAfterData()) + _offset += ZipDataInfo::getFullHeaderSize(); + _files.insert(std::make_pair(fileName.toString(Poco::Path::PATH_UNIX), hdr)); + poco_assert (_out); + ZipFileInfo nfo(hdr); + nfo.setOffset(localHeaderOffset); + _infos.insert(std::make_pair(fileName.toString(Poco::Path::PATH_UNIX), nfo)); + EDone.notify(this, hdr); +} + + +void Compress::addFileRaw(std::istream& in, const ZipLocalFileHeader& h, const Poco::Path& fileName) +{ + std::string fn = ZipUtil::validZipEntryFileName(fileName); + //bypass the header of the input stream and point to the first byte of the data payload + in.seekg(h.getDataStartPos(), std::ios_base::beg); + + if (_files.size() >= 65535) + throw ZipException("Maximum number of entries for a ZIP file reached: 65535"); + if (!in.good()) + throw ZipException("Invalid input stream"); + + std::streamoff localHeaderOffset = _offset; + ZipLocalFileHeader hdr(h); + hdr.setFileName(fn, h.isDirectory()); + hdr.setStartPos(localHeaderOffset); + //bypass zipoutputstream + //write the header directly + std::string header = hdr.createHeader(); + _out.write(header.c_str(), static_cast(header.size())); + // now fwd the payload to _out in chunks of size CHUNKSIZE + Poco::UInt32 totalSize = hdr.getCompressedSize(); + if (totalSize > 0) + { + Poco::Buffer buffer(COMPRESS_CHUNK_SIZE); + Poco::UInt32 remaining = totalSize; + while(remaining > 0) + { + if (remaining > COMPRESS_CHUNK_SIZE) + { + in.read(buffer.begin(), COMPRESS_CHUNK_SIZE); + std::streamsize n = in.gcount(); + poco_assert_dbg (n == COMPRESS_CHUNK_SIZE); + _out.write(buffer.begin(), n); + remaining -= COMPRESS_CHUNK_SIZE; + } + else + { + in.read(buffer.begin(), remaining); + std::streamsize n = in.gcount(); + poco_assert_dbg (n == remaining); + _out.write(buffer.begin(), n); + remaining = 0; + } + } + } + //write optional block afterwards + if (hdr.searchCRCAndSizesAfterData()) + { + ZipDataInfo info(in, false); + _out.write(info.getRawHeader(), static_cast(info.getFullHeaderSize())); + } + hdr.setStartPos(localHeaderOffset); // reset again now that compressed Size is known + _offset = hdr.getEndPos(); + if (hdr.searchCRCAndSizesAfterData()) + _offset += ZipDataInfo::getFullHeaderSize(); + _files.insert(std::make_pair(fileName.toString(Poco::Path::PATH_UNIX), hdr)); + poco_assert (_out); + ZipFileInfo nfo(hdr); + nfo.setOffset(localHeaderOffset); + _infos.insert(std::make_pair(fileName.toString(Poco::Path::PATH_UNIX), nfo)); + EDone.notify(this, hdr); +} + + +void Compress::addFile(std::istream& in, const Poco::DateTime& lastModifiedAt, const Poco::Path& fileName, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl) +{ + if (!fileName.isFile()) + throw ZipException("Not a file: "+ fileName.toString()); + + if (fileName.depth() > 1) + { + addDirectory(fileName.parent(), lastModifiedAt); + } + addEntry(in, lastModifiedAt, fileName, cm, cl); +} + + +void Compress::addFile(const Poco::Path& file, const Poco::Path& fileName, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl) +{ + Poco::File aFile(file); + std::ifstream in(file.toString().c_str(), std::ios::binary); + if (!in.good()) + throw ZipException("Invalid input stream for " + aFile.path()); + if (fileName.depth() > 1) + { + Poco::File aParent(file.parent()); + addDirectory(fileName.parent(), aParent.getLastModified()); + } + addFile(in, aFile.getLastModified(), fileName, cm, cl); +} + + +void Compress::addDirectory(const Poco::Path& entryName, const Poco::DateTime& lastModifiedAt) +{ + if (!entryName.isDirectory()) + throw ZipException("Not a directory: "+ entryName.toString()); + + std::string fileStr = entryName.toString(Poco::Path::PATH_UNIX); + if (_files.find(fileStr) != _files.end()) + return; // ignore duplicate add + if (_files.size() >= 65535) + throw ZipException("Maximum number of entries for a ZIP file reached: 65535"); + if (fileStr == "/") + throw ZipException("Illegal entry name /"); + if (fileStr.empty()) + throw ZipException("Illegal empty entry name"); + if (fileStr.find(ZipCommon::ILLEGAL_PATH) != std::string::npos) + throw ZipException("Illegal entry name " + fileStr + " containing " + ZipCommon::ILLEGAL_PATH); + + if (entryName.depth() > 1) + { + addDirectory(entryName.parent(), lastModifiedAt); + } + + std::streamoff localHeaderOffset = _offset; + ZipCommon::CompressionMethod cm = ZipCommon::CM_STORE; + ZipCommon::CompressionLevel cl = ZipCommon::CL_NORMAL; + ZipLocalFileHeader hdr(entryName, lastModifiedAt, cm, cl); + hdr.setStartPos(localHeaderOffset); + ZipOutputStream zipOut(_out, hdr, _seekableOut); + zipOut.close(); + hdr.setStartPos(localHeaderOffset); // reset again now that compressed Size is known + _offset = hdr.getEndPos(); + if (hdr.searchCRCAndSizesAfterData()) + _offset += ZipDataInfo::getFullHeaderSize(); + _files.insert(std::make_pair(entryName.toString(Poco::Path::PATH_UNIX), hdr)); + poco_assert (_out); + ZipFileInfo nfo(hdr); + nfo.setOffset(localHeaderOffset); + _infos.insert(std::make_pair(entryName.toString(Poco::Path::PATH_UNIX), nfo)); + EDone.notify(this, hdr); +} + + +void Compress::addRecursive(const Poco::Path& entry, ZipCommon::CompressionLevel cl, bool excludeRoot, const Poco::Path& name) +{ + Poco::File aFile(entry); + if (!aFile.isDirectory()) + throw ZipException("Not a directory: "+ entry.toString()); + Poco::Path aName(name); + aName.makeDirectory(); + if (!excludeRoot) + { + if (aName.depth() == 0) + { + Poco::Path tmp(entry); + tmp.makeAbsolute(); // eliminate ../ + aName = Poco::Path(tmp[tmp.depth()-1]); + aName.makeDirectory(); + } + + addDirectory(aName, aFile.getLastModified()); + } + + // iterate over children + std::vector children; + aFile.list(children); + std::vector::const_iterator it = children.begin(); + std::vector::const_iterator itEnd = children.end(); + for (; it != itEnd; ++it) + { + Poco::Path realFile(entry, *it); + Poco::Path renamedFile(aName, *it); + Poco::File aFile(realFile); + if (aFile.isDirectory()) + { + realFile.makeDirectory(); + renamedFile.makeDirectory(); + addRecursive(realFile, cl, false, renamedFile); + } + else + { + realFile.makeFile(); + renamedFile.makeFile(); + addFile(realFile, renamedFile, ZipCommon::CM_DEFLATE, cl); + } + } +} + + +ZipArchive Compress::close() +{ + if (!_dirs.empty()) + return ZipArchive(_files, _infos, _dirs); + + poco_assert (_infos.size() == _files.size()); + poco_assert (_files.size() < 65536); + Poco::UInt32 centralDirStart = _offset; + Poco::UInt32 centralDirSize = 0; + // write all infos + ZipArchive::FileInfos::const_iterator it = _infos.begin(); + ZipArchive::FileInfos::const_iterator itEnd = _infos.end(); + for (; it != itEnd; ++it) + { + const ZipFileInfo& nfo = it->second; + std::string info(nfo.createHeader()); + _out.write(info.c_str(), static_cast(info.size())); + Poco::UInt32 entrySize = static_cast(info.size()); + centralDirSize += entrySize; + _offset += entrySize; + } + poco_assert (_out); + + + Poco::UInt16 numEntries = static_cast(_infos.size()); + ZipArchiveInfo central; + central.setCentralDirectorySize(centralDirSize); + central.setNumberOfEntries(numEntries); + central.setTotalNumberOfEntries(numEntries); + central.setHeaderOffset(centralDirStart); + std::string centr(central.createHeader()); + _out.write(centr.c_str(), static_cast(centr.size())); + _out.flush(); + _dirs.insert(std::make_pair(0, central)); + return ZipArchive(_files, _infos, _dirs); +} + + +} } // namespace Poco::Zip Property changes on: Zip/src/Compress.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/testsuite/files.cmake =================================================================== --- Zip/testsuite/files.cmake (revision 0) +++ Zip/testsuite/files.cmake (revision 0) @@ -0,0 +1,19 @@ +SET(CPP_BASE_FILENAMES + CompressTest + Driver + PartialStreamTest + ZipTest + ZipTestSuite +) + +IF(WIN32) +SET(CPP_BASE_FILENAMES + WinDriver + ${CPP_BASE_FILENAMES} +) +ENDIF(WIN32) + +SET(CPP_FILES "") +FOREACH(basename ${CPP_BASE_FILENAMES}) + SET(CPP_FILES ${CPP_FILES} src/${basename}) +ENDFOREACH(basename ${CPP_BASE_FILENAMES}) Property changes on: Zip/testsuite/files.cmake ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/testsuite/src/CompressTest.h =================================================================== --- Zip/testsuite/src/CompressTest.h (revision 0) +++ Zip/testsuite/src/CompressTest.h (revision 0) @@ -0,0 +1,64 @@ +// +// CompressTest.h +// +// $Id$ +// +// Definition of the CompressTest class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef CompressTest_INCLUDED +#define CompressTest_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "CppUnit/TestCase.h" + + +class CompressTest: public CppUnit::TestCase +{ +public: + CompressTest(const std::string& name); + ~CompressTest(); + + void testSingleFile(); + void testDirectory(); + void testManipulator(); + void testManipulatorDel(); + void testManipulatorReplace(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // CompressTest_INCLUDED Property changes on: Zip/testsuite/src/CompressTest.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/testsuite/src/ZipTestSuite.h =================================================================== --- Zip/testsuite/src/ZipTestSuite.h (revision 0) +++ Zip/testsuite/src/ZipTestSuite.h (revision 0) @@ -0,0 +1,49 @@ +// +// ZipTestSuite.h +// +// $Id$ +// +// Definition of the ZipTestSuite class. +// +// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef ZipTestSuite_INCLUDED +#define ZipTestSuite_INCLUDED + + +#include "CppUnit/TestSuite.h" + + +class ZipTestSuite +{ +public: + static CppUnit::Test* suite(); +}; + + +#endif // ZipTestSuite_INCLUDED Property changes on: Zip/testsuite/src/ZipTestSuite.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/testsuite/src/ZipTest.cpp =================================================================== --- Zip/testsuite/src/ZipTest.cpp (revision 0) +++ Zip/testsuite/src/ZipTest.cpp (revision 0) @@ -0,0 +1,215 @@ +// +// ZipTest.cpp +// +// $Id$ +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "ZipTest.h" +#include "Poco/Zip/SkipCallback.h" +#include "Poco/Zip/ZipLocalFileHeader.h" +#include "Poco/Zip/ZipArchive.h" +#include "Poco/Zip/ZipStream.h" +#include "Poco/Zip/Decompress.h" +#include "Poco/Zip/ZipCommon.h" +#include "Poco/StreamCopier.h" +#include "Poco/File.h" +#include "Poco/URI.h" +#include "Poco/Path.h" +#include "Poco/Delegate.h" +#include "Poco/StreamCopier.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include +#include + + +using namespace Poco::Zip; + + +ZipTest::ZipTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +ZipTest::~ZipTest() +{ +} + + +void ZipTest::testSkipSingleFile() +{ + std::string testFile = getTestFile("test.zip"); + std::ifstream inp(testFile.c_str(), std::ios::binary); + assert (inp.good()); + SkipCallback skip; + ZipLocalFileHeader hdr(inp, false, skip); + assert (ZipCommon::HS_FAT == hdr.getHostSystem()); + int major = hdr.getMajorVersionNumber(); + int minor = hdr.getMinorVersionNumber(); + assert (major <= 2); + std::size_t hdrSize = hdr.getHeaderSize(); + assert (hdrSize > 30); + ZipCommon::CompressionMethod cm = hdr.getCompressionMethod(); + assert (!hdr.isEncrypted()); + Poco::DateTime aDate = hdr.lastModifiedAt(); + Poco::UInt32 cS = hdr.getCompressedSize(); + Poco::UInt32 uS = hdr.getUncompressedSize(); + const std::string& fileName = hdr.getFileName(); +} + + +void ZipTest::testDecompressSingleFile() +{ + std::string testFile = getTestFile("test.zip"); + std::ifstream inp(testFile.c_str(), std::ios::binary); + assert (inp.good()); + ZipArchive arch(inp); + ZipArchive::FileHeaders::const_iterator it = arch.findHeader("testfile.txt"); + assert (it != arch.headerEnd()); + ZipInputStream zipin (inp, it->second); + std::ostringstream out(std::ios::binary); + Poco::StreamCopier::copyStream(zipin, out); + assert(!out.str().empty()); +} + + +void ZipTest::testCrcAndSizeAfterData() +{ + std::string testFile = getTestFile("data.zip"); + std::ifstream inp(testFile.c_str(), std::ios::binary); + assert (inp.good()); + Decompress dec(inp, Poco::Path()); + dec.EError += Poco::Delegate >(this, &ZipTest::onDecompressError); + dec.decompressAllFiles(); + dec.EError -= Poco::Delegate >(this, &ZipTest::onDecompressError); + assert (_errCnt == 0); + assert (!dec.mapping().empty()); +} + + +void ZipTest::testCrcAndSizeAfterDataWithArchive() +{ + std::string testFile = getTestFile("data.zip"); + std::ifstream inp(testFile.c_str(), std::ios::binary); + assert (inp.good()); + Poco::Zip::ZipArchive zip(inp); + inp.clear(); + inp.seekg(0); + Poco::Zip::ZipArchive::FileHeaders::const_iterator it = zip.headerBegin(); + for ( ; it!=zip.headerEnd(); ++it) + { + Poco::Zip::ZipInputStream zipis(inp,it->second); + Poco::Path path(it->second.getFileName()); + if (path.isFile()) + { + std::ofstream os("test.dat"); + Poco::StreamCopier::copyStream(zipis,os); + } + } +} + + +std::string ZipTest::getTestFile(const std::string& testFile) +{ + Poco::Path root; + root.makeAbsolute(); + Poco::Path result; + while (!Poco::Path::find(root.toString(), "data", result)) + { + root.makeParent(); + if (root.toString().empty() || root.toString() == "/") + throw Poco::FileNotFoundException("Didn't find data subdir"); + } + result.makeDirectory(); + result.setFileName(testFile); + Poco::File aFile(result.toString()); + if (!aFile.exists() || (aFile.exists() && !aFile.isFile())) + throw Poco::FileNotFoundException("Didn't find " + testFile); + + return result.toString(); +} + + +void ZipTest::testDecompress() +{ + std::string testFile = getTestFile("test.zip"); + std::ifstream inp(testFile.c_str(), std::ios::binary); + assert (inp.good()); + Decompress dec(inp, Poco::Path()); + dec.EError += Poco::Delegate >(this, &ZipTest::onDecompressError); + dec.decompressAllFiles(); + dec.EError -= Poco::Delegate >(this, &ZipTest::onDecompressError); + assert (_errCnt == 0); + assert (!dec.mapping().empty()); +} + + +void ZipTest::testDecompressFlat() +{ + std::string testFile = getTestFile("test.zip"); + std::ifstream inp(testFile.c_str(), std::ios::binary); + assert (inp.good()); + Decompress dec(inp, Poco::Path(), true); + dec.EError += Poco::Delegate >(this, &ZipTest::onDecompressError); + dec.decompressAllFiles(); + dec.EError -= Poco::Delegate >(this, &ZipTest::onDecompressError); + assert (_errCnt == 0); + assert (!dec.mapping().empty()); +} + + +void ZipTest::onDecompressError(const void* pSender, std::pair& info) +{ + ++_errCnt; +} + + +void ZipTest::setUp() +{ + _errCnt = 0; +} + + +void ZipTest::tearDown() +{ +} + + +CppUnit::Test* ZipTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ZipTest"); + + CppUnit_addTest(pSuite, ZipTest, testSkipSingleFile); + CppUnit_addTest(pSuite, ZipTest, testDecompressSingleFile); + CppUnit_addTest(pSuite, ZipTest, testDecompress); + CppUnit_addTest(pSuite, ZipTest, testDecompressFlat); + CppUnit_addTest(pSuite, ZipTest, testCrcAndSizeAfterData); + CppUnit_addTest(pSuite, ZipTest, testCrcAndSizeAfterDataWithArchive); + return pSuite; +} Property changes on: Zip/testsuite/src/ZipTest.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/testsuite/src/ZipTest.h =================================================================== --- Zip/testsuite/src/ZipTest.h (revision 0) +++ Zip/testsuite/src/ZipTest.h (revision 0) @@ -0,0 +1,72 @@ +// +// ZipTest.h +// +// $Id$ +// +// Definition of the ZipTest class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef ZipTest_INCLUDED +#define ZipTest_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "Poco/Zip/ZipLocalFileHeader.h" +#include "CppUnit/TestCase.h" + + +class ZipTest: public CppUnit::TestCase +{ +public: + ZipTest(const std::string& name); + ~ZipTest(); + + void testSkipSingleFile(); + void testDecompressSingleFile(); + void testDecompress(); + void testCrcAndSizeAfterData(); + void testCrcAndSizeAfterDataWithArchive(); + + void testDecompressFlat(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + + static std::string getTestFile(const std::string& testFile); + +private: + void onDecompressError(const void* pSender, std::pair& info); + + int _errCnt; +}; + + +#endif // ZipTest_INCLUDED Property changes on: Zip/testsuite/src/ZipTest.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/testsuite/src/PartialStreamTest.cpp =================================================================== --- Zip/testsuite/src/PartialStreamTest.cpp (revision 0) +++ Zip/testsuite/src/PartialStreamTest.cpp (revision 0) @@ -0,0 +1,139 @@ +// +// PartialStreamTest.cpp +// +// $Id$ +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "PartialStreamTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/Zip/PartialStream.h" +#include + + +using namespace Poco::Zip; + + +PartialStreamTest::PartialStreamTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +PartialStreamTest::~PartialStreamTest() +{ +} + + +void PartialStreamTest::testReading() +{ + std::string message("some dummy message !"); + std::string prefix("pre "); + std::string postfix(" post"); + std::string result(prefix+message+postfix); + std::istringstream istr(message); + PartialInputStream in(istr, 0, static_cast(message.length()), true, prefix, postfix); + char buf[124]; + in.read(buf, 124); + std::string res(buf, in.gcount()); + assert (res == result); +} + + +void PartialStreamTest::testWriting() +{ + std::string prefix("X"); + std::string message("some test message"); + std::string postfix("YYY"); + std::string result(prefix+message+postfix); + std::ostringstream ostr; + PartialOutputStream out(ostr, prefix.size(), postfix.size()); + out.write(result.c_str(), static_cast(result.length())); + assert (out.good()); + out.close(); + std::string res (ostr.str()); + assert (out.bytesWritten() == message.size()); + assert (message == res); +} + + +void PartialStreamTest::testWritingZero() +{ + std::string prefix("X"); + std::string message; + std::string postfix("YYY"); + std::string result(prefix+message+postfix); + std::ostringstream ostr; + PartialOutputStream out(ostr, prefix.size(), postfix.size()); + out.write(result.c_str(), static_cast(result.length())); + assert (out.good()); + out.close(); + std::string res (ostr.str()); + assert (out.bytesWritten() == message.size()); + assert (message == res); +} + + +void PartialStreamTest::testWritingOne() +{ + std::string prefix("X"); + std::string message("a"); + std::string postfix("YYY"); + std::string result(prefix+message+postfix); + std::ostringstream ostr; + PartialOutputStream out(ostr, prefix.size(), postfix.size()); + out.write(result.c_str(), static_cast(result.length())); + assert (out.good()); + out.close(); + std::string res (ostr.str()); + assert (out.bytesWritten() == message.size()); + assert (message == res); +} + + +void PartialStreamTest::setUp() +{ +} + + +void PartialStreamTest::tearDown() +{ +} + + +CppUnit::Test* PartialStreamTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("PartialStreamTest"); + + CppUnit_addTest(pSuite, PartialStreamTest, testReading); + CppUnit_addTest(pSuite, PartialStreamTest, testWriting); + CppUnit_addTest(pSuite, PartialStreamTest, testWritingZero); + CppUnit_addTest(pSuite, PartialStreamTest, testWritingOne); + + return pSuite; +} Property changes on: Zip/testsuite/src/PartialStreamTest.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/testsuite/src/WinDriver.cpp =================================================================== --- Zip/testsuite/src/WinDriver.cpp (revision 0) +++ Zip/testsuite/src/WinDriver.cpp (revision 0) @@ -0,0 +1,50 @@ +// +// WinDriver.cpp +// +// $Id$ +// +// Windows test driver for Poco Zip. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "WinTestRunner/WinTestRunner.h" +#include "ZipTestSuite.h" + + +class TestDriver: public CppUnit::WinTestRunnerApp +{ + void TestMain() + { + CppUnit::WinTestRunner runner; + runner.addTest(ZipTestSuite::suite()); + runner.run(); + } +}; + + +TestDriver theDriver; Property changes on: Zip/testsuite/src/WinDriver.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/testsuite/src/CompressTest.cpp =================================================================== --- Zip/testsuite/src/CompressTest.cpp (revision 0) +++ Zip/testsuite/src/CompressTest.cpp (revision 0) @@ -0,0 +1,165 @@ +// +// CompressTest.cpp +// +// $Id$ +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "CompressTest.h" +#include "ZipTest.h" +#include "Poco/Zip/Compress.h" +#include "Poco/Zip/ZipManipulator.h" +#include "Poco/File.h" +#include "Poco/FileStream.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include + + +using namespace Poco::Zip; + + +CompressTest::CompressTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +CompressTest::~CompressTest() +{ +} + + +void CompressTest::testSingleFile() +{ + std::ofstream out("appinf.zip", std::ios::binary); + Poco::Path theFile(ZipTest::getTestFile("test.zip")); + Compress c(out, true); + c.addFile(theFile, theFile.getFileName()); + ZipArchive a(c.close()); +} + + +void CompressTest::testDirectory() +{ + std::ofstream out("pocobin.zip", std::ios::binary); + Poco::File aFile("some/"); + if (aFile.exists()) + aFile.remove(true); + Poco::File aDir("some/recursive/dir/"); + aDir.createDirectories(); + Poco::File aDir2("some/other/recursive/dir/"); + aDir2.createDirectories(); + Poco::File aF("some/recursive/dir/test.file"); + aF.createFile(); + Poco::FileOutputStream fos(aF.path()); + fos << "just some test data"; + fos.close(); + + Poco::Path theFile(aFile.path()); + theFile.makeDirectory(); + Compress c(out, true); + c.addRecursive(theFile, ZipCommon::CL_MAXIMUM, false, theFile); + ZipArchive a(c.close()); +} + + +void CompressTest::testManipulator() +{ + { + std::ofstream out("appinf.zip", std::ios::binary); + Poco::Path theFile(ZipTest::getTestFile("test.zip")); + Compress c(out, true); + c.addFile(theFile, theFile.getFileName()); + ZipArchive a(c.close()); + } + ZipManipulator zm("appinf.zip", true); + zm.renameFile("test.zip", "renamedtest.zip"); + zm.addFile("doc/othertest.zip", ZipTest::getTestFile("test.zip")); + ZipArchive archive=zm.commit(); + assert (archive.findHeader("doc/othertest.zip") != archive.headerEnd()); +} + + +void CompressTest::testManipulatorDel() +{ + { + std::ofstream out("appinf.zip", std::ios::binary); + Poco::Path theFile(ZipTest::getTestFile("test.zip")); + Compress c(out, true); + c.addFile(theFile, theFile.getFileName()); + ZipArchive a(c.close()); + } + ZipManipulator zm("appinf.zip", true); + zm.deleteFile("test.zip"); + zm.addFile("doc/data.zip", ZipTest::getTestFile("data.zip")); + ZipArchive archive=zm.commit(); + assert (archive.findHeader("test.zip") == archive.headerEnd()); + assert (archive.findHeader("doc/data.zip") != archive.headerEnd()); +} + + +void CompressTest::testManipulatorReplace() +{ + { + std::ofstream out("appinf.zip", std::ios::binary); + Poco::Path theFile(ZipTest::getTestFile("test.zip")); + Compress c(out, true); + c.addFile(theFile, theFile.getFileName()); + ZipArchive a(c.close()); + } + ZipManipulator zm("appinf.zip", true); + zm.replaceFile("test.zip", ZipTest::getTestFile("doc.zip")); + + ZipArchive archive=zm.commit(); + assert (archive.findHeader("test.zip") != archive.headerEnd()); + assert (archive.findHeader("doc.zip") == archive.headerEnd()); +} + + +void CompressTest::setUp() +{ +} + + +void CompressTest::tearDown() +{ +} + + +CppUnit::Test* CompressTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("CompressTest"); + + CppUnit_addTest(pSuite, CompressTest, testSingleFile); + CppUnit_addTest(pSuite, CompressTest, testDirectory); + CppUnit_addTest(pSuite, CompressTest, testManipulator); + CppUnit_addTest(pSuite, CompressTest, testManipulatorDel); + CppUnit_addTest(pSuite, CompressTest, testManipulatorReplace); + + return pSuite; +} Property changes on: Zip/testsuite/src/CompressTest.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/testsuite/src/Driver.cpp =================================================================== --- Zip/testsuite/src/Driver.cpp (revision 0) +++ Zip/testsuite/src/Driver.cpp (revision 0) @@ -0,0 +1,39 @@ +// +// Driver.cpp +// +// $Id$ +// +// Console-based test driver for Poco Zip. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "CppUnit/TestRunner.h" +#include "ZipTestSuite.h" + + +CppUnitMain(ZipTestSuite) Property changes on: Zip/testsuite/src/Driver.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/testsuite/src/ZipTestSuite.cpp =================================================================== --- Zip/testsuite/src/ZipTestSuite.cpp (revision 0) +++ Zip/testsuite/src/ZipTestSuite.cpp (revision 0) @@ -0,0 +1,48 @@ +// +// ZipTestSuite.cpp +// +// $Id$ +// +// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "ZipTestSuite.h" +#include "ZipTest.h" +#include "PartialStreamTest.h" +#include "CompressTest.h" + + +CppUnit::Test* ZipTestSuite::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ZipTestSuite"); + + pSuite->addTest(ZipTest::suite()); + pSuite->addTest(PartialStreamTest::suite()); + pSuite->addTest(CompressTest::suite()); + + return pSuite; +} Property changes on: Zip/testsuite/src/ZipTestSuite.cpp ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/testsuite/src/PartialStreamTest.h =================================================================== --- Zip/testsuite/src/PartialStreamTest.h (revision 0) +++ Zip/testsuite/src/PartialStreamTest.h (revision 0) @@ -0,0 +1,63 @@ +// +// PartialStreamTest.h +// +// $Id$ +// +// Definition of the PartialStreamTest class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef PartialStreamTest_INCLUDED +#define PartialStreamTest_INCLUDED + + +#include "Poco/Zip/Zip.h" +#include "CppUnit/TestCase.h" + + +class PartialStreamTest: public CppUnit::TestCase +{ +public: + PartialStreamTest(const std::string& name); + ~PartialStreamTest(); + + void testReading(); + void testWriting(); + void testWritingZero(); + void testWritingOne(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // PartialStreamTest_INCLUDED Property changes on: Zip/testsuite/src/PartialStreamTest.h ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision" Added: svn:eol-style + native Index: Zip/testsuite/data/testfile2.txt =================================================================== --- Zip/testsuite/data/testfile2.txt (revision 0) +++ Zip/testsuite/data/testfile2.txt (revision 0) @@ -0,0 +1,49 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae arcu +ac arcu semper mollis. Donec lobortis mi at dui. Integer placerat, +sapien at suscipit faucibus, mi quam sodales sapien, non accumsan enim +justo sit amet sem. Proin fermentum dui vitae metus. Donec a velit et +lectus fermentum bibendum. Donec risus magna, fermentum tempor, tempor +cursus, elementum ac, turpis. Suspendisse ultricies tincidunt quam. Nam +quis risus. Suspendisse in lacus. Vivamus et est ac nisi sollicitudin +ullamcorper. Sed vitae ligula non sem suscipit tempus. Donec tincidunt, +justo nec tristique euismod, sapien velit consequat ante, in vestibulum +dolor justo nec orci. Sed placerat eros. Suspendisse potenti. Vestibulum +eu sem at ante aliquet varius. In quis diam nec libero pretium +vestibulum. Morbi ipsum. Vivamus eros. + +Nam pellentesque ante. Donec sit amet nisl. Vestibulum blandit risus sit +amet quam facilisis mollis. Lorem ipsum dolor sit amet, consectetur +adipiscing elit. Nulla mattis orci a diam. Duis ultricies massa rhoncus +neque. Morbi hendrerit arcu vel mi. Suspendisse lorem. Pellentesque non +nunc molestie metus pretium tristique. Maecenas ante. Nunc sagittis. + +Proin ornare. Donec mi tellus, venenatis nec, ultrices ac, hendrerit in, +quam. Mauris nunc. Vivamus cursus rhoncus felis. Nunc at justo. In hac +habitasse platea dictumst. Nulla metus sapien, cursus nec, luctus eget, +malesuada sed, odio. Sed augue orci, sollicitudin id, auctor eu, +porttitor id, eros. Proin arcu dolor, iaculis quis, ullamcorper sit +amet, ullamcorper nec, ante. Sed dictum luctus est. Phasellus nibh. +Morbi fringilla magna et mi. In eleifend sem non dui luctus suscipit. +Duis dapibus. Proin molestie. Cras vel dui. + +In et orci vel erat euismod sodales. Integer porta. Vivamus congue +turpis eu eros tincidunt fermentum. Curabitur consequat ultrices mi. +Praesent sit amet ante. Proin ante. Phasellus vitae nibh. Aliquam ipsum +massa, pretium quis, mattis sed, sagittis sit amet, justo. Integer quam. +Aenean leo erat, commodo quis, elementum sit amet, placerat sed, lacus. +Nam a nunc in sapien scelerisque sodales. Phasellus luctus arcu at +nulla. Pellentesque habitant morbi tristique senectus et netus et +malesuada fames ac turpis egestas. Donec facilisis. + +Nam scelerisque lacus a eros. Praesent ac arcu et nisl eleifend commodo. +Aenean vestibulum, augue vel posuere mattis, sem massa varius mauris, +non porttitor diam felis eu libero. Suspendisse vulputate, urna quis +dictum scelerisque, risus est pharetra orci, a iaculis dui sem quis +quam. Nam imperdiet quam eget velit. Mauris dui lacus, posuere in, +cursus eget, ultrices ut, eros. Etiam eget purus. Curabitur accumsan +lacinia urna. Donec aliquet dictum erat. Nulla ac magna. Quisque +ultrices vehicula lacus. Fusce eu quam quis est mollis adipiscing. +Pellentesque non libero at eros vulputate iaculis. Praesent vitae orci +ac sapien laoreet scelerisque. Ut ut libero. Vivamus massa urna, +convallis at, laoreet a, adipiscing et, eros. Suspendisse feugiat +malesuada felis. Suspendisse a odio eget tortor tempus pretium. Property changes on: Zip/testsuite/data/testfile2.txt ___________________________________________________________________ Added: svn:eol-style + native Index: Zip/testsuite/data/test.zip =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: Zip/testsuite/data/test.zip ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: Zip/testsuite/data/testfile3.txt =================================================================== --- Zip/testsuite/data/testfile3.txt (revision 0) +++ Zip/testsuite/data/testfile3.txt (revision 0) @@ -0,0 +1,49 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae arcu +ac arcu semper mollis. Donec lobortis mi at dui. Integer placerat, +sapien at suscipit faucibus, mi quam sodales sapien, non accumsan enim +justo sit amet sem. Proin fermentum dui vitae metus. Donec a velit et +lectus fermentum bibendum. Donec risus magna, fermentum tempor, tempor +cursus, elementum ac, turpis. Suspendisse ultricies tincidunt quam. Nam +quis risus. Suspendisse in lacus. Vivamus et est ac nisi sollicitudin +ullamcorper. Sed vitae ligula non sem suscipit tempus. Donec tincidunt, +justo nec tristique euismod, sapien velit consequat ante, in vestibulum +dolor justo nec orci. Sed placerat eros. Suspendisse potenti. Vestibulum +eu sem at ante aliquet varius. In quis diam nec libero pretium +vestibulum. Morbi ipsum. Vivamus eros. + +Nam pellentesque ante. Donec sit amet nisl. Vestibulum blandit risus sit +amet quam facilisis mollis. Lorem ipsum dolor sit amet, consectetur +adipiscing elit. Nulla mattis orci a diam. Duis ultricies massa rhoncus +neque. Morbi hendrerit arcu vel mi. Suspendisse lorem. Pellentesque non +nunc molestie metus pretium tristique. Maecenas ante. Nunc sagittis. + +Proin ornare. Donec mi tellus, venenatis nec, ultrices ac, hendrerit in, +quam. Mauris nunc. Vivamus cursus rhoncus felis. Nunc at justo. In hac +habitasse platea dictumst. Nulla metus sapien, cursus nec, luctus eget, +malesuada sed, odio. Sed augue orci, sollicitudin id, auctor eu, +porttitor id, eros. Proin arcu dolor, iaculis quis, ullamcorper sit +amet, ullamcorper nec, ante. Sed dictum luctus est. Phasellus nibh. +Morbi fringilla magna et mi. In eleifend sem non dui luctus suscipit. +Duis dapibus. Proin molestie. Cras vel dui. + +In et orci vel erat euismod sodales. Integer porta. Vivamus congue +turpis eu eros tincidunt fermentum. Curabitur consequat ultrices mi. +Praesent sit amet ante. Proin ante. Phasellus vitae nibh. Aliquam ipsum +massa, pretium quis, mattis sed, sagittis sit amet, justo. Integer quam. +Aenean leo erat, commodo quis, elementum sit amet, placerat sed, lacus. +Nam a nunc in sapien scelerisque sodales. Phasellus luctus arcu at +nulla. Pellentesque habitant morbi tristique senectus et netus et +malesuada fames ac turpis egestas. Donec facilisis. + +Nam scelerisque lacus a eros. Praesent ac arcu et nisl eleifend commodo. +Aenean vestibulum, augue vel posuere mattis, sem massa varius mauris, +non porttitor diam felis eu libero. Suspendisse vulputate, urna quis +dictum scelerisque, risus est pharetra orci, a iaculis dui sem quis +quam. Nam imperdiet quam eget velit. Mauris dui lacus, posuere in, +cursus eget, ultrices ut, eros. Etiam eget purus. Curabitur accumsan +lacinia urna. Donec aliquet dictum erat. Nulla ac magna. Quisque +ultrices vehicula lacus. Fusce eu quam quis est mollis adipiscing. +Pellentesque non libero at eros vulputate iaculis. Praesent vitae orci +ac sapien laoreet scelerisque. Ut ut libero. Vivamus massa urna, +convallis at, laoreet a, adipiscing et, eros. Suspendisse feugiat +malesuada felis. Suspendisse a odio eget tortor tempus pretium. Property changes on: Zip/testsuite/data/testfile3.txt ___________________________________________________________________ Added: svn:eol-style + native Index: Zip/testsuite/data/some/recursive/dir/test.file =================================================================== --- Zip/testsuite/data/some/recursive/dir/test.file (revision 0) +++ Zip/testsuite/data/some/recursive/dir/test.file (revision 0) @@ -0,0 +1 @@ +just some test data \ No newline at end of file Index: Zip/testsuite/data/doc.zip =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: Zip/testsuite/data/doc.zip ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: Zip/testsuite/data/test.dat =================================================================== --- Zip/testsuite/data/test.dat (revision 0) +++ Zip/testsuite/data/test.dat (revision 0) @@ -0,0 +1,49 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae arcu +ac arcu semper mollis. Donec lobortis mi at dui. Integer placerat, +sapien at suscipit faucibus, mi quam sodales sapien, non accumsan enim +justo sit amet sem. Proin fermentum dui vitae metus. Donec a velit et +lectus fermentum bibendum. Donec risus magna, fermentum tempor, tempor +cursus, elementum ac, turpis. Suspendisse ultricies tincidunt quam. Nam +quis risus. Suspendisse in lacus. Vivamus et est ac nisi sollicitudin +ullamcorper. Sed vitae ligula non sem suscipit tempus. Donec tincidunt, +justo nec tristique euismod, sapien velit consequat ante, in vestibulum +dolor justo nec orci. Sed placerat eros. Suspendisse potenti. Vestibulum +eu sem at ante aliquet varius. In quis diam nec libero pretium +vestibulum. Morbi ipsum. Vivamus eros. + +Nam pellentesque ante. Donec sit amet nisl. Vestibulum blandit risus sit +amet quam facilisis mollis. Lorem ipsum dolor sit amet, consectetur +adipiscing elit. Nulla mattis orci a diam. Duis ultricies massa rhoncus +neque. Morbi hendrerit arcu vel mi. Suspendisse lorem. Pellentesque non +nunc molestie metus pretium tristique. Maecenas ante. Nunc sagittis. + +Proin ornare. Donec mi tellus, venenatis nec, ultrices ac, hendrerit in, +quam. Mauris nunc. Vivamus cursus rhoncus felis. Nunc at justo. In hac +habitasse platea dictumst. Nulla metus sapien, cursus nec, luctus eget, +malesuada sed, odio. Sed augue orci, sollicitudin id, auctor eu, +porttitor id, eros. Proin arcu dolor, iaculis quis, ullamcorper sit +amet, ullamcorper nec, ante. Sed dictum luctus est. Phasellus nibh. +Morbi fringilla magna et mi. In eleifend sem non dui luctus suscipit. +Duis dapibus. Proin molestie. Cras vel dui. + +In et orci vel erat euismod sodales. Integer porta. Vivamus congue +turpis eu eros tincidunt fermentum. Curabitur consequat ultrices mi. +Praesent sit amet ante. Proin ante. Phasellus vitae nibh. Aliquam ipsum +massa, pretium quis, mattis sed, sagittis sit amet, justo. Integer quam. +Aenean leo erat, commodo quis, elementum sit amet, placerat sed, lacus. +Nam a nunc in sapien scelerisque sodales. Phasellus luctus arcu at +nulla. Pellentesque habitant morbi tristique senectus et netus et +malesuada fames ac turpis egestas. Donec facilisis. + +Nam scelerisque lacus a eros. Praesent ac arcu et nisl eleifend commodo. +Aenean vestibulum, augue vel posuere mattis, sem massa varius mauris, +non porttitor diam felis eu libero. Suspendisse vulputate, urna quis +dictum scelerisque, risus est pharetra orci, a iaculis dui sem quis +quam. Nam imperdiet quam eget velit. Mauris dui lacus, posuere in, +cursus eget, ultrices ut, eros. Etiam eget purus. Curabitur accumsan +lacinia urna. Donec aliquet dictum erat. Nulla ac magna. Quisque +ultrices vehicula lacus. Fusce eu quam quis est mollis adipiscing. +Pellentesque non libero at eros vulputate iaculis. Praesent vitae orci +ac sapien laoreet scelerisque. Ut ut libero. Vivamus massa urna, +convallis at, laoreet a, adipiscing et, eros. Suspendisse feugiat +malesuada felis. Suspendisse a odio eget tortor tempus pretium. Index: Zip/testsuite/data/data.zip =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: Zip/testsuite/data/data.zip ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: Zip/testsuite/data/pocobin.zip =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: Zip/testsuite/data/pocobin.zip ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: Zip/testsuite/data/appinf.zip.bak =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: Zip/testsuite/data/appinf.zip.bak ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: Zip/testsuite/data/testfile.txt =================================================================== --- Zip/testsuite/data/testfile.txt (revision 0) +++ Zip/testsuite/data/testfile.txt (revision 0) @@ -0,0 +1,49 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae arcu +ac arcu semper mollis. Donec lobortis mi at dui. Integer placerat, +sapien at suscipit faucibus, mi quam sodales sapien, non accumsan enim +justo sit amet sem. Proin fermentum dui vitae metus. Donec a velit et +lectus fermentum bibendum. Donec risus magna, fermentum tempor, tempor +cursus, elementum ac, turpis. Suspendisse ultricies tincidunt quam. Nam +quis risus. Suspendisse in lacus. Vivamus et est ac nisi sollicitudin +ullamcorper. Sed vitae ligula non sem suscipit tempus. Donec tincidunt, +justo nec tristique euismod, sapien velit consequat ante, in vestibulum +dolor justo nec orci. Sed placerat eros. Suspendisse potenti. Vestibulum +eu sem at ante aliquet varius. In quis diam nec libero pretium +vestibulum. Morbi ipsum. Vivamus eros. + +Nam pellentesque ante. Donec sit amet nisl. Vestibulum blandit risus sit +amet quam facilisis mollis. Lorem ipsum dolor sit amet, consectetur +adipiscing elit. Nulla mattis orci a diam. Duis ultricies massa rhoncus +neque. Morbi hendrerit arcu vel mi. Suspendisse lorem. Pellentesque non +nunc molestie metus pretium tristique. Maecenas ante. Nunc sagittis. + +Proin ornare. Donec mi tellus, venenatis nec, ultrices ac, hendrerit in, +quam. Mauris nunc. Vivamus cursus rhoncus felis. Nunc at justo. In hac +habitasse platea dictumst. Nulla metus sapien, cursus nec, luctus eget, +malesuada sed, odio. Sed augue orci, sollicitudin id, auctor eu, +porttitor id, eros. Proin arcu dolor, iaculis quis, ullamcorper sit +amet, ullamcorper nec, ante. Sed dictum luctus est. Phasellus nibh. +Morbi fringilla magna et mi. In eleifend sem non dui luctus suscipit. +Duis dapibus. Proin molestie. Cras vel dui. + +In et orci vel erat euismod sodales. Integer porta. Vivamus congue +turpis eu eros tincidunt fermentum. Curabitur consequat ultrices mi. +Praesent sit amet ante. Proin ante. Phasellus vitae nibh. Aliquam ipsum +massa, pretium quis, mattis sed, sagittis sit amet, justo. Integer quam. +Aenean leo erat, commodo quis, elementum sit amet, placerat sed, lacus. +Nam a nunc in sapien scelerisque sodales. Phasellus luctus arcu at +nulla. Pellentesque habitant morbi tristique senectus et netus et +malesuada fames ac turpis egestas. Donec facilisis. + +Nam scelerisque lacus a eros. Praesent ac arcu et nisl eleifend commodo. +Aenean vestibulum, augue vel posuere mattis, sem massa varius mauris, +non porttitor diam felis eu libero. Suspendisse vulputate, urna quis +dictum scelerisque, risus est pharetra orci, a iaculis dui sem quis +quam. Nam imperdiet quam eget velit. Mauris dui lacus, posuere in, +cursus eget, ultrices ut, eros. Etiam eget purus. Curabitur accumsan +lacinia urna. Donec aliquet dictum erat. Nulla ac magna. Quisque +ultrices vehicula lacus. Fusce eu quam quis est mollis adipiscing. +Pellentesque non libero at eros vulputate iaculis. Praesent vitae orci +ac sapien laoreet scelerisque. Ut ut libero. Vivamus massa urna, +convallis at, laoreet a, adipiscing et, eros. Suspendisse feugiat +malesuada felis. Suspendisse a odio eget tortor tempus pretium. Property changes on: Zip/testsuite/data/testfile.txt ___________________________________________________________________ Added: svn:eol-style + native Index: Zip/testsuite/data/testdir/testfile2.txt =================================================================== --- Zip/testsuite/data/testdir/testfile2.txt (revision 0) +++ Zip/testsuite/data/testdir/testfile2.txt (revision 0) @@ -0,0 +1,49 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae arcu +ac arcu semper mollis. Donec lobortis mi at dui. Integer placerat, +sapien at suscipit faucibus, mi quam sodales sapien, non accumsan enim +justo sit amet sem. Proin fermentum dui vitae metus. Donec a velit et +lectus fermentum bibendum. Donec risus magna, fermentum tempor, tempor +cursus, elementum ac, turpis. Suspendisse ultricies tincidunt quam. Nam +quis risus. Suspendisse in lacus. Vivamus et est ac nisi sollicitudin +ullamcorper. Sed vitae ligula non sem suscipit tempus. Donec tincidunt, +justo nec tristique euismod, sapien velit consequat ante, in vestibulum +dolor justo nec orci. Sed placerat eros. Suspendisse potenti. Vestibulum +eu sem at ante aliquet varius. In quis diam nec libero pretium +vestibulum. Morbi ipsum. Vivamus eros. + +Nam pellentesque ante. Donec sit amet nisl. Vestibulum blandit risus sit +amet quam facilisis mollis. Lorem ipsum dolor sit amet, consectetur +adipiscing elit. Nulla mattis orci a diam. Duis ultricies massa rhoncus +neque. Morbi hendrerit arcu vel mi. Suspendisse lorem. Pellentesque non +nunc molestie metus pretium tristique. Maecenas ante. Nunc sagittis. + +Proin ornare. Donec mi tellus, venenatis nec, ultrices ac, hendrerit in, +quam. Mauris nunc. Vivamus cursus rhoncus felis. Nunc at justo. In hac +habitasse platea dictumst. Nulla metus sapien, cursus nec, luctus eget, +malesuada sed, odio. Sed augue orci, sollicitudin id, auctor eu, +porttitor id, eros. Proin arcu dolor, iaculis quis, ullamcorper sit +amet, ullamcorper nec, ante. Sed dictum luctus est. Phasellus nibh. +Morbi fringilla magna et mi. In eleifend sem non dui luctus suscipit. +Duis dapibus. Proin molestie. Cras vel dui. + +In et orci vel erat euismod sodales. Integer porta. Vivamus congue +turpis eu eros tincidunt fermentum. Curabitur consequat ultrices mi. +Praesent sit amet ante. Proin ante. Phasellus vitae nibh. Aliquam ipsum +massa, pretium quis, mattis sed, sagittis sit amet, justo. Integer quam. +Aenean leo erat, commodo quis, elementum sit amet, placerat sed, lacus. +Nam a nunc in sapien scelerisque sodales. Phasellus luctus arcu at +nulla. Pellentesque habitant morbi tristique senectus et netus et +malesuada fames ac turpis egestas. Donec facilisis. + +Nam scelerisque lacus a eros. Praesent ac arcu et nisl eleifend commodo. +Aenean vestibulum, augue vel posuere mattis, sem massa varius mauris, +non porttitor diam felis eu libero. Suspendisse vulputate, urna quis +dictum scelerisque, risus est pharetra orci, a iaculis dui sem quis +quam. Nam imperdiet quam eget velit. Mauris dui lacus, posuere in, +cursus eget, ultrices ut, eros. Etiam eget purus. Curabitur accumsan +lacinia urna. Donec aliquet dictum erat. Nulla ac magna. Quisque +ultrices vehicula lacus. Fusce eu quam quis est mollis adipiscing. +Pellentesque non libero at eros vulputate iaculis. Praesent vitae orci +ac sapien laoreet scelerisque. Ut ut libero. Vivamus massa urna, +convallis at, laoreet a, adipiscing et, eros. Suspendisse feugiat +malesuada felis. Suspendisse a odio eget tortor tempus pretium. Property changes on: Zip/testsuite/data/testdir/testfile2.txt ___________________________________________________________________ Added: svn:eol-style + native Index: Zip/testsuite/data/testdir/testdir2/testfile3.txt =================================================================== --- Zip/testsuite/data/testdir/testdir2/testfile3.txt (revision 0) +++ Zip/testsuite/data/testdir/testdir2/testfile3.txt (revision 0) @@ -0,0 +1,49 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae arcu +ac arcu semper mollis. Donec lobortis mi at dui. Integer placerat, +sapien at suscipit faucibus, mi quam sodales sapien, non accumsan enim +justo sit amet sem. Proin fermentum dui vitae metus. Donec a velit et +lectus fermentum bibendum. Donec risus magna, fermentum tempor, tempor +cursus, elementum ac, turpis. Suspendisse ultricies tincidunt quam. Nam +quis risus. Suspendisse in lacus. Vivamus et est ac nisi sollicitudin +ullamcorper. Sed vitae ligula non sem suscipit tempus. Donec tincidunt, +justo nec tristique euismod, sapien velit consequat ante, in vestibulum +dolor justo nec orci. Sed placerat eros. Suspendisse potenti. Vestibulum +eu sem at ante aliquet varius. In quis diam nec libero pretium +vestibulum. Morbi ipsum. Vivamus eros. + +Nam pellentesque ante. Donec sit amet nisl. Vestibulum blandit risus sit +amet quam facilisis mollis. Lorem ipsum dolor sit amet, consectetur +adipiscing elit. Nulla mattis orci a diam. Duis ultricies massa rhoncus +neque. Morbi hendrerit arcu vel mi. Suspendisse lorem. Pellentesque non +nunc molestie metus pretium tristique. Maecenas ante. Nunc sagittis. + +Proin ornare. Donec mi tellus, venenatis nec, ultrices ac, hendrerit in, +quam. Mauris nunc. Vivamus cursus rhoncus felis. Nunc at justo. In hac +habitasse platea dictumst. Nulla metus sapien, cursus nec, luctus eget, +malesuada sed, odio. Sed augue orci, sollicitudin id, auctor eu, +porttitor id, eros. Proin arcu dolor, iaculis quis, ullamcorper sit +amet, ullamcorper nec, ante. Sed dictum luctus est. Phasellus nibh. +Morbi fringilla magna et mi. In eleifend sem non dui luctus suscipit. +Duis dapibus. Proin molestie. Cras vel dui. + +In et orci vel erat euismod sodales. Integer porta. Vivamus congue +turpis eu eros tincidunt fermentum. Curabitur consequat ultrices mi. +Praesent sit amet ante. Proin ante. Phasellus vitae nibh. Aliquam ipsum +massa, pretium quis, mattis sed, sagittis sit amet, justo. Integer quam. +Aenean leo erat, commodo quis, elementum sit amet, placerat sed, lacus. +Nam a nunc in sapien scelerisque sodales. Phasellus luctus arcu at +nulla. Pellentesque habitant morbi tristique senectus et netus et +malesuada fames ac turpis egestas. Donec facilisis. + +Nam scelerisque lacus a eros. Praesent ac arcu et nisl eleifend commodo. +Aenean vestibulum, augue vel posuere mattis, sem massa varius mauris, +non porttitor diam felis eu libero. Suspendisse vulputate, urna quis +dictum scelerisque, risus est pharetra orci, a iaculis dui sem quis +quam. Nam imperdiet quam eget velit. Mauris dui lacus, posuere in, +cursus eget, ultrices ut, eros. Etiam eget purus. Curabitur accumsan +lacinia urna. Donec aliquet dictum erat. Nulla ac magna. Quisque +ultrices vehicula lacus. Fusce eu quam quis est mollis adipiscing. +Pellentesque non libero at eros vulputate iaculis. Praesent vitae orci +ac sapien laoreet scelerisque. Ut ut libero. Vivamus massa urna, +convallis at, laoreet a, adipiscing et, eros. Suspendisse feugiat +malesuada felis. Suspendisse a odio eget tortor tempus pretium. Property changes on: Zip/testsuite/data/testdir/testdir2/testfile3.txt ___________________________________________________________________ Added: svn:eol-style + native Index: Zip/testsuite/data/testdir/testfile.txt =================================================================== --- Zip/testsuite/data/testdir/testfile.txt (revision 0) +++ Zip/testsuite/data/testdir/testfile.txt (revision 0) @@ -0,0 +1,49 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae arcu +ac arcu semper mollis. Donec lobortis mi at dui. Integer placerat, +sapien at suscipit faucibus, mi quam sodales sapien, non accumsan enim +justo sit amet sem. Proin fermentum dui vitae metus. Donec a velit et +lectus fermentum bibendum. Donec risus magna, fermentum tempor, tempor +cursus, elementum ac, turpis. Suspendisse ultricies tincidunt quam. Nam +quis risus. Suspendisse in lacus. Vivamus et est ac nisi sollicitudin +ullamcorper. Sed vitae ligula non sem suscipit tempus. Donec tincidunt, +justo nec tristique euismod, sapien velit consequat ante, in vestibulum +dolor justo nec orci. Sed placerat eros. Suspendisse potenti. Vestibulum +eu sem at ante aliquet varius. In quis diam nec libero pretium +vestibulum. Morbi ipsum. Vivamus eros. + +Nam pellentesque ante. Donec sit amet nisl. Vestibulum blandit risus sit +amet quam facilisis mollis. Lorem ipsum dolor sit amet, consectetur +adipiscing elit. Nulla mattis orci a diam. Duis ultricies massa rhoncus +neque. Morbi hendrerit arcu vel mi. Suspendisse lorem. Pellentesque non +nunc molestie metus pretium tristique. Maecenas ante. Nunc sagittis. + +Proin ornare. Donec mi tellus, venenatis nec, ultrices ac, hendrerit in, +quam. Mauris nunc. Vivamus cursus rhoncus felis. Nunc at justo. In hac +habitasse platea dictumst. Nulla metus sapien, cursus nec, luctus eget, +malesuada sed, odio. Sed augue orci, sollicitudin id, auctor eu, +porttitor id, eros. Proin arcu dolor, iaculis quis, ullamcorper sit +amet, ullamcorper nec, ante. Sed dictum luctus est. Phasellus nibh. +Morbi fringilla magna et mi. In eleifend sem non dui luctus suscipit. +Duis dapibus. Proin molestie. Cras vel dui. + +In et orci vel erat euismod sodales. Integer porta. Vivamus congue +turpis eu eros tincidunt fermentum. Curabitur consequat ultrices mi. +Praesent sit amet ante. Proin ante. Phasellus vitae nibh. Aliquam ipsum +massa, pretium quis, mattis sed, sagittis sit amet, justo. Integer quam. +Aenean leo erat, commodo quis, elementum sit amet, placerat sed, lacus. +Nam a nunc in sapien scelerisque sodales. Phasellus luctus arcu at +nulla. Pellentesque habitant morbi tristique senectus et netus et +malesuada fames ac turpis egestas. Donec facilisis. + +Nam scelerisque lacus a eros. Praesent ac arcu et nisl eleifend commodo. +Aenean vestibulum, augue vel posuere mattis, sem massa varius mauris, +non porttitor diam felis eu libero. Suspendisse vulputate, urna quis +dictum scelerisque, risus est pharetra orci, a iaculis dui sem quis +quam. Nam imperdiet quam eget velit. Mauris dui lacus, posuere in, +cursus eget, ultrices ut, eros. Etiam eget purus. Curabitur accumsan +lacinia urna. Donec aliquet dictum erat. Nulla ac magna. Quisque +ultrices vehicula lacus. Fusce eu quam quis est mollis adipiscing. +Pellentesque non libero at eros vulputate iaculis. Praesent vitae orci +ac sapien laoreet scelerisque. Ut ut libero. Vivamus massa urna, +convallis at, laoreet a, adipiscing et, eros. Suspendisse feugiat +malesuada felis. Suspendisse a odio eget tortor tempus pretium. Property changes on: Zip/testsuite/data/testdir/testfile.txt ___________________________________________________________________ Added: svn:eol-style + native Index: Zip/testsuite/data/appinf.zip =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: Zip/testsuite/data/appinf.zip ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: Zip/testsuite/CMakeLists.txt =================================================================== --- Zip/testsuite/CMakeLists.txt (revision 0) +++ Zip/testsuite/CMakeLists.txt (revision 0) @@ -0,0 +1,16 @@ +INCLUDE(files.cmake) + +ADD_Executable(PocoTestRunnerZip ${CPP_FILES}) +TARGET_LINK_LIBRARIES(PocoTestRunnerZip + PocoUtil + PocoZip + PocoFoundation + CppUnit) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../include + ${CMAKE_CURRENT_SOURCE_DIR}/../../Foundation/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../XML/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../Zip/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../CppUnit/include +) + Property changes on: Zip/testsuite/CMakeLists.txt ___________________________________________________________________ Added: svn:eol-style + native Index: Zip/CMakeLists.txt =================================================================== --- Zip/CMakeLists.txt (revision 0) +++ Zip/CMakeLists.txt (revision 0) @@ -0,0 +1,32 @@ +set(LIBNAME "PocoZip") +#set(LIBNAMED "${LIBNAME}d") + +aux_source_directory(src SRCS) + +add_library( ${LIBNAME} ${LIB_MODE} ${SRCS} ) +set_target_properties( ${LIBNAME} PROPERTIES +#COMPILE_FLAGS ${DEBUG_CXX_FLAGS} + VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} + SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}) +target_link_libraries( ${LIBNAME} PocoUtil PocoXML PocoFoundation) + +#add_library( ${LIBNAMED} ${LIB_MODE} ${SRCS} ) +#set_target_properties( ${LIBNAMED} +# PROPERTIES COMPILE_FLAGS "${RELEASE_CXX_FLAGS}" +# VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} +# SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}) +#target_link_libraries( ${LIBNAMED} PocoUtild PocoXMLd PocoFoundationd) + +install( + DIRECTORY include/Poco + DESTINATION include + PATTERN ".svn" EXCLUDE + ) + +install( + TARGETS ${LIBNAME} #${LIBNAMED} + DESTINATION lib + ) + +#add_subdirectory(samples) +#add_subdirectory(testsuite) Property changes on: Zip/CMakeLists.txt ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Index: CMakeLists.txt =================================================================== --- CMakeLists.txt (revision 17887) +++ CMakeLists.txt (working copy) @@ -38,7 +38,7 @@ # Set local include path #include_directories( CppUnit/include Foundation/include XML/include Net/include NetSSL_OpenSSL/include Util/include Data/include WebWidgets/include Zip/include) -include_directories( CppUnit/include Foundation/include XML/include Util/include ) +include_directories( CppUnit/include Foundation/include XML/include Util/include Zip/include) include(CheckTypeSize) include(FindCygwin) @@ -97,13 +97,14 @@ #add_subdirectory(Data) #add_subdirectory(WebWidgets) -#add_subdirectory(Zip) +add_subdirectory(Zip) if (ENABLE_TESTS) add_subdirectory(CppUnit) add_subdirectory(Foundation/testsuite) add_subdirectory(XML/testsuite) add_subdirectory(Util/testsuite) + add_subdirectory(Zip/testsuite) endif (ENABLE_TESTS)