diff options
author | Martin Gallwey <mtg@openoffice.org> | 2000-11-13 12:38:03 +0000 |
---|---|---|
committer | Martin Gallwey <mtg@openoffice.org> | 2000-11-13 12:38:03 +0000 |
commit | db4e8a77ce6ad9a7f742574a6c01121675bd8c9c (patch) | |
tree | 5db30bcc8150595546941efc88ed432c6c7d3fb1 /package/source | |
parent | e1f02829a365c86e711bdc8141c8308e60bcfd45 (diff) |
Initial Revision :D
Diffstat (limited to 'package/source')
-rw-r--r-- | package/source/zipapi/ByteChucker.cxx | 202 | ||||
-rw-r--r-- | package/source/zipapi/ByteGrabber.cxx | 215 | ||||
-rw-r--r-- | package/source/zipapi/CRC32.cxx | 110 | ||||
-rw-r--r-- | package/source/zipapi/Deflater.cxx | 303 | ||||
-rw-r--r-- | package/source/zipapi/EntryInputStream.cxx | 188 | ||||
-rw-r--r-- | package/source/zipapi/Inflater.cxx | 268 | ||||
-rw-r--r-- | package/source/zipapi/ZipEnumeration.cxx | 105 | ||||
-rw-r--r-- | package/source/zipapi/ZipFile.cxx | 483 | ||||
-rw-r--r-- | package/source/zipapi/ZipOutputStream.cxx | 356 | ||||
-rw-r--r-- | package/source/zipapi/makefile.mk | 115 |
10 files changed, 2345 insertions, 0 deletions
diff --git a/package/source/zipapi/ByteChucker.cxx b/package/source/zipapi/ByteChucker.cxx new file mode 100644 index 000000000000..56b2ecc49a3d --- /dev/null +++ b/package/source/zipapi/ByteChucker.cxx @@ -0,0 +1,202 @@ +/************************************************************************* + * + * $RCSfile: ByteChucker.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _BYTE_CHUCKER_HXX_ +#include "ByteChucker.hxx" +#endif + +using namespace ::com::sun::star; + +/** ByteChucker implements the << operators on an XOutputStream. This is + * potentially quite slow and may need to be optimised + */ + +ByteChucker::ByteChucker(uno::Reference<io::XOutputStream> xOstream) +: xStream(xOstream) +, xSeek (xOstream, uno::UNO_QUERY ) +{ +} +ByteChucker::~ByteChucker() +{ + if ( xStream.is() ) + xStream->closeOutput(); +} + +// XOutputStream chained... +void SAL_CALL ByteChucker::writeBytes( const uno::Sequence< sal_Int8 >& aData ) + throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) +{ + xStream->writeBytes(aData); +} +void SAL_CALL ByteChucker::flush( ) + throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) +{ + xStream->flush(); +} +void SAL_CALL ByteChucker::closeOutput( ) + throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) +{ + xStream->closeOutput(); +} + +// XSeekable chained... +sal_Int64 SAL_CALL ByteChucker::seek( sal_Int64 location ) + throw(lang::IllegalArgumentException, io::IOException, uno::RuntimeException) +{ + if (xSeek.is() ) + { + sal_Int32 nLen = xSeek->getLength(); + if (location > nLen ) + location = nLen; + xSeek->seek( location ); + return location; + } + else + throw (io::IOException()); +} +sal_Int64 SAL_CALL ByteChucker::getPosition( ) + throw(io::IOException, uno::RuntimeException) +{ + if (xSeek.is() ) + return xSeek->getPosition(); + else + throw (io::IOException()); +} +sal_Int64 SAL_CALL ByteChucker::getLength( ) + throw(io::IOException, uno::RuntimeException) +{ + if (xSeek.is() ) + return xSeek->getLength(); + else + throw (io::IOException()); +} +void ByteChucker::putInt8( sal_Int8 nInt8) +{ + uno::Sequence< sal_Int8 > aSequence (1); + aSequence[0]=nInt8 & 0xFF; + xStream->writeBytes(aSequence); +} +void ByteChucker::putInt16(sal_Int16 nInt16) +{ + uno::Sequence< sal_Int8 > aSequence (2); + aSequence[0] = (nInt16 >>0 ) & 0xFF; + aSequence[1] = (nInt16 >>8 ) & 0xFF; + xStream->writeBytes(aSequence); +} +void ByteChucker::putInt32(sal_Int32 nInt32) +{ + uno::Sequence< sal_Int8 > aSequence (4); + aSequence[0] = (nInt32 >> 0 ) & 0xFF; + aSequence[1] = (nInt32 >> 8 ) & 0xFF; + aSequence[2] = (nInt32 >> 16 ) & 0xFF; + aSequence[3] = (nInt32 >> 24 ) & 0xFF; + xStream->writeBytes(aSequence); +} +ByteChucker& ByteChucker::operator << (sal_Int8 nInt8) +{ + uno::Sequence< sal_Int8 > aSequence (1); + aSequence[0]=nInt8 & 0xFF; + xStream->writeBytes(aSequence); + return *this; +} +ByteChucker& ByteChucker::operator << (sal_Int16 nInt16) +{ + uno::Sequence< sal_Int8 > aSequence (2); + aSequence[0] = (nInt16 >>0 ) & 0xFF; + aSequence[1] = (nInt16 >>8 ) & 0xFF; + xStream->writeBytes(aSequence); + return *this; +} +ByteChucker& ByteChucker::operator << (sal_Int32 nInt32) +{ + uno::Sequence< sal_Int8 > aSequence (4); + aSequence[0] = (nInt32 >> 0 ) & 0xFF; + aSequence[1] = (nInt32 >> 8 ) & 0xFF; + aSequence[2] = (nInt32 >> 16 ) & 0xFF; + aSequence[3] = (nInt32 >> 24 ) & 0xFF; + xStream->writeBytes(aSequence); + return *this; +} + +ByteChucker& ByteChucker::operator << (sal_uInt8 nuInt8) +{ + uno::Sequence< sal_Int8 > aSequence (1); + aSequence[0]=nuInt8 & 0xFF; + xStream->writeBytes(aSequence); + return *this; +} +ByteChucker& ByteChucker::operator << (sal_uInt16 nuInt16) +{ + uno::Sequence< sal_Int8 > aSequence (2); + aSequence[0] = (nuInt16 >>0 ) & 0xFF; + aSequence[1] = (nuInt16 >>8 ) & 0xFF; + xStream->writeBytes(aSequence); + return *this; +} +ByteChucker& ByteChucker::operator << (sal_uInt32 nuInt32) +{ + uno::Sequence< sal_Int8 > aSequence (4); + aSequence[0] = (nuInt32 >> 0 ) & 0xFF; + aSequence[1] = (nuInt32 >> 8 ) & 0xFF; + aSequence[2] = (nuInt32 >> 16 ) & 0xFF; + aSequence[3] = (nuInt32 >> 24 ) & 0xFF; + xStream->writeBytes(aSequence); + return *this; +} diff --git a/package/source/zipapi/ByteGrabber.cxx b/package/source/zipapi/ByteGrabber.cxx new file mode 100644 index 000000000000..785454d13e9f --- /dev/null +++ b/package/source/zipapi/ByteGrabber.cxx @@ -0,0 +1,215 @@ +/************************************************************************* + * + * $RCSfile: ByteGrabber.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _BYTE_GRABBER_HXX_ +#include "ByteGrabber.hxx" +#endif + +using namespace ::com::sun::star; + +/** ByteGrabber implements the >> operators on an XOutputStream. This is + * potentially quite slow and may need to be optimised + */ + +ByteGrabber::ByteGrabber(uno::Reference < io::XInputStream > xIstream) +: xStream(xIstream) +, xSeek (xIstream, uno::UNO_QUERY ) +{ +} +ByteGrabber::~ByteGrabber() +{ + if ( xStream.is() ) + xStream->closeInput(); +} + +// XInputStream chained +sal_Int32 SAL_CALL ByteGrabber::readBytes( uno::Sequence< sal_Int8 >& aData, + sal_Int32 nBytesToRead ) + throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) +{ + return xStream->readBytes(aData, nBytesToRead ); +} +sal_Int32 SAL_CALL ByteGrabber::readSomeBytes( uno::Sequence< sal_Int8 >& aData, + sal_Int32 nMaxBytesToRead ) + throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) +{ + return xStream->readSomeBytes( aData, nMaxBytesToRead ); +} +void SAL_CALL ByteGrabber::skipBytes( sal_Int32 nBytesToSkip ) + throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) +{ + xStream->skipBytes( nBytesToSkip ); +} +sal_Int32 SAL_CALL ByteGrabber::available( ) + throw(io::NotConnectedException, io::IOException, uno::RuntimeException) +{ + return xStream->available(); +} +void SAL_CALL ByteGrabber::closeInput( ) + throw(io::NotConnectedException, io::IOException, uno::RuntimeException) +{ + xStream->closeInput(); +} + +// XSeekable chained... +sal_Int64 SAL_CALL ByteGrabber::seek( sal_Int64 location ) + throw(lang::IllegalArgumentException, io::IOException, uno::RuntimeException) +{ + if (xSeek.is() ) + { + sal_Int32 nLen = xSeek->getLength(); + if (location > nLen ) + location = nLen; + xSeek->seek( location ); + return location; + } + else + throw (io::IOException()); +} +sal_Int64 SAL_CALL ByteGrabber::getPosition( ) + throw(io::IOException, uno::RuntimeException) +{ + if (xSeek.is() ) + return xSeek->getPosition(); + else + throw (io::IOException()); +} +sal_Int64 SAL_CALL ByteGrabber::getLength( ) + throw(io::IOException, uno::RuntimeException) +{ + if (xSeek.is() ) + return xSeek->getLength(); + else + throw (io::IOException()); +} + +sal_Int8 ByteGrabber::getInt8() +{ + uno::Sequence< sal_Int8 > aSequence (1); + xStream->readBytes(aSequence,1); + return aSequence[0]; +} +sal_Int16 ByteGrabber::getInt16() +{ + uno::Sequence< sal_Int8 > aSequence (2); + xStream->readBytes(aSequence, 2); + return (aSequence[0] | aSequence[1] << 8); +} +sal_Int32 ByteGrabber::getInt32() +{ + uno::Sequence< sal_Int8 > aSequence (4); + xStream->readBytes(aSequence, 4); + return (aSequence [0]| aSequence[1] << 8 | (sal_Int32) (aSequence[2] | aSequence[3] <<8) << 16); +} +ByteGrabber& ByteGrabber::operator >> (sal_Int8& rInt8) +{ + uno::Sequence< sal_Int8 > aSequence (1); + xStream->readBytes(aSequence,1); + rInt8 = aSequence[0]& 0xFF; + return *this; +} +ByteGrabber& ByteGrabber::operator >> (sal_Int16& rInt16) +{ + uno::Sequence< sal_Int8 > aSequence (2); + xStream->readBytes(aSequence, 2); + rInt16 = static_cast <sal_Int16> + (static_cast <sal_uInt8> (aSequence[0]& 0xFF) + | static_cast <sal_uInt8> (aSequence[1]& 0xFF) << 8); + return *this; +} +ByteGrabber& ByteGrabber::operator >> (sal_Int32& rInt32) +{ + uno::Sequence< sal_Int8 > aSequence (4); + xStream->readBytes(aSequence, 4); + rInt32 = static_cast < sal_Int32 > + (static_cast < sal_uInt8> (aSequence[0]& 0xFF) + | static_cast < sal_uInt8> (aSequence[1]& 0xFF) << 8 + | static_cast < sal_uInt8> (aSequence[2]& 0xFF) << 16 + | static_cast < sal_uInt8> (aSequence[3]& 0xFF) << 24 ); + return *this; +} + +ByteGrabber& ByteGrabber::operator >> (sal_uInt8& ruInt8) +{ + uno::Sequence< sal_Int8 > aSequence (1); + xStream->readBytes(aSequence,1); + ruInt8 = static_cast <sal_uInt8> (aSequence[0]& 0xFF); + return *this; +} +ByteGrabber& ByteGrabber::operator >> (sal_uInt16& ruInt16) +{ + uno::Sequence< sal_Int8 > aSequence (2); + xStream->readBytes(aSequence, 2); + ruInt16 = static_cast <sal_uInt16> + (static_cast < sal_uInt8 > (aSequence[0]& 0xFF) + | static_cast < sal_uInt8 > (aSequence[1]& 0xFF) << 8); + return *this; +} +ByteGrabber& ByteGrabber::operator >> (sal_uInt32& ruInt32) +{ + uno::Sequence< sal_Int8 > aSequence (4); + xStream->readBytes(aSequence, 4); + ruInt32 = static_cast < sal_uInt32 > + (static_cast < sal_uInt8> (aSequence[0]& 0xFF) + | static_cast < sal_uInt8> (aSequence[1]& 0xFF) << 8 + | static_cast < sal_uInt8> (aSequence[2]& 0xFF) << 16 + | static_cast < sal_uInt8> (aSequence[3]& 0xFF) << 24); + return *this; +} diff --git a/package/source/zipapi/CRC32.cxx b/package/source/zipapi/CRC32.cxx new file mode 100644 index 000000000000..bca9154af66f --- /dev/null +++ b/package/source/zipapi/CRC32.cxx @@ -0,0 +1,110 @@ +/************************************************************************* + * + * $RCSfile: CRC32.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CRC32_HXX +#include "CRC32.hxx" +#endif + +using namespace rtl; +using namespace com::sun::star; + +/** A class to compute the CRC32 value of a data stream + */ + +CRC32::CRC32() +: nCRC(0) +{ +} +CRC32::~CRC32() +{ +} +void CRC32::reset() +{ + nCRC=0; +} +sal_Int32 CRC32::getValue() +{ + return (sal_Int32) nCRC & 0xFFFFFFFFL; +} +/** Update CRC32 with specified byte + */ +void SAL_CALL CRC32::updateByte (sal_Int8 nByte) + throw(uno::RuntimeException) +{ + sal_uInt8 pBuf[1]; + pBuf[0] = (sal_uInt8)nByte; + nCRC = crc32(nCRC, pBuf, 1); +} +/** Update CRC32 with specified sequence of bytes + */ +void SAL_CALL CRC32::updateSegment(const uno::Sequence< sal_Int8 > &b, + sal_Int32 off, + sal_Int32 len) + throw(uno::RuntimeException) +{ + nCRC = crc32(nCRC, (const unsigned char*)b.getConstArray()+off, len ); +} +/** Update CRC32 with specified sequence of bytes + */ +void SAL_CALL CRC32::update(const uno::Sequence< sal_Int8 > &b) + throw(uno::RuntimeException) +{ + nCRC = crc32(nCRC, (const unsigned char*)b.getConstArray(),b.getLength()); +} diff --git a/package/source/zipapi/Deflater.cxx b/package/source/zipapi/Deflater.cxx new file mode 100644 index 000000000000..3bcff5fd2971 --- /dev/null +++ b/package/source/zipapi/Deflater.cxx @@ -0,0 +1,303 @@ +/************************************************************************* + * + * $RCSfile: Deflater.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _DEFLATER_HXX_ +#include "Deflater.hxx" +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +#include <iostream.h> +#include <string.h> + +using namespace com::sun::star::package::ZipConstants; +using namespace com::sun::star; + +/** Provides general purpose compression using the ZLIB compression + * library. + */ + +Deflater::~Deflater(void) +{ + if (pStream) + delete pStream; +} +void Deflater::init (sal_Int16 nLevel, sal_Int16 nStrategy, sal_Bool bNowrap) +{ + pStream = new z_stream; + /* Memset it to 0...sets zalloc/zfree/opaque to NULL */ + memset (pStream, 0, sizeof(*pStream)); + + switch (deflateInit2(pStream, nLevel, Z_DEFLATED, bNowrap? -MAX_WBITS : MAX_WBITS, + DEF_MEM_LEVEL, nStrategy)) + { + case Z_OK: + break; + case Z_MEM_ERROR: + delete pStream; + break; + case Z_STREAM_ERROR: + delete pStream; + break; + default: + break; + } +} +Deflater::Deflater() +: nLevel(DEFAULT_COMPRESSION) +, nStrategy(DEFAULT_STRATEGY) +, bFinish(sal_False) +, bFinished(sal_False) +, bSetParams(sal_False) +, nOffset(0) +, nLength(0) +{ + init(DEFAULT_COMPRESSION, DEFAULT_STRATEGY, sal_False); +} + +Deflater::Deflater(sal_Int16 nSetLevel) +: nLevel(nSetLevel) +, nStrategy(DEFAULT_STRATEGY) +, bFinish(sal_False) +, bFinished(sal_False) +, bSetParams(sal_False) +, nOffset(0) +, nLength(0) +{ + init(nSetLevel, DEFAULT_STRATEGY, sal_False); +} + +Deflater::Deflater(sal_Int16 nSetLevel, sal_Bool bNowrap) +: nLevel(nSetLevel) +, nStrategy(DEFAULT_STRATEGY) +, bFinish(sal_False) +, bFinished(sal_False) +, bSetParams(sal_False) +, nOffset(0) +, nLength(0) +{ + init(nSetLevel, DEFAULT_STRATEGY, bNowrap); +} + +sal_Int16 Deflater::doDeflateBytes (uno::Sequence < sal_Int8 > &rBuffer, sal_Int16 nNewOffset, sal_Int16 nNewLength) +{ + sal_Int16 nResult; + if (bSetParams) + { + nResult = z_deflateParams(pStream, nLevel, nStrategy); + bSetParams = sal_False; + } + pStream->next_in = (unsigned char*) sInBuffer.getConstArray(); + pStream->next_out = (unsigned char*) rBuffer.getArray()+nNewOffset; + pStream->avail_in = nLength; + pStream->avail_out = nNewLength; + + + nResult = z_deflate(pStream, Z_FINISH); + switch (nResult) + { + case Z_STREAM_END: + bFinished = sal_True; + case Z_OK: + nOffset += nLength - pStream->avail_in; + nLength = pStream->avail_in; + return nNewLength - pStream->avail_out; + case Z_BUF_ERROR: + bSetParams = sal_False; + DBG_ERROR( pStream->msg ); + return 0; + default: + DBG_ERROR( pStream->msg ); + return 0; + } + return 0; +} + +void SAL_CALL Deflater::setInputSegment( const uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) + throw(uno::RuntimeException) +{ + if (nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength()) + DBG_ERROR("Invalid parameters to Deflater::setInputSegment!"); + + sInBuffer = rBuffer; + nOffset = nNewOffset; + nLength = nNewLength; +} +void SAL_CALL Deflater::setInput( const uno::Sequence< sal_Int8 >& rBuffer ) + throw(uno::RuntimeException) +{ + sInBuffer = rBuffer; + nOffset = 0; + nLength = rBuffer.getLength(); +} +void SAL_CALL Deflater::setDictionarySegment( const uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) + throw(uno::RuntimeException) +{ + if (pStream == NULL) + { + // do error handling + DBG_ERROR("No stream!"); + } + if (nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength()) + { + // do error handling + } + sal_Int16 nResult = z_deflateSetDictionary(pStream, (const unsigned char*)rBuffer.getConstArray()+nOffset, nLength); +} +void SAL_CALL Deflater::setDictionary( const uno::Sequence< sal_Int8 >& rBuffer ) + throw(uno::RuntimeException) +{ + if (pStream == NULL) + { + // do error handling + DBG_ERROR("No stream!"); + + } + sal_Int16 nResult = z_deflateSetDictionary(pStream, (const unsigned char*)rBuffer.getConstArray(), rBuffer.getLength()); +} +void SAL_CALL Deflater::setStrategy( sal_Int32 nNewStrategy ) + throw(uno::RuntimeException) +{ + if (nNewStrategy != DEFAULT_STRATEGY && + nNewStrategy != FILTERED && + nNewStrategy != HUFFMAN_ONLY) + { + // do error handling + } + if (nStrategy != nNewStrategy) + { + nStrategy = nNewStrategy; + bSetParams = sal_True; + } +} +void SAL_CALL Deflater::setLevel( sal_Int32 nNewLevel ) + throw(uno::RuntimeException) +{ + if ((nNewLevel < 0 || nNewLevel > 9) && nNewLevel != DEFAULT_COMPRESSION) + { + // do error handling + } + if (nNewLevel != nLevel) + { + nLevel = nNewLevel; + bSetParams = sal_True; + } +} +sal_Bool SAL_CALL Deflater::needsInput( ) + throw(uno::RuntimeException) +{ + return nLength <=0; +} +void SAL_CALL Deflater::finish( ) + throw(uno::RuntimeException) +{ + bFinish = sal_True; +} +sal_Bool SAL_CALL Deflater::finished( ) + throw(uno::RuntimeException) +{ + return bFinished; +} +sal_Int32 SAL_CALL Deflater::doDeflateSegment( uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) + throw(uno::RuntimeException) +{ + if (nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength()) + { + // do error handling + } + return doDeflateBytes(rBuffer, nNewOffset, nNewLength); +} +sal_Int32 SAL_CALL Deflater::doDeflate( uno::Sequence< sal_Int8 >& rBuffer ) + throw(uno::RuntimeException) +{ + return doDeflateBytes(rBuffer, 0, rBuffer.getLength()); +} + +sal_Int32 SAL_CALL Deflater::getAdler( ) + throw(uno::RuntimeException) +{ + return pStream->adler; +} +sal_Int32 SAL_CALL Deflater::getTotalIn( ) + throw(uno::RuntimeException) +{ + return pStream->total_in; +} +sal_Int32 SAL_CALL Deflater::getTotalOut( ) + throw(uno::RuntimeException) +{ + return pStream->total_out; +} +void SAL_CALL Deflater::reset( ) + throw(uno::RuntimeException) +{ + z_deflateReset(pStream); + bFinish = sal_False; + bFinished = sal_False; + nOffset = nLength = 0; +} +void SAL_CALL Deflater::end( ) + throw(uno::RuntimeException) +{ + z_deflateEnd(pStream); + pStream = NULL; +} diff --git a/package/source/zipapi/EntryInputStream.cxx b/package/source/zipapi/EntryInputStream.cxx new file mode 100644 index 000000000000..a2f65288a7ef --- /dev/null +++ b/package/source/zipapi/EntryInputStream.cxx @@ -0,0 +1,188 @@ +/************************************************************************* + * + * $RCSfile: EntryInputStream.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _ENTRY_INPUT_STREAM_HXX +#include "EntryInputStream.hxx" +#endif + +#ifndef _COM_SUN_STAR_PACKAGE_ZIPCONSTANTS_HPP_ +#include <com/sun/star/package/ZipConstants.hpp> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +using namespace rtl; +using namespace com::sun::star; + +/** Provides access to the compressed data in a zipfile. Decompresses on the fly, but + * does not currently support XSeekable into the compressed data stream. + * Acts on the same underlying XInputStream as both the full Zip File and other + * EntryInputStreams, and thus must maintain its current position in the stream and + * seek to it before performing any reads. + */ + +EntryInputStream::EntryInputStream( uno::Reference < io::XInputStream > xNewInput, sal_Int64 nNewBegin, sal_Int64 nNewEnd, sal_Int32 nNewBufferSize) +: xStream(xNewInput) +, xSeek(xNewInput, uno::UNO_QUERY) +, nBegin(nNewBegin) +, nCurrent(nNewBegin) +, nEnd(nNewEnd) +, aSequence ( nNewBufferSize ) +, aInflater( sal_True ) +, nLength(0) +{ +} + +EntryInputStream::~EntryInputStream( void ) +{ +} +void EntryInputStream::fill(void) +{ + sal_Int32 nBytesToRead = aSequence.getLength(); + if (nBytesToRead + nCurrent> nEnd) + nBytesToRead = nEnd - nCurrent; + if (xSeek.is()) + xSeek->seek( nCurrent ); + else + throw (io::IOException()); + nLength = xStream->readBytes(aSequence, nBytesToRead); + aInflater.setInputSegment(aSequence, 0, nLength); +} +sal_Int32 SAL_CALL EntryInputStream::readBytes( uno::Sequence< sal_Int8 >& aData, + sal_Int32 nBytesToRead ) + throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) +{ + sal_Int32 n; + if (nBytesToRead <=0) + return 0; + while ( (n = aInflater.doInflate(aData)) == 0) + { + if (aInflater.finished() || aInflater.needsDictionary()) + { + bReachEOF = sal_True; + return -1; + } + if (aInflater.needsInput()) + fill(); + } + return n; + //return xStream->readBytes(aData, nBytesToRead ); +} +sal_Int32 SAL_CALL EntryInputStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, + sal_Int32 nMaxBytesToRead ) + throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) +{ + if (nMaxBytesToRead + nCurrent > nEnd) + { + if (nCurrent > nEnd) + return 0; + nMaxBytesToRead = nEnd - nCurrent; + } + if (xSeek.is()) + xSeek->seek( nCurrent ); + else + throw (io::IOException()); + return xStream->readSomeBytes( aData, nMaxBytesToRead ); +} +void SAL_CALL EntryInputStream::skipBytes( sal_Int32 nBytesToSkip ) + throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) +{ + if (nBytesToSkip + nCurrent> nEnd) + { + if (nCurrent> nEnd) + return; + nBytesToSkip = nEnd - nCurrent; + } + nCurrent+=nBytesToSkip; +} +sal_Int32 SAL_CALL EntryInputStream::available( ) + throw(io::NotConnectedException, io::IOException, uno::RuntimeException) +{ + return nEnd - nCurrent; +} +void SAL_CALL EntryInputStream::closeInput( ) + throw(io::NotConnectedException, io::IOException, uno::RuntimeException) +{ +} + + +sal_Int64 SAL_CALL EntryInputStream::seek( sal_Int64 location ) + throw(lang::IllegalArgumentException, io::IOException, uno::RuntimeException) +{ + if (location < nBegin) + location = nBegin; + if (location > nEnd) + location = nEnd; + nCurrent = location; + return nCurrent; +} +sal_Int64 SAL_CALL EntryInputStream::getPosition( ) + throw(io::IOException, uno::RuntimeException) +{ + return nCurrent; +} +sal_Int64 SAL_CALL EntryInputStream::getLength( ) + throw(io::IOException, uno::RuntimeException) +{ + return nEnd - nBegin; +} + diff --git a/package/source/zipapi/Inflater.cxx b/package/source/zipapi/Inflater.cxx new file mode 100644 index 000000000000..f7f9501ad6ac --- /dev/null +++ b/package/source/zipapi/Inflater.cxx @@ -0,0 +1,268 @@ +/************************************************************************* + * + * $RCSfile: Inflater.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _INFLATER_HXX_ +#include "Inflater.hxx" +#endif + +#include <iostream.h> +#include <string.h> + +/** Provides general purpose decompression using the ZLIB library */ +void Inflater::init (sal_Bool bNowrap) +{ + pStream = new z_stream; + /* memset to 0 to set zalloc/opaque etc */ + memset (pStream, 0, sizeof(*pStream)); + sal_Int16 nRes; + nRes = inflateInit2(pStream, bNowrap ? -MAX_WBITS : MAX_WBITS); + switch (nRes) + { + case Z_OK: + break; + case Z_MEM_ERROR: + DBG_ERROR ( pStream->msg); + delete pStream; + break; + case Z_STREAM_ERROR: + DBG_ERROR ( pStream->msg); + delete pStream; + break; + default: + DBG_ERROR ( pStream->msg); + break; + } +} + +Inflater::Inflater(sal_Bool bNoWrap) +: bFinish(sal_False), + bFinished(sal_False), + bSetParams(sal_False), + bNeedDict(sal_False), + nOffset(0), + nLength(0), + pStream(NULL) +{ + init(bNoWrap); +} + +Inflater::Inflater() +: bFinish(sal_False), + bFinished(sal_False), + bSetParams(sal_False), + bNeedDict(sal_False), + nOffset(0), + nLength(0), + pStream(NULL) +{ + init(sal_False); +} +Inflater::~Inflater() +{ + if (pStream) + delete pStream; +} +void SAL_CALL Inflater::setInputSegment( const com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) + throw(com::sun::star::uno::RuntimeException) +{ + sInBuffer = rBuffer; + nOffset = nNewOffset; + nLength = nNewLength; +} + +void SAL_CALL Inflater::setInput( const com::sun::star::uno::Sequence< sal_Int8 >& rBuffer ) + throw(com::sun::star::uno::RuntimeException) +{ + sInBuffer = rBuffer; + nOffset = 0; + nLength = rBuffer.getLength(); +} + +void SAL_CALL Inflater::setDictionarySegment( const com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) + throw(com::sun::star::uno::RuntimeException) +{ + if (pStream == NULL) + { + // do error handling + } + if (nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength()) + { + // do error handling + } + z_inflateSetDictionary(pStream, (const unsigned char*)rBuffer.getConstArray() + nNewOffset, + nNewLength); +} + +void SAL_CALL Inflater::setDictionary( const com::sun::star::uno::Sequence< sal_Int8 >& rBuffer ) + throw(com::sun::star::uno::RuntimeException) +{ + if (pStream == NULL) + { + // do error handling + } + z_inflateSetDictionary(pStream, (const unsigned char*)rBuffer.getConstArray(), + rBuffer.getLength()); +} + +sal_Int32 SAL_CALL Inflater::getRemaining( ) + throw(com::sun::star::uno::RuntimeException) +{ + return nLength; +} + +sal_Bool SAL_CALL Inflater::needsInput( ) + throw(com::sun::star::uno::RuntimeException) +{ + return nLength <=0; +} + +sal_Bool SAL_CALL Inflater::needsDictionary( ) + throw(com::sun::star::uno::RuntimeException) +{ + return bNeedDict; +} + +sal_Bool SAL_CALL Inflater::finished( ) + throw(com::sun::star::uno::RuntimeException) +{ + return bFinished; +} + +sal_Int32 SAL_CALL Inflater::doInflateSegment( com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) + throw(com::sun::star::uno::RuntimeException) +{ + if (nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength()) + { + // do error handling + } + return doInflateBytes(rBuffer, nNewOffset, nNewLength); +} + +sal_Int32 SAL_CALL Inflater::doInflate( com::sun::star::uno::Sequence< sal_Int8 >& rBuffer ) + throw(com::sun::star::uno::RuntimeException) +{ + return doInflateBytes(rBuffer, 0, rBuffer.getLength()); +} + +sal_Int32 SAL_CALL Inflater::getAdler( ) + throw(com::sun::star::uno::RuntimeException) +{ + return pStream->adler; +} + +sal_Int32 SAL_CALL Inflater::getTotalIn( ) + throw(com::sun::star::uno::RuntimeException) +{ + return pStream->total_in; +} + +sal_Int32 SAL_CALL Inflater::getTotalOut( ) + throw(com::sun::star::uno::RuntimeException) +{ + return pStream->total_out; +} + +void SAL_CALL Inflater::reset( ) + throw(com::sun::star::uno::RuntimeException) +{ + z_inflateReset(pStream); + bNeedDict = sal_False; + bFinished = sal_False; + nOffset = nLength = 0; +} + +void SAL_CALL Inflater::end( ) + throw(com::sun::star::uno::RuntimeException) +{ + z_inflateEnd(pStream); + pStream = NULL; +} + +sal_Int16 Inflater::doInflateBytes (com::sun::star::uno::Sequence < sal_Int8 > &rBuffer, sal_Int16 nNewOffset, sal_Int16 nNewLength) +{ + sal_Int16 nResult; + pStream->next_in = (unsigned char*) sInBuffer.getConstArray()+ nOffset; + pStream->avail_in = nLength; + pStream->next_out = (unsigned char*) rBuffer.getArray() + nNewOffset; + pStream->avail_out = nNewLength; + + nResult = ::z_inflate(pStream, Z_PARTIAL_FLUSH); + + switch (nResult) + { + case Z_STREAM_END: + bFinished = sal_True; + case Z_OK: + nOffset += nLength - pStream->avail_in; + nLength = pStream->avail_in; + return nLength - pStream->avail_out; + case Z_NEED_DICT: + bNeedDict = sal_True; + nOffset += nLength - pStream->avail_in; + nLength = pStream->avail_in; + case Z_BUF_ERROR: + return 0; + case Z_DATA_ERROR: + DBG_ERROR(pStream->msg); + return 0; + } + return 0; +} + diff --git a/package/source/zipapi/ZipEnumeration.cxx b/package/source/zipapi/ZipEnumeration.cxx new file mode 100644 index 000000000000..467f8d48798f --- /dev/null +++ b/package/source/zipapi/ZipEnumeration.cxx @@ -0,0 +1,105 @@ +/************************************************************************* + * + * $RCSfile: ZipEnumeration.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _ZIP_ENUMERATION_HXX +#include "ZipEnumeration.hxx" +#endif + +#ifndef _COM_SUN_STAR_PACKAGE_ZIPCONSTANTS_HPP_ +#include <com/sun/star/package/ZipConstants.hpp> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +#include <iostream.h> +using namespace rtl; +using namespace com::sun::star; + +/** Provides an Enumeration over the contents of a Zip file */ + +ZipEnumeration::ZipEnumeration( uno::Sequence< package::ZipEntry > &xList) +: nCurrent(0) +{ + xZipList = xList; +} +ZipEnumeration::ZipEnumeration( ) +: nCurrent(0) +{ +} + +ZipEnumeration::~ZipEnumeration( void ) +{ +} +sal_Bool SAL_CALL ZipEnumeration::hasMoreElements() throw (uno::RuntimeException) +{ + return (nCurrent < xZipList.getLength()); +} + +uno::Any SAL_CALL ZipEnumeration::nextElement() throw (uno::RuntimeException) +{ + if (hasMoreElements() == sal_False) + throw (container::NoSuchElementException() ); + uno::Any aElement; + //aElement <<= uno::Reference < package::ZipEntry > (static_cast <package::ZipEntry > (xZipList[nCurrent++])); + aElement <<= xZipList[nCurrent++]; + return aElement; +} diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx new file mode 100644 index 000000000000..3d4d9335fd08 --- /dev/null +++ b/package/source/zipapi/ZipFile.cxx @@ -0,0 +1,483 @@ +/************************************************************************* + * + * $RCSfile: ZipFile.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _ZIP_FILE_HXX +#include "ZipFile.hxx" +#endif + +#ifndef _ZIP_ENUMERATION_HXX +#include "ZipEnumeration.hxx" +#endif + +#ifndef _COM_SUN_STAR_PACKAGE_ZIPCONSTANTS_HPP_ +#include <com/sun/star/package/ZipConstants.hpp> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +#ifndef _RTL_BYTESEQ_HXX_ +#include <rtl/byteseq.hxx> +#endif + +#include <string.h> + +using namespace rtl; +using namespace com::sun::star; +using namespace com::sun::star::package::ZipConstants; + +/** This class is used to read entries from a zip file + */ +ZipFile::ZipFile (uno::Reference < io::XInputStream > &xInput) +: xStream(xInput) +, aGrabber(xInput) +, pEntries(NULL) +, pTable(NULL) +, nTotal(0) +, nTableLen(0) +{ + readCEN(); +} + +/* +ZipFile::ZipFile( void ) +:pEntries(NULL) +, pTable(NULL) +, nTotal(0) +, nTableLen(0) +{ +} +void SAL_CALL ZipFile::setInputStream( const uno::Reference< io::XInputStream >& xInput ) + throw(io::IOException, package::ZipException, uno::RuntimeException) +{ + xStream = uno::Reference <io::XInputStream> (xInput); + aGrabber.setInputStream ( xInput ); + readCEN(); +} +*/ + +//ZipFile::ZipFile (const uno::Reference < lang::XMultiServiceFactory > &xFactory) +//{ +//} +ZipFile::~ZipFile() +{ + if (pEntries != NULL) + delete []pEntries; + if (pTable != NULL) + { + ZipEntryImpl* pTmp = NULL; + for (int i =0; i < nTableLen; i++) + { + while ((pTmp = pTable[i]) != NULL) + { + pTable[i] = pTmp->pNext; + delete pTmp; + } + } + delete []pTable; + } + +} +void ZipFile::close() +{ +} + +uno::Reference<container::XEnumeration> ZipFile::entries() +{ + uno::Reference< container::XEnumeration> xEnumRef; + xEnumRef= new ZipEnumeration( uno::Sequence < package::ZipEntry > (pEntries, nTotal) ); + //xEnumRef = uno::Reference < container::XEnumeration>( (OWeakObject*) pEnum, uno::UNO_QUERY ); +// xEnumRef = uno::Reference < container::XEnumeration>( static_cast < container::XEnumeration *> (pEnum), uno::UNO_QUERY ); + return xEnumRef; +} +::rtl::OUString ZipFile::getName() +{ + return sName; +} +sal_Int32 ZipFile::getSize() +{ + return nTotal; +} + +uno::Type ZipFile::getElementType() +{ + return ::getCppuType((package::ZipEntry *) 0); +} +sal_Bool ZipFile::hasElements() +{ + return (nTotal>0); +} + +uno::Any ZipFile::getByName(const ::rtl::OUString& rName) +{ + uno::Any aAny; + sal_Int32 nHash = abs(rName.hashCode() % nTableLen); + ZipEntryImpl * pEntry = pTable[nHash]; + while (pEntry != NULL) + { + if (rName == pEntry->getName()) + { + //uno::Reference < package::ZepEntry > xEntry = pEntry; + aAny <<= *(pEntry->pEntry); + return aAny; + } + pEntry = pEntry->pNext; + } + throw container::NoSuchElementException(); + return aAny; +} +uno::Sequence<rtl::OUString> ZipFile::getElementNames() +{ + OUString *pNames = new OUString[nTotal]; + for (int i = 0; i < nTotal; i++) + pNames[i] = pEntries[i].sName; + return uno::Sequence<OUString> (pNames, nTotal); +} +sal_Bool ZipFile::hasByName(const ::rtl::OUString& rName) +{ + sal_Int32 nHash = abs(rName.hashCode() % nTableLen); + ZipEntryImpl * pEntry = pTable[nHash]; + while (pEntry != NULL) + { + if (rName == pEntry->getName()) + return sal_True; + pEntry = pEntry->pNext; + } + return sal_False; +} +uno::Reference< io::XInputStream> ZipFile::getInputStream(const package::ZipEntry& rEntry) +{ + sal_Int64 nEnd = rEntry.nCompressedSize == 0 ? rEntry.nSize : rEntry.nCompressedSize; + if (rEntry.nOffset <= 0) + readLOC(rEntry); + sal_Int64 nBegin = rEntry.nOffset; + nEnd +=nBegin; + + uno::Reference< io::XInputStream > xStreamRef = new EntryInputStream(xStream, nBegin, nEnd, 1024); + return xStreamRef; +} +sal_Bool ZipFile::readLOC(const package::ZipEntry &rEntry) +{ + sal_uInt32 nTestSig, nTime, nCRC, nSize, nCompressedSize; + sal_uInt16 nVersion, nFlag, nHow, nNameLen, nExtraLen; + sal_Int32 nPos = -rEntry.nOffset; + + aGrabber.seek(nPos); + aGrabber >> nTestSig; + + if (nTestSig != LOCSIG) + { + DBG_ERROR ("Invalid LOC header (bad signature)"); + return sal_False; + } + aGrabber >> nVersion; + aGrabber >> nFlag; + aGrabber >> nHow; + aGrabber >> nTime; + aGrabber >> nCRC; + aGrabber >> nCompressedSize; + aGrabber >> nSize; + aGrabber >> nNameLen; + aGrabber >> nExtraLen; + package::ZipEntry *pNonConstEntry = const_cast < package::ZipEntry* > (&rEntry); + pNonConstEntry->nOffset = aGrabber.getPosition() + nNameLen + nExtraLen; + return sal_True; + +/* + ZipEntryImpl *pEntry = new ZipEntryImpl(); + + sal_Char * pTmpName = new sal_Char[nNameLen]; + xStream.Read(pTmpName, nNameLen); + pEntry->sName = ByteSequence( pTmpName, nNameLen, RTL_TEXTENCODING_ASCII_US); + delete [] pTmpName; + + sal_Char * pTmpExtra = new sal_Char[nExtraLen]; + xStream.Read(pTmpExtra, nExtraLen); + pEntry->sExtra = ByteSequence(pTmpExtra, nExtraLen); + delete [] pTmpExtra; + + pEntry->sComment = pComments[pCell->nIndex]; + pEntry->nSize = pCell->nSize; + pEntry->nCompressedSize = pCell->nCompressedSize; + pEntry->nCRC = pCell->nCRC; + pEntry->nTime = nTime; + pEntry->nMethod = nHow; + pEntry->nPos = pCell->nPos + LOCHDR + nNameLen + nExtraLen; + return pEntry; +*/ +} + + +sal_Int32 ZipFile::findEND( ) +{ + ULONG nLength=0, nPos=0; + ByteSequence aByteSeq; + nLength = nPos = aGrabber.getLength(); + aGrabber.seek( nLength ); + + while (nLength - nPos < 0xFFFF) + { + ULONG nCount = 0xFFFF - ( nLength - nPos); + if (nCount > ENDHDR) + nCount = ENDHDR; + nPos -= nCount; + + for (sal_uInt16 i=0; i <nCount;i++) + { + sal_uInt32 nTest=0, nFoo=ENDSIG; + aGrabber.seek (nPos+i); + aGrabber >> nTest; + if (nTest == ENDSIG) + { + sal_uInt16 nCommentLength; + sal_uInt32 nEndPos = nPos + i; + aGrabber.seek(nEndPos+ENDCOM); + aGrabber >> nCommentLength; + if (nEndPos + ENDHDR + nCommentLength == nLength) + { + if (nCommentLength>0) + { + aByteSeq.realloc(nCommentLength+1); + aGrabber.readBytes(uno::Sequence< sal_Int8>(aByteSeq.getArray(), nCommentLength), nCommentLength); + aByteSeq[nCommentLength]='\0'; + sComment = OUString((sal_Char*)aByteSeq.getConstArray(), nCommentLength+1, RTL_TEXTENCODING_ASCII_US); + + } + return nPos + i; + } + } + } + } + return -1; +} + +#if 0 +sal_Bool ZipFile::isMetaName( ByteSequence &rName) +{ + ByteSequence sTemp = rName.toUpperCase(); + if (sTemp.compareToAscii( "META_INF/", 9) == 0) + return sal_True; + return sal_False; + +} +void ZipFile::addMetaName( ByteSequence &rName ) +{ + aMetaNames.Insert (new String(rName)); +} + + +void ZipFile::addEntryComment( int nIndex, ByteSequence &rComment) +{ + if (pComments == NULL) + pComments = new ByteSequence[nTotal]; + pComments[nIndex]=rComment; +} +#endif + +sal_Int32 ZipFile::readCEN() +{ + sal_uInt32 nEndPos, nLocPos; + sal_Int16 nCount; + sal_uInt32 nCenLen, nCenPos, nCenOff; + + nEndPos = findEND(); + aGrabber.seek(nEndPos + ENDTOT); + aGrabber >> nTotal; + aGrabber >> nCenLen; + aGrabber >> nCenOff; + + if (nTotal<0 || nTotal * CENHDR > nCenLen) + { + DBG_ERROR("invalid END header (bad entry count)"); + return -1; + } + if (nTotal > ZIP_MAXENTRIES) + { + DBG_ERROR("too many entries in ZIP File"); + return -1; + } + + //aGrabber.seek(nEndPos+ENDSIZ); + + + if (nCenLen < 0 || nCenLen > nEndPos) + { + DBG_ERROR ("invalid END header (bad central directory size)"); + return -1; + } + nCenPos = nEndPos - nCenLen; + + if (nCenOff < 0 || nCenOff > nCenPos) + { + DBG_ERROR("invalid END header (bad central directory size)"); + return -1; + } + nLocPos = nCenPos - nCenOff; + + aGrabber.seek(nCenPos); + + pEntries = new package::ZipEntry[nTotal]; + nTableLen = nTotal * 2; + pTable = new ZipEntryImpl*[nTableLen]; + memset(pTable, 0, sizeof (ZipEntryImpl*) * nTableLen); + + for (nCount = 0 ; nCount < nTotal; nCount++) + { + package::ZipEntry *pEntry = &pEntries[nCount]; + sal_Int32 nTestSig, nCRC, nCompressedSize, nTime, nSize, nExtAttr, nOffset; + sal_Int16 nVerMade, nVersion, nFlag, nHow, nNameLen, nExtraLen, nCommentLen; + sal_Int16 nDisk, nIntAttr; + if (aGrabber.getPosition() - nCenPos + CENHDR > nCenLen) + { + DBG_ERROR("invalid CEN header (bad header size check 1"); + break; + } + aGrabber >> nTestSig; + if (nTestSig != CENSIG) + { + DBG_ERROR ("invalid CEN header (bad signature)"); + break; + } + aGrabber >> nVerMade; + aGrabber >> nVersion; + if ((nVersion & 1) == 1) + { + DBG_ERROR ( "invalid CEN header (encrypted entry)"); + break; + } + aGrabber >> nFlag; + aGrabber >> nHow; + if (nHow != STORED && nHow != DEFLATED) + { + DBG_ERROR ( "invalid CEN header (bad compression method)"); + break; + } + aGrabber >> nTime; + aGrabber >> nCRC; + aGrabber >> nCompressedSize; + aGrabber >> nSize; + aGrabber >> nNameLen; + aGrabber >> nExtraLen; + aGrabber >> nCommentLen; + aGrabber >> nDisk; + aGrabber >> nIntAttr; + aGrabber >> nExtAttr; + aGrabber >> nOffset; + + if (aGrabber.getPosition() - nCenPos + nNameLen + nExtraLen + nCommentLen > nCenLen) + { + DBG_ERROR ( "invalid CEN header (bad header size check 2)"); + break; + } + if (nNameLen > ZIP_MAXNAMELEN) + { + DBG_ERROR ( "name length exceeds 512 bytes"); + break; + } + if (nExtraLen > ZIP_MAXEXTRA) + { + DBG_ERROR ( "extra header info exceeds 256 bytes"); + break; + } + + pEntry->nTime = nTime; + pEntry->nCrc = nCRC; + pEntry->nSize = nSize; + pEntry->nCompressedSize = nCompressedSize; + pEntry->nMethod = nHow; + pEntry->nFlag = nFlag; + pEntry->nVersion= nVersion; + pEntry->nOffset = nOffset + nLocPos; + + pEntry->nOffset *= -1; + + if (nHow == STORED) + pEntry->nCompressedSize = 0; + + uno::Sequence < sal_Int8> aSequence (nNameLen); + aGrabber.readBytes(aSequence, nNameLen); + pEntry->sName = OUString((sal_Char*)aSequence.getConstArray(), nNameLen, RTL_TEXTENCODING_ASCII_US); + + aGrabber.seek(aGrabber.getPosition() + nExtraLen); + if (nCommentLen>0) + { + uno::Sequence < sal_Int8 > aCommentSeq( nCommentLen ); + aGrabber.readBytes(aCommentSeq, nCommentLen); + pEntry->sComment = OUString((sal_Char*)aCommentSeq.getConstArray(), nNameLen, RTL_TEXTENCODING_ASCII_US); + } + sal_Int32 nHash = abs(pEntry->sName.hashCode() % nTableLen); + ZipEntryImpl* pTmp = new ZipEntryImpl(); + pTmp->pEntry = pEntry; + pTmp->pNext = pTable[nHash]; + pTable[nHash] = pTmp; + /*pEntry->pNext = pTable[nHash]; + pTable[nHash] = pEntry;*/ + } + + if (nCount != nTotal) + { + DBG_ERROR("Count != total!"); + return -1; + } + return nCenPos; +} + + diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx new file mode 100644 index 000000000000..fa5e8ac5b2d8 --- /dev/null +++ b/package/source/zipapi/ZipOutputStream.cxx @@ -0,0 +1,356 @@ +/************************************************************************* + * + * $RCSfile: ZipOutputStream.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _ZIP_OUTPUT_STREAM_HXX +#include "ZipOutputStream.hxx" +#endif + +using namespace rtl; +using namespace com::sun::star; +using namespace com::sun::star::package::ZipConstants; + +/** This class is used to write Zip files + */ +ZipOutputStream::ZipOutputStream( uno::Reference < io::XOutputStream > &xOStream, sal_Int32 nNewBufferSize) +: xStream(xOStream) +, aChucker(xOStream) +, nMethod(DEFLATED) +, pCurrentEntry(NULL) +, bFinished(sal_False) +, aBuffer(nNewBufferSize) +, aDeflater(DEFAULT_COMPRESSION, sal_True) +{ +} + +ZipOutputStream::~ZipOutputStream( void ) +{ +} + +void SAL_CALL ZipOutputStream::setComment( const ::rtl::OUString& rComment ) + throw(uno::RuntimeException) +{ + sComment = rComment; +} +void SAL_CALL ZipOutputStream::setMethod( sal_Int32 nNewMethod ) + throw(uno::RuntimeException) +{ + nMethod = nNewMethod; +} +void SAL_CALL ZipOutputStream::setLevel( sal_Int32 nNewLevel ) + throw(uno::RuntimeException) +{ + aDeflater.setLevel( nNewLevel); +} +void SAL_CALL ZipOutputStream::putNextEntry( const package::ZipEntry& rEntry ) + throw(io::IOException, uno::RuntimeException) +{ + package::ZipEntry *pNonConstEntry = const_cast < package::ZipEntry* >(&rEntry); + if (pCurrentEntry != NULL) + closeEntry(); + if (pNonConstEntry->nTime == -1) + { + Time aTime; + aTime = Time(); + pNonConstEntry->nTime = aTime.GetTime(); + } + if (pNonConstEntry->nMethod == -1) + { + pNonConstEntry->nMethod = nMethod; + } + switch (pNonConstEntry->nMethod) + { + case DEFLATED: + if (pNonConstEntry->nSize == -1 || pNonConstEntry->nCompressedSize == -1 || + pNonConstEntry->nCrc == -1) + pNonConstEntry->nFlag = 8; + else if (pNonConstEntry->nSize != -1 && pNonConstEntry->nCompressedSize != -1 && + pNonConstEntry->nCrc != -1) + pNonConstEntry->nFlag=0; + pNonConstEntry->nVersion = 20; + break; + case STORED: + if (pNonConstEntry->nSize == -1) + pNonConstEntry->nSize = pNonConstEntry->nCompressedSize; + else if (pNonConstEntry->nCompressedSize == -1) + pNonConstEntry->nCompressedSize = pNonConstEntry->nSize; + pNonConstEntry->nVersion = 10; + pNonConstEntry->nFlag = 0; + break; + } + pNonConstEntry->nOffset = aChucker.getPosition(); + writeLOC(rEntry); + aZipList.push_back(pNonConstEntry); + pCurrentEntry=pNonConstEntry; +} +void SAL_CALL ZipOutputStream::close( ) + throw(io::IOException, uno::RuntimeException) +{ + finish(); +} + +void SAL_CALL ZipOutputStream::closeEntry( ) + throw(io::IOException, uno::RuntimeException) +{ + package::ZipEntry *pEntry = pCurrentEntry; + if (pEntry) + { + switch (pEntry->nMethod) + { + case DEFLATED: + aDeflater.finish(); + while (!aDeflater.finished()) + doDeflate(); + if ((pEntry->nFlag & 8) == 0) + { + if (pEntry->nSize != aDeflater.getTotalIn()) + { + // boom + DBG_ERROR("Invalid entry size"); + } + if (pEntry->nCompressedSize != aDeflater.getTotalOut()) + { + // boom + DBG_ERROR("Invalid entry compressed size"); + } + if (pEntry->nCrc != aCRC.getValue()) + { + // boom + DBG_ERROR("Invalid entry CRC-32"); + } + } + else + { + pEntry->nSize = aDeflater.getTotalIn(); + pEntry->nCompressedSize = aDeflater.getTotalOut(); + pEntry->nCrc = aCRC.getValue(); + writeEXT(*pEntry); + } + aDeflater.reset(); + break; + case STORED: + if (pEntry->nCrc != aCRC.getValue()) + { + // boom + DBG_ERROR("Invalid entry crc32"); + } + break; + default: + // boom; + DBG_ERROR("Invalid compression method"); + break; + } + aCRC.reset(); + pCurrentEntry = NULL; + } +} + +void SAL_CALL ZipOutputStream::write( const uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ) + throw(io::IOException, uno::RuntimeException) +{ + switch (pCurrentEntry->nMethod) + { + case DEFLATED: + if (!aDeflater.finished()) + { + aDeflater.setInputSegment(rBuffer, nNewOffset, nNewLength); + while (!aDeflater.needsInput()) + doDeflate(); + } + break; + case STORED: + aChucker.writeBytes(rBuffer); + break; + } + aCRC.updateSegment(rBuffer, nNewOffset, nNewLength); +} +void SAL_CALL ZipOutputStream::finish( ) + throw(io::IOException, uno::RuntimeException) +{ + if (bFinished) + return; + if (pCurrentEntry != NULL) + closeEntry(); + if (aZipList.size() < 1) + { + // boom + DBG_ERROR("Zip file must have at least one entry!\n"); + } + sal_Int32 nOffset= aChucker.getPosition(); + for (int i =0, nEnd = aZipList.size(); i < nEnd; i++) + writeCEN(*aZipList[i]); + writeEND( nOffset, aChucker.getPosition() - nOffset); + bFinished = sal_True; +} +void ZipOutputStream::doDeflate() +{ + sal_Int16 nLength = aDeflater.doDeflateSegment(aBuffer, 0, aBuffer.getLength()); + if (nLength > 0 ) + { + aChucker.writeBytes(aBuffer); + } +} +void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength) +{ + sal_Int16 i=0, nCommentLength = sComment.getLength(); + const sal_Unicode *pChar = sComment.getStr(); + uno::Sequence < sal_Int8 > aSequence (nCommentLength); + for ( ; i < nCommentLength; i++) + { + DBG_ASSERT (pChar[i] <127, "Non US ASCII character in zipfile comment!"); + aSequence[i] = static_cast < const sal_Int8 > (pChar[i]); + } + aChucker << ENDSIG; + aChucker << static_cast < sal_Int16 > ( 0 ); + aChucker << static_cast < sal_Int16 > ( 0 ); + aChucker << static_cast < sal_Int16 > ( aZipList.size() ); + aChucker << static_cast < sal_Int16 > ( aZipList.size() ); + aChucker << nLength; + aChucker << nOffset; + aChucker << nCommentLength; + if (nCommentLength) + aChucker.writeBytes(aSequence); +} +void ZipOutputStream::writeCEN( const package::ZipEntry &rEntry ) +{ + sal_Int16 nNameLength = rEntry.sName.getLength(), + nCommentLength = rEntry.sName.getLength(), + nExtraLength = rEntry.extra.getLength(), i = 0; + + aChucker << CENSIG; + aChucker << rEntry.nVersion; + aChucker << rEntry.nVersion; + aChucker << rEntry.nFlag; + aChucker << rEntry.nMethod; + aChucker << rEntry.nTime; + aChucker << static_cast < sal_uInt32> (rEntry.nCrc); + aChucker << rEntry.nCompressedSize; + aChucker << rEntry.nSize; + aChucker << nNameLength; + aChucker << nExtraLength; + aChucker << nCommentLength; + aChucker << static_cast < sal_Int16> (0); + aChucker << static_cast < sal_Int16> (0); + aChucker << static_cast < sal_Int32> (0); + aChucker << rEntry.nOffset; + + const sal_Unicode *pChar = rEntry.sName.getStr(); + uno::Sequence < sal_Int8 > aSequence (nNameLength); + for ( ; i < nNameLength; i++) + { + DBG_ASSERT (pChar[i] <127, "Non US ASCII character in zipentry name!"); + aSequence[i] = static_cast < const sal_Int8 > (pChar[i]); + } + + aChucker.writeBytes( aSequence ); + if (nExtraLength) + aChucker.writeBytes( rEntry.extra); + if (nCommentLength) + { + aSequence.realloc (nCommentLength); + for (i=0, pChar = rEntry.sName.getStr(); i < nCommentLength; i++) + { + DBG_ASSERT (pChar[i] <127, "Non US ASCII character in zipentry comment!"); + aSequence[i] = static_cast < const sal_Int8 > (pChar[i]); + } + aChucker.writeBytes( aSequence ); + } +} +void ZipOutputStream::writeEXT( const package::ZipEntry &rEntry ) +{ + aChucker << EXTSIG; + aChucker << rEntry.nCrc; + aChucker << rEntry.nCompressedSize; + aChucker << rEntry.nSize; +} + +void ZipOutputStream::writeLOC( const package::ZipEntry &rEntry ) +{ + sal_Int16 nNameLength = rEntry.sName.getLength(), i=0; + aChucker << LOCSIG; + aChucker << rEntry.nVersion; + aChucker << rEntry.nFlag; + aChucker << rEntry.nMethod; + aChucker << rEntry.nTime; + if ((rEntry.nFlag & 8) == 8 ) + { + aChucker << static_cast < sal_Int32 > (0); + aChucker << static_cast < sal_Int32 > (0); + aChucker << static_cast < sal_Int32 > (0); + } + else + { + aChucker << static_cast < sal_uInt32 > (rEntry.nCrc); + aChucker << rEntry.nCompressedSize; + aChucker << rEntry.nSize; + } + aChucker << nNameLength; + aChucker << static_cast <sal_Int16 > ( rEntry.extra.getLength()); + + const sal_Unicode *pChar = rEntry.sName.getStr(); + uno::Sequence < sal_Int8 > aSequence (nNameLength); + for ( ; i < nNameLength; i++) + { + DBG_ASSERT (pChar[i] <127, "Non US ASCII character in zipentry name!"); + aSequence[i] = static_cast < const sal_Int8 > (pChar[i]); + } + aChucker.writeBytes( aSequence ); + if (rEntry.extra.getLength() != 0) + aChucker.writeBytes( rEntry.extra ); +} diff --git a/package/source/zipapi/makefile.mk b/package/source/zipapi/makefile.mk new file mode 100644 index 000000000000..a0b55b0aa85e --- /dev/null +++ b/package/source/zipapi/makefile.mk @@ -0,0 +1,115 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=package +TARGET=zipapi +AUTOSEG=true + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +# --- Files -------------------------------------------------------- + +SLOFILES= \ + $(SLO)$/Adler32.obj \ + $(SLO)$/CRC32.obj \ + $(SLO)$/ByteChucker.obj \ + $(SLO)$/ByteGrabber.obj \ + $(SLO)$/Inflater.obj \ + $(SLO)$/Deflater.obj \ + $(SLO)$/ZipEnumeration.obj \ + $(SLO)$/ZipFile.obj \ + $(SLO)$/ZipOutputStream.obj \ + $(SLO)$/EntryInputStream.obj \ + +# --- UNO stuff --------------------------------------------------- + +CPPUMAKERFLAGS= +#UNOUCROUT=$(OUT)$/inc +#INCPRE+=$(UNOUCROUT) + +UNOUCRDEP= $(SOLARBINDIR)$/applicat.rdb +UNOUCRRDB= $(SOLARBINDIR)$/applicat.rdb + +UNOTYPES=\ + com.sun.star.package.* \ + com.sun.star.io.XSeekable \ + com.sun.star.io.XOutputStream \ + com.sun.star.lang.XInitialization \ + com.sun.star.container.XHierarchicalNameAccess \ + com.sun.star.lang.XSingleServiceFactory \ + com.sun.star.util.XChangesBatch \ + com.sun.star.container.XEnumeration \ + com.sun.star.container.XNamed \ + com.sun.star.container.XNameContainer \ + com.sun.star.container.XEnumerationAccess \ + com.sun.star.io.XActiveDataSink \ + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk |