diff options
Diffstat (limited to 'package/inc')
23 files changed, 2041 insertions, 0 deletions
diff --git a/package/inc/ByteChucker.hxx b/package/inc/ByteChucker.hxx new file mode 100644 index 000000000..707b678ff --- /dev/null +++ b/package/inc/ByteChucker.hxx @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_BYTECHUCKER_HXX +#define INCLUDED_PACKAGE_INC_BYTECHUCKER_HXX + +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/uno/Reference.h> + +namespace com::sun::star { + namespace io { class XSeekable; class XOutputStream; } +} +class ByteChucker final +{ + css::uno::Reference < css::io::XOutputStream > xStream; + css::uno::Reference < css::io::XSeekable > xSeek; + css::uno::Sequence < sal_Int8 > a2Sequence, a4Sequence; + sal_Int8 * const p2Sequence, * const p4Sequence; + +public: + ByteChucker (css::uno::Reference<css::io::XOutputStream> const & xOstream); + ~ByteChucker(); + + /// @throws css::io::NotConnectedException + /// @throws css::io::BufferSizeExceededException + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + void WriteBytes( const css::uno::Sequence< sal_Int8 >& aData ); + + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + sal_Int64 GetPosition(); + + void WriteInt16(sal_Int16 nInt16) + { + p2Sequence[0] = static_cast< sal_Int8 >((nInt16 >> 0 ) & 0xFF); + p2Sequence[1] = static_cast< sal_Int8 >((nInt16 >> 8 ) & 0xFF); + WriteBytes( a2Sequence ); + } + + void WriteInt32(sal_Int32 nInt32) + { + p4Sequence[0] = static_cast< sal_Int8 >((nInt32 >> 0 ) & 0xFF); + p4Sequence[1] = static_cast< sal_Int8 >((nInt32 >> 8 ) & 0xFF); + p4Sequence[2] = static_cast< sal_Int8 >((nInt32 >> 16 ) & 0xFF); + p4Sequence[3] = static_cast< sal_Int8 >((nInt32 >> 24 ) & 0xFF); + WriteBytes( a4Sequence ); + } + + void WriteUInt32(sal_uInt32 nuInt32) + { + p4Sequence[0] = static_cast < sal_Int8 > ((nuInt32 >> 0 ) & 0xFF); + p4Sequence[1] = static_cast < sal_Int8 > ((nuInt32 >> 8 ) & 0xFF); + p4Sequence[2] = static_cast < sal_Int8 > ((nuInt32 >> 16 ) & 0xFF); + p4Sequence[3] = static_cast < sal_Int8 > ((nuInt32 >> 24 ) & 0xFF); + WriteBytes( a4Sequence ); + } +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/ByteGrabber.hxx b/package/inc/ByteGrabber.hxx new file mode 100644 index 000000000..ba1512cf5 --- /dev/null +++ b/package/inc/ByteGrabber.hxx @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_BYTEGRABBER_HXX +#define INCLUDED_PACKAGE_INC_BYTEGRABBER_HXX + +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/uno/Reference.h> + +#include <mutex> + +namespace com::sun::star { + namespace io { class XSeekable; class XInputStream; } +} +class ByteGrabber final +{ + std::mutex m_aMutex; + + css::uno::Reference < css::io::XInputStream > xStream; + css::uno::Reference < css::io::XSeekable > xSeek; + css::uno::Sequence < sal_Int8 > aSequence; + const sal_Int8 *pSequence; + +public: + ByteGrabber (css::uno::Reference < css::io::XInputStream > const & xIstream); + ~ByteGrabber(); + + void setInputStream (const css::uno::Reference < css::io::XInputStream >& xNewStream); + // XInputStream + /// @throws css::io::NotConnectedException + /// @throws css::io::BufferSizeExceededException + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + sal_Int32 readBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ); + // XSeekable + /// @throws css::lang::IllegalArgumentException + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + void seek( sal_Int64 location ); + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + sal_Int64 getPosition( ); + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + sal_Int64 getLength( ); + + sal_uInt16 ReadUInt16(); + sal_uInt32 ReadUInt32(); + sal_Int16 ReadInt16() + { + return static_cast<sal_Int16>(ReadUInt16()); + } + sal_Int32 ReadInt32() + { + return static_cast<sal_Int32>(ReadUInt32()); + } +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/CRC32.hxx b/package/inc/CRC32.hxx new file mode 100644 index 000000000..a2ca1b435 --- /dev/null +++ b/package/inc/CRC32.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_CRC32_HXX +#define INCLUDED_PACKAGE_INC_CRC32_HXX + +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/uno/Reference.h> + +namespace com::sun::star { + namespace io { class XInputStream; } +} +class CRC32 final +{ + sal_uInt32 nCRC; +public: + CRC32(); + + /// @throws css::uno::RuntimeException + sal_Int64 updateStream (css::uno::Reference < css::io::XInputStream > const & xStream); + /// @throws css::uno::RuntimeException + void updateSegment(const css::uno::Sequence< sal_Int8 > &b, sal_Int32 len); + /// @throws css::uno::RuntimeException + void update(const css::uno::Sequence< sal_Int8 > &b); + /// @throws css::uno::RuntimeException + sal_Int32 getValue() const; + /// @throws css::uno::RuntimeException + void reset(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/EncryptedDataHeader.hxx b/package/inc/EncryptedDataHeader.hxx new file mode 100644 index 000000000..6860c50ab --- /dev/null +++ b/package/inc/EncryptedDataHeader.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_ENCRYPTEDDATAHEADER_HXX +#define INCLUDED_PACKAGE_INC_ENCRYPTEDDATAHEADER_HXX + +#include <sal/types.h> + +/* The structure of this header is as follows: + + Header signature 4 bytes + Version number 2 bytes + Iteration count 4 bytes + Size 4 bytes + EncAlgorithm 4 bytes + DigestAlgorithm 4 bytes + DerivedKeySize 4 bytes + StartKeyAlgorithm 4 bytes + Salt length 2 bytes + IV length 2 bytes + Digest length 2 bytes + MediaType length 2 bytes + Salt content X bytes + IV content X bytes + digest content X bytes + MediaType X bytes + +*/ +const sal_uInt32 n_ConstHeader = 0x05024d4dL; // "MM\002\005" +const sal_Int32 n_ConstHeaderSize + = 38; // + salt length + iv length + digest length + mediatype length +const sal_Int16 n_ConstCurrentVersion = 1; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/EncryptionData.hxx b/package/inc/EncryptionData.hxx new file mode 100644 index 000000000..73408a090 --- /dev/null +++ b/package/inc/EncryptionData.hxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_ENCRYPTIONDATA_HXX +#define INCLUDED_PACKAGE_INC_ENCRYPTIONDATA_HXX + +#include <com/sun/star/uno/Sequence.hxx> +#include <cppuhelper/weak.hxx> + +class BaseEncryptionData : public cppu::OWeakObject +{ +public: + css::uno::Sequence< sal_Int8 > m_aSalt; + css::uno::Sequence< sal_Int8 > m_aInitVector; + css::uno::Sequence< sal_Int8 > m_aDigest; + sal_Int32 m_nIterationCount; + + BaseEncryptionData() + : m_nIterationCount ( 0 ){} + + BaseEncryptionData( const BaseEncryptionData& aData ) + : cppu::OWeakObject() + , m_aSalt( aData.m_aSalt ) + , m_aInitVector( aData.m_aInitVector ) + , m_aDigest( aData.m_aDigest ) + , m_nIterationCount( aData.m_nIterationCount ) + {} +}; + +class EncryptionData final : public BaseEncryptionData +{ +public: + css::uno::Sequence < sal_Int8 > m_aKey; + sal_Int32 m_nEncAlg; + sal_Int32 m_nCheckAlg; + sal_Int32 m_nDerivedKeySize; + sal_Int32 m_nStartKeyGenID; + bool m_bTryWrongSHA1; + + EncryptionData(const BaseEncryptionData& aData, const css::uno::Sequence< sal_Int8 >& aKey, sal_Int32 nEncAlg, sal_Int32 nCheckAlg, sal_Int32 nDerivedKeySize, sal_Int32 nStartKeyGenID, bool const bTryWrongSHA1) + : BaseEncryptionData( aData ) + , m_aKey( aKey ) + , m_nEncAlg( nEncAlg ) + , m_nCheckAlg( nCheckAlg ) + , m_nDerivedKeySize( nDerivedKeySize ) + , m_nStartKeyGenID( nStartKeyGenID ) + , m_bTryWrongSHA1(bTryWrongSHA1) + {} + + EncryptionData( const EncryptionData& aData ) + : BaseEncryptionData( aData ) + , m_aKey( aData.m_aKey ) + , m_nEncAlg( aData.m_nEncAlg ) + , m_nCheckAlg( aData.m_nCheckAlg ) + , m_nDerivedKeySize( aData.m_nDerivedKeySize ) + , m_nStartKeyGenID( aData.m_nStartKeyGenID ) + , m_bTryWrongSHA1(aData.m_bTryWrongSHA1) + {} +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/HashMaps.hxx b/package/inc/HashMaps.hxx new file mode 100644 index 000000000..000afa9e3 --- /dev/null +++ b/package/inc/HashMaps.hxx @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_HASHMAPS_HXX +#define INCLUDED_PACKAGE_INC_HASHMAPS_HXX + +#include "ZipEntry.hxx" +#include <unordered_map> + +class ZipPackageFolder; +struct ZipContentInfo; + +typedef std::unordered_map < OUString, + ZipPackageFolder * > FolderHash; + +typedef std::unordered_map < OUString, + ZipEntry > EntryHash; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/PackageConstants.hxx b/package/inc/PackageConstants.hxx new file mode 100644 index 000000000..2e9f1527b --- /dev/null +++ b/package/inc/PackageConstants.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_PACKAGECONSTANTS_HXX +#define INCLUDED_PACKAGE_INC_PACKAGECONSTANTS_HXX + +#include <sal/types.h> +#include <rtl/ustring.hxx> + +const sal_Int32 n_ConstBufferSize = 32768; + +// by calculation of the digest we read 32 bytes more ( if available ) +// it allows to ignore the padding if the stream is longer than n_ConstDigestDecrypt since we read at least two blocks more; +// if the stream is shorter or equal the padding will be done successfully +const sal_Int32 n_ConstDigestLength = 1024; +const sal_Int32 n_ConstDigestDecrypt = 1056; // 1024 + 32 + +// the constants related to the manifest.xml entries +#define PKG_MNFST_FULLPATH 0 //FullPath (Put full-path property first for MBA) +#define PKG_MNFST_VERSION 1 //Version +#define PKG_MNFST_MEDIATYPE 2 //MediaType + +#define PKG_MNFST_INIVECTOR 3 //InitialisationVector +#define PKG_MNFST_SALT 4 //Salt +#define PKG_MNFST_ITERATION 5 //IterationCount +#define PKG_MNFST_UCOMPSIZE 6 //Size +#define PKG_MNFST_DIGEST 7 //Digest +#define PKG_MNFST_ENCALG 8 //EncryptionAlgorithm +#define PKG_MNFST_STARTALG 9 //StartKeyAlgorithm +#define PKG_MNFST_DIGESTALG 10 //DigestAlgorithm +#define PKG_MNFST_DERKEYSIZE 11 //DerivedKeySize + +#define PKG_SIZE_NOENCR_MNFST 3 +#define PKG_SIZE_ENCR_MNFST 12 + +// the properties related constants +inline constexpr OUStringLiteral ENCRYPTION_KEY_PROPERTY = u"EncryptionKey"; +inline constexpr OUStringLiteral STORAGE_ENCRYPTION_KEYS_PROPERTY = u"StorageEncryptionKeys"; +inline constexpr OUStringLiteral ENCRYPTION_ALGORITHMS_PROPERTY = u"EncryptionAlgorithms"; +inline constexpr OUStringLiteral ENCRYPTION_GPG_PROPERTIES = u"EncryptionGpGProperties"; +#define HAS_ENCRYPTED_ENTRIES_PROPERTY "HasEncryptedEntries" +#define HAS_NONENCRYPTED_ENTRIES_PROPERTY "HasNonEncryptedEntries" +#define IS_INCONSISTENT_PROPERTY "IsInconsistent" +inline constexpr OUStringLiteral MEDIATYPE_FALLBACK_USED_PROPERTY = u"MediaTypeFallbackUsed"; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/ThreadedDeflater.hxx b/package/inc/ThreadedDeflater.hxx new file mode 100644 index 000000000..361129d0f --- /dev/null +++ b/package/inc/ThreadedDeflater.hxx @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_PACKAGE_THREADEDDEFLATER_HXX +#define INCLUDED_PACKAGE_THREADEDDEFLATER_HXX + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <comphelper/threadpool.hxx> +#include <memory> +#include <vector> +#include <functional> + +namespace ZipUtils +{ +/// Parallel compression a stream using the libz deflate algorithm. +/// +/// Call deflateWrite() with the input stream and input/output processing functions. +/// This will use multiple threads for compression on each batch of data from the stream. +class ThreadedDeflater final +{ + class Task; + // Note: All this should be lock-less. Each task writes only to its part + // of the data. + std::vector<std::vector<sal_Int8>> outBuffers; + std::shared_ptr<comphelper::ThreadTaskTag> threadTaskTag; + css::uno::Sequence<sal_Int8> inBuffer; + css::uno::Sequence<sal_Int8> prevDataBlock; + std::function<void(const css::uno::Sequence<sal_Int8>&, sal_Int32)> maProcessOutputFunc; + sal_Int64 totalIn; + sal_Int64 totalOut; + int zlibLevel; + +public: + // Unlike with Deflater class, bNoWrap is always true. + ThreadedDeflater(sal_Int32 nSetLevel); + ~ThreadedDeflater() COVERITY_NOEXCEPT_FALSE; + void deflateWrite( + const css::uno::Reference<css::io::XInputStream>& xInStream, + std::function<void(const css::uno::Sequence<sal_Int8>&, sal_Int32)> aProcessInputFunc, + std::function<void(const css::uno::Sequence<sal_Int8>&, sal_Int32)> aProcessOutputFunc); + sal_Int64 getTotalIn() const { return totalIn; } + sal_Int64 getTotalOut() const { return totalOut; } + +private: + void processDeflatedBuffers(); + void clear(); +}; + +} // namespace + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/ZipEntry.hxx b/package/inc/ZipEntry.hxx new file mode 100644 index 000000000..db87f660d --- /dev/null +++ b/package/inc/ZipEntry.hxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_ZIPENTRY_HXX +#define INCLUDED_PACKAGE_INC_ZIPENTRY_HXX + +#include <rtl/ustring.hxx> + +struct ZipEntry +{ + sal_Int16 nVersion; + sal_Int16 nFlag; + sal_Int16 nMethod; + sal_Int32 nTime; + sal_Int32 nCrc; + sal_Int64 nCompressedSize; + sal_Int64 nSize; + sal_Int64 nOffset; + sal_Int16 nPathLen; + sal_Int16 nExtraLen; + OUString sPath; +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/ZipEnumeration.hxx b/package/inc/ZipEnumeration.hxx new file mode 100644 index 000000000..50533cc28 --- /dev/null +++ b/package/inc/ZipEnumeration.hxx @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include "HashMaps.hxx" + +class ZipEnumeration final +{ + EntryHash& rEntryHash; + EntryHash::const_iterator aIterator; + +public: + bool hasMoreElements(); + const ZipEntry* nextElement(); + ZipEnumeration(EntryHash& rNewEntryHash); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/ZipFile.hxx b/package/inc/ZipFile.hxx new file mode 100644 index 000000000..15b800430 --- /dev/null +++ b/package/inc/ZipFile.hxx @@ -0,0 +1,167 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_ZIPFILE_HXX +#define INCLUDED_PACKAGE_INC_ZIPFILE_HXX + +#include <com/sun/star/xml/crypto/XCipherContext.hpp> +#include <com/sun/star/xml/crypto/XDigestContext.hpp> + +#include <comphelper/refcountedmutex.hxx> +#include <package/Inflater.hxx> +#include <rtl/ref.hxx> +#include "ByteGrabber.hxx" +#include "HashMaps.hxx" +#include "EncryptionData.hxx" + +namespace com::sun::star { + namespace uno { class XComponentContext; } + namespace ucb { class XProgressHandler; } +} +namespace rtl +{ + template < class T > class Reference; +} + +/* + * We impose arbitrary but reasonable limit on ZIP files. + */ + +#define ZIP_MAXNAMELEN 512 +#define ZIP_MAXENTRIES (0x10000 - 2) + +class ZipEnumeration; + +class ZipFile +{ + rtl::Reference<comphelper::RefCountedMutex> m_aMutexHolder; + + EntryHash aEntries; + ByteGrabber aGrabber; + ZipUtils::Inflater aInflater; + css::uno::Reference < css::io::XInputStream > xStream; + const css::uno::Reference < css::uno::XComponentContext > m_xContext; + + bool bRecoveryMode; + + // aMediaType parameter is used only for raw stream header creation + css::uno::Reference < css::io::XInputStream > createStreamForZipEntry( + const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder, + ZipEntry const & rEntry, + const ::rtl::Reference < EncryptionData > &rData, + sal_Int8 nStreamMode, + bool bDecrypt, + const bool bUseBufferedStream = true, + const OUString& aMediaType = OUString() ); + + bool hasValidPassword ( ZipEntry const & rEntry, const rtl::Reference < EncryptionData > &rData ); + + bool checkSizeAndCRC( const ZipEntry& aEntry ); + + sal_Int32 getCRC( sal_Int64 nOffset, sal_Int64 nSize ); + + void getSizeAndCRC( sal_Int64 nOffset, sal_Int64 nCompressedSize, sal_Int64 *nSize, sal_Int32 *nCRC ); + + void readLOC( ZipEntry &rEntry ); + sal_Int32 readCEN(); + sal_Int32 findEND(); + void recover(); + +public: + + ZipFile( const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder, + css::uno::Reference < css::io::XInputStream > const &xInput, + const css::uno::Reference < css::uno::XComponentContext > &rxContext, + bool bInitialise ); + + ZipFile( const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder, + css::uno::Reference < css::io::XInputStream > const &xInput, + const css::uno::Reference < css::uno::XComponentContext > &rxContext, + bool bInitialise, + bool bForceRecover ); + + ~ZipFile(); + + EntryHash& GetEntryHash() { return aEntries; } + + void setInputStream ( const css::uno::Reference < css::io::XInputStream >& xNewStream ); + css::uno::Reference< css::io::XInputStream > getRawData( + ZipEntry& rEntry, + const ::rtl::Reference < EncryptionData > &rData, + bool bDecrypt, + const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder, + const bool bUseBufferedStream = true ); + + static css::uno::Reference< css::xml::crypto::XDigestContext > StaticGetDigestContextForChecksum( + const css::uno::Reference< css::uno::XComponentContext >& xArgContext, + const ::rtl::Reference< EncryptionData >& xEncryptionData ); + + static css::uno::Reference< css::xml::crypto::XCipherContext > StaticGetCipher( + const css::uno::Reference< css::uno::XComponentContext >& xArgContext, + const ::rtl::Reference< EncryptionData >& xEncryptionData, + bool bEncrypt ); + + static void StaticFillHeader ( const ::rtl::Reference < EncryptionData > & rData, + sal_Int64 nSize, + const OUString& aMediaType, + sal_Int8 * & pHeader ); + + static bool StaticFillData ( ::rtl::Reference < BaseEncryptionData > const & rData, + sal_Int32 &rEncAlgorithm, + sal_Int32 &rChecksumAlgorithm, + sal_Int32 &rDerivedKeySize, + sal_Int32 &rStartKeyGenID, + sal_Int32 &rSize, + OUString& aMediaType, + const css::uno::Reference < css::io::XInputStream >& rStream ); + + static css::uno::Reference< css::io::XInputStream > StaticGetDataFromRawStream( + const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const css::uno::Reference< css::io::XInputStream >& xStream, + const ::rtl::Reference < EncryptionData > &rData ); + + static bool StaticHasValidPassword ( + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const css::uno::Sequence< sal_Int8 > &aReadBuffer, + const ::rtl::Reference < EncryptionData > &rData ); + + css::uno::Reference< css::io::XInputStream > getInputStream( + ZipEntry& rEntry, + const ::rtl::Reference < EncryptionData > &rData, + bool bDecrypt, + const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder ); + + css::uno::Reference< css::io::XInputStream > getDataStream( + ZipEntry& rEntry, + const ::rtl::Reference < EncryptionData > &rData, + bool bDecrypt, + const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder ); + + css::uno::Reference< css::io::XInputStream > getWrappedRawStream( + ZipEntry& rEntry, + const ::rtl::Reference < EncryptionData > &rData, + const OUString& aMediaType, + const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder ); + + ZipEnumeration entries(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/ZipOutputEntry.hxx b/package/inc/ZipOutputEntry.hxx new file mode 100644 index 000000000..078c07359 --- /dev/null +++ b/package/inc/ZipOutputEntry.hxx @@ -0,0 +1,159 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_ZIPOUTPUTENTRY_HXX +#define INCLUDED_PACKAGE_INC_ZIPOUTPUTENTRY_HXX + +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XTempFile.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/xml/crypto/XCipherContext.hpp> +#include <com/sun/star/xml/crypto/XDigestContext.hpp> + +#include <package/Deflater.hxx> +#include <comphelper/threadpool.hxx> +#include "CRC32.hxx" +#include <atomic> + +struct ZipEntry; +class ZipPackageBuffer; +class ZipPackageStream; + +class ZipOutputEntryBase +{ +protected: + css::uno::Reference< css::uno::XComponentContext > m_xContext; + css::uno::Reference< css::io::XOutputStream > m_xOutStream; + + css::uno::Reference< css::xml::crypto::XCipherContext > m_xCipherContext; + css::uno::Reference< css::xml::crypto::XDigestContext > m_xDigestContext; + + CRC32 m_aCRC; + ZipEntry *m_pCurrentEntry; + sal_Int16 m_nDigested; + ZipPackageStream* m_pCurrentStream; + bool m_bEncryptCurrentEntry; + +public: + virtual ~ZipOutputEntryBase() = default; + + virtual void writeStream(const css::uno::Reference< css::io::XInputStream >& xInStream) = 0; + + ZipEntry* getZipEntry() { return m_pCurrentEntry; } + ZipPackageStream* getZipPackageStream() { return m_pCurrentStream; } + bool isEncrypt() const { return m_bEncryptCurrentEntry; } + + void closeEntry(); + +protected: + ZipOutputEntryBase( + const css::uno::Reference< css::io::XOutputStream >& rxOutStream, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt, bool checkStream); + + // Inherited classes call this with deflated data buffer. + void processDeflated( const css::uno::Sequence< sal_Int8 >& deflateBuffer, sal_Int32 nLength ); + // Inherited classes call this with the input buffer. + void processInput( const css::uno::Sequence< sal_Int8 >& rBuffer ); + + virtual void finishDeflater() = 0; + virtual sal_Int64 getDeflaterTotalIn() const = 0; + virtual sal_Int64 getDeflaterTotalOut() const = 0; + virtual void deflaterReset() = 0; + virtual bool isDeflaterFinished() const = 0; +}; + +// Normal non-threaded case. +class ZipOutputEntry : public ZipOutputEntryBase +{ + css::uno::Sequence< sal_Int8 > m_aDeflateBuffer; + ZipUtils::Deflater m_aDeflater; + +public: + ZipOutputEntry( + const css::uno::Reference< css::io::XOutputStream >& rxOutStream, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt); + void writeStream(const css::uno::Reference< css::io::XInputStream >& xInStream) override; + void write(const css::uno::Sequence< sal_Int8 >& rBuffer); + +protected: + ZipOutputEntry( + const css::uno::Reference< css::io::XOutputStream >& rxOutStream, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt, bool checkStream); + virtual void finishDeflater() override; + virtual sal_Int64 getDeflaterTotalIn() const override; + virtual sal_Int64 getDeflaterTotalOut() const override; + virtual void deflaterReset() override; + virtual bool isDeflaterFinished() const override; + void doDeflate(); +}; + +// Class that runs the compression in a background thread. +class ZipOutputEntryInThread final : public ZipOutputEntry +{ + class Task; + css::uno::Reference<css::io::XTempFile> m_xTempFile; + std::exception_ptr m_aParallelDeflateException; + std::atomic<bool> m_bFinished; + +public: + ZipOutputEntryInThread( + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt); + std::unique_ptr<comphelper::ThreadTask> createTask( + const std::shared_ptr<comphelper::ThreadTaskTag>& pTag, + const css::uno::Reference< css::io::XInputStream >& xInStream ); + /* This block of methods is for threaded zipping, where we compress to a temp stream, whose + data is retrieved via getData */ + void createBufferFile(); + void setParallelDeflateException(const std::exception_ptr& exception) { m_aParallelDeflateException = exception; } + css::uno::Reference< css::io::XInputStream > getData() const; + const std::exception_ptr& getParallelDeflateException() const { return m_aParallelDeflateException; } + void closeBufferFile(); + void deleteBufferFile(); + bool isFinished() const { return m_bFinished; } +private: + void setFinished() { m_bFinished = true; } +}; + +// Class that synchronously runs the compression in multiple threads (using ThreadDeflater). +class ZipOutputEntryParallel final : public ZipOutputEntryBase +{ + sal_Int64 totalIn; + sal_Int64 totalOut; + bool finished; +public: + ZipOutputEntryParallel( + const css::uno::Reference< css::io::XOutputStream >& rxOutStream, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt); + void writeStream(const css::uno::Reference< css::io::XInputStream >& xInStream) override; +private: + virtual void finishDeflater() override; + virtual sal_Int64 getDeflaterTotalIn() const override; + virtual sal_Int64 getDeflaterTotalOut() const override; + virtual void deflaterReset() override; + virtual bool isDeflaterFinished() const override; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/ZipOutputStream.hxx b/package/inc/ZipOutputStream.hxx new file mode 100644 index 000000000..f55ef59a8 --- /dev/null +++ b/package/inc/ZipOutputStream.hxx @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_ZIPOUTPUTSTREAM_HXX +#define INCLUDED_PACKAGE_INC_ZIPOUTPUTSTREAM_HXX + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/io/XOutputStream.hpp> + +#include "ByteChucker.hxx" +#include <comphelper/threadpool.hxx> + +#include <cstddef> +#include <vector> + +struct ZipEntry; +class ZipOutputEntry; +class ZipOutputEntryInThread; +class ZipPackageStream; + +class ZipOutputStream +{ + css::uno::Reference< css::io::XOutputStream > m_xStream; + ::std::vector < ZipEntry * > m_aZipList; + std::shared_ptr<comphelper::ThreadTaskTag> mpThreadTaskTag; + + ByteChucker m_aChucker; + ZipEntry *m_pCurrentEntry; + std::vector< ZipOutputEntryInThread* > m_aEntries; + std::exception_ptr m_aDeflateException; + +public: + ZipOutputStream( + const css::uno::Reference< css::io::XOutputStream > &xOStream ); + ~ZipOutputStream(); + + void addDeflatingThreadTask( ZipOutputEntryInThread *pEntry, std::unique_ptr<comphelper::ThreadTask> pThreadTask ); + + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + void writeLOC( ZipEntry *pEntry, bool bEncrypt = false ); + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + void rawWrite( const css::uno::Sequence< sal_Int8 >& rBuffer ); + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + void rawCloseEntry( bool bEncrypt = false ); + + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + void finish(); + const css::uno::Reference< css::io::XOutputStream >& getStream() const; + + static sal_uInt32 getCurrentDosTime(); + static void setEntry( ZipEntry *pEntry ); + +private: + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + void writeEND(sal_uInt32 nOffset, sal_uInt32 nLength); + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + void writeCEN( const ZipEntry &rEntry ); + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + void writeEXT( const ZipEntry &rEntry ); + + // ScheduledThread handling helpers + void consumeScheduledThreadTaskEntry(std::unique_ptr<ZipOutputEntryInThread> pCandidate); + void consumeFinishedScheduledThreadTaskEntries(); + +public: + void reduceScheduledThreadTasksToGivenNumberOrLess( + std::size_t nThreadTasks); + + const std::shared_ptr<comphelper::ThreadTaskTag>& getThreadTaskTag() const { return mpThreadTaskTag; } +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/ZipPackage.hxx b/package/inc/ZipPackage.hxx new file mode 100644 index 000000000..e6cf614ad --- /dev/null +++ b/package/inc/ZipPackage.hxx @@ -0,0 +1,167 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_ZIPPACKAGE_HXX +#define INCLUDED_PACKAGE_INC_ZIPPACKAGE_HXX + +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/util/XChangesBatch.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> +#include <comphelper/refcountedmutex.hxx> +#include <rtl/ref.hxx> + +#include "HashMaps.hxx" +#include "ZipFile.hxx" +#include <vector> +#include <optional> + +class ZipOutputStream; +class ZipPackageFolder; +class ZipFile; +namespace com::sun::star { + namespace container { class XNameContainer; } + namespace io { class XStream; class XOutputStream; class XInputStream; class XSeekable; class XActiveDataStreamer; } + namespace lang { class XMultiServiceFactory; } + namespace uno { class XComponentContext; } + namespace task { class XInteractionHandler; } +} + +enum InitialisationMode +{ + e_IMode_None, + e_IMode_URL, + e_IMode_XInputStream, + e_IMode_XStream +}; + +class ZipPackage final : public cppu::WeakImplHelper + < + css::lang::XInitialization, + css::lang::XSingleServiceFactory, + css::lang::XUnoTunnel, + css::lang::XServiceInfo, + css::container::XHierarchicalNameAccess, + css::util::XChangesBatch, + css::beans::XPropertySet + > +{ + rtl::Reference<comphelper::RefCountedMutex> m_aMutexHolder; + + css::uno::Sequence< css::beans::NamedValue > m_aStorageEncryptionKeys; + css::uno::Sequence< sal_Int8 > m_aEncryptionKey; + css::uno::Sequence< css::uno::Sequence< css::beans::NamedValue > > m_aGpgProps; + + FolderHash m_aRecent; + OUString m_aURL; + + sal_Int32 m_nStartKeyGenerationID; + sal_Int32 m_nChecksumDigestID; + sal_Int32 m_nCommonEncryptionID; + bool m_bHasEncryptedEntries; + bool m_bHasNonEncryptedEntries; + + bool m_bInconsistent; + bool m_bForceRecovery; + + bool m_bMediaTypeFallbackUsed; + sal_Int32 m_nFormat; + bool m_bAllowRemoveOnInsert; + + InitialisationMode m_eMode; + + rtl::Reference < ZipPackageFolder > m_xRootFolder; + css::uno::Reference < css::io::XStream > m_xStream; + css::uno::Reference < css::io::XInputStream > m_xContentStream; + css::uno::Reference < css::io::XSeekable > m_xContentSeek; + const css::uno::Reference < css::uno::XComponentContext > m_xContext; + + std::optional<ZipFile> m_pZipFile; + bool m_bDisableFileSync = false; + + bool isLocalFile() const; + + void parseManifest(); + void parseContentType(); + void getZipFileContents(); + + void WriteMimetypeMagicFile( ZipOutputStream& aZipOut ); + void WriteManifest( ZipOutputStream& aZipOut, const ::std::vector< css::uno::Sequence< css::beans::PropertyValue > >& aManList ); + void WriteContentTypes( ZipOutputStream& aZipOut, const ::std::vector< css::uno::Sequence< css::beans::PropertyValue > >& aManList ); + + css::uno::Reference< css::io::XInputStream > writeTempFile(); + css::uno::Reference < css::io::XActiveDataStreamer > openOriginalForOutput(); + void DisconnectFromTargetAndThrowException_Impl( + const css::uno::Reference< css::io::XInputStream >& xTempStream ); + +public: + ZipPackage( const css::uno::Reference < css::uno::XComponentContext > &xContext ); + virtual ~ZipPackage() override; + ZipFile& getZipFile() { return *m_pZipFile;} + sal_Int32 getFormat() const { return m_nFormat; } + + sal_Int32 GetStartKeyGenID() const { return m_nStartKeyGenerationID; } + sal_Int32 GetEncAlgID() const { return m_nCommonEncryptionID; } + sal_Int32 GetChecksumAlgID() const { return m_nChecksumDigestID; } + sal_Int32 GetDefaultDerivedKeySize() const { return m_nCommonEncryptionID == css::xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 32 : 16; } + + rtl::Reference<comphelper::RefCountedMutex>& GetSharedMutexRef() { return m_aMutexHolder; } + + void ConnectTo( const css::uno::Reference< css::io::XInputStream >& xInStream ); + css::uno::Sequence< sal_Int8 > GetEncryptionKey(); + + // XInitialization + virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; + // XHierarchicalNameAccess + virtual css::uno::Any SAL_CALL getByHierarchicalName( const OUString& aName ) override; + virtual sal_Bool SAL_CALL hasByHierarchicalName( const OUString& aName ) override; + // XSingleServiceFactory + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( ) override; + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const css::uno::Sequence< css::uno::Any >& aArguments ) override; + // XChangesBatch + virtual void SAL_CALL commitChanges( ) override; + virtual sal_Bool SAL_CALL hasPendingChanges( ) override; + virtual css::uno::Sequence< css::util::ElementChange > SAL_CALL getPendingChanges( ) override; + // XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; + /// @throws css::uno::RuntimeException + static const css::uno::Sequence < sal_Int8 > & getUnoTunnelId(); + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override; + virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override; + virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override; + virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override; + virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override; + virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/ZipPackageBuffer.hxx b/package/inc/ZipPackageBuffer.hxx new file mode 100644 index 000000000..64a24563c --- /dev/null +++ b/package/inc/ZipPackageBuffer.hxx @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_ZIPPACKAGEBUFFER_HXX +#define INCLUDED_PACKAGE_INC_ZIPPACKAGEBUFFER_HXX + +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <cppuhelper/implbase.hxx> + +class ZipPackageBuffer final : public ::cppu::WeakImplHelper +< + css::io::XInputStream, + css::io::XOutputStream, + css::io::XSeekable +> +{ + css::uno::Sequence < sal_Int8 > m_aBuffer; + sal_Int64 m_nBufferSize, m_nEnd, m_nCurrent; + bool m_bMustInitBuffer; +public: + ZipPackageBuffer(); + virtual ~ZipPackageBuffer() override; + + void realloc ( sal_Int32 nSize ) { m_aBuffer.realloc ( nSize ); } + const css::uno::Sequence < sal_Int8>& getSequence () const { return m_aBuffer; } + + // XInputStream + virtual sal_Int32 SAL_CALL readBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) override; + virtual sal_Int32 SAL_CALL readSomeBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) override; + virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) override; + virtual sal_Int32 SAL_CALL available( ) override; + virtual void SAL_CALL closeInput( ) override; + // XOutputStream + virtual void SAL_CALL writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override; + virtual void SAL_CALL flush( ) override; + virtual void SAL_CALL closeOutput( ) override; + // XSeekable + virtual void SAL_CALL seek( sal_Int64 location ) override; + virtual sal_Int64 SAL_CALL getPosition( ) override; + virtual sal_Int64 SAL_CALL getLength( ) override; +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/ZipPackageEntry.hxx b/package/inc/ZipPackageEntry.hxx new file mode 100644 index 000000000..2617e6275 --- /dev/null +++ b/package/inc/ZipPackageEntry.hxx @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_ZIPPACKAGEENTRY_HXX +#define INCLUDED_PACKAGE_INC_ZIPPACKAGEENTRY_HXX + +#include <com/sun/star/container/XChild.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include "ZipEntry.hxx" +#include <cppuhelper/implbase.hxx> + +#include <vector> + +typedef void* rtlRandomPool; +class ZipOutputStream; +class ZipPackageFolder; + +class ZipPackageEntry : public cppu::WeakImplHelper +< + css::container::XNamed, + css::container::XChild, + css::lang::XUnoTunnel, + css::beans::XPropertySet, + css::lang::XServiceInfo +> +{ +protected: + css::uno::Reference< css::uno::XComponentContext > m_xContext; + OUString msName; + bool mbIsFolder:1; + bool mbAllowRemoveOnInsert:1; + OUString msMediaType; + ZipPackageFolder* mpParent; + sal_Int32 m_nFormat; + +public: + ZipEntry aEntry; + ZipPackageEntry(); + virtual ~ZipPackageEntry() override; + + const OUString& GetMediaType() const { return msMediaType; } + void SetMediaType(const OUString & sNewType) { msMediaType = sNewType; } + void doSetParent(ZipPackageFolder * pNewParent); + bool IsFolder() const { return mbIsFolder; } + void SetFolder(const bool bSetFolder) { mbIsFolder = bSetFolder; } + + virtual bool saveChild( const OUString &rPath, + std::vector < css::uno::Sequence < css::beans::PropertyValue > > &rManList, + ZipOutputStream & rZipOut, + const css::uno::Sequence < sal_Int8 >& rEncryptionKey, + sal_Int32 nPBKDF2IterationCount, + const rtlRandomPool &rRandomPool ) = 0; + + void clearParent() + { + // xParent.clear(); + mpParent = nullptr; + } + // XNamed + virtual OUString SAL_CALL getName( ) override; + virtual void SAL_CALL setName( const OUString& aName ) override; + // XChild + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent( ) override; + virtual void SAL_CALL setParent( const css::uno::Reference< css::uno::XInterface >& Parent ) override; + // XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override = 0; + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override = 0; + virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override = 0; + virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override; + virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override; + virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override; + virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override; +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/ZipPackageFolder.hxx b/package/inc/ZipPackageFolder.hxx new file mode 100644 index 000000000..825822931 --- /dev/null +++ b/package/inc/ZipPackageFolder.hxx @@ -0,0 +1,149 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_ZIPPACKAGEFOLDER_HXX +#define INCLUDED_PACKAGE_INC_ZIPPACKAGEFOLDER_HXX + +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/beans/StringPair.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include "ZipPackageEntry.hxx" +#include <cppuhelper/implbase.hxx> + +#include <string_view> +#include <unordered_map> +#include <vector> + +class ZipOutputStream; +struct ZipEntry; +class ZipPackageFolder; +class ZipPackageStream; + +struct ZipContentInfo +{ + css::uno::Reference < css::lang::XUnoTunnel > xTunnel; + bool bFolder; + union + { + ZipPackageFolder *pFolder; + ZipPackageStream *pStream; + }; + ZipContentInfo( ZipPackageStream * pNewStream ); + ZipContentInfo( ZipPackageFolder * pNewFolder ); + ZipContentInfo( const ZipContentInfo& ); + ZipContentInfo( ZipContentInfo&& ); + ZipContentInfo& operator=( const ZipContentInfo& ); + ZipContentInfo& operator=( ZipContentInfo&& ); + + ~ZipContentInfo(); +}; + +typedef std::unordered_map < OUString, + ZipContentInfo > ContentHash; + +class ZipPackageFolder final : public cppu::ImplInheritanceHelper +< + ZipPackageEntry, + css::container::XNameContainer, + css::container::XEnumerationAccess +> +{ +private: + ContentHash maContents; + OUString m_sVersion; + +public: + + ZipPackageFolder( const css::uno::Reference < css::uno::XComponentContext >& xContext, + sal_Int32 nFormat, + bool bAllowRemoveOnInsert ); + virtual ~ZipPackageFolder() override; + + const OUString& GetVersion() const { return m_sVersion; } + void SetVersion( const OUString& aVersion ) { m_sVersion = aVersion; } + + bool LookForUnexpectedODF12Streams( std::u16string_view aPath ); + + void setChildStreamsTypeByExtension( const css::beans::StringPair& aPair ); + + /// @throws css::lang::IllegalArgumentException + /// @throws css::container::ElementExistException + /// @throws css::lang::WrappedTargetException + /// @throws css::uno::RuntimeException + void doInsertByName ( ZipPackageEntry *pEntry, bool bSetParent ); + + ZipContentInfo& doGetByName( const OUString& aName ); + + static const css::uno::Sequence < sal_Int8 > & getUnoTunnelId(); + + void setPackageFormat_Impl( sal_Int32 nFormat ) { m_nFormat = nFormat; } + void setRemoveOnInsertMode_Impl( bool bRemove ) { mbAllowRemoveOnInsert = bRemove; } + + virtual bool saveChild( const OUString &rPath, + std::vector < css::uno::Sequence < css::beans::PropertyValue > > &rManList, + ZipOutputStream & rZipOut, + const css::uno::Sequence < sal_Int8 >& rEncryptionKey, + sal_Int32 nPBKDF2IterationCount, + const rtlRandomPool &rRandomPool ) override; + + // Recursive functions + /// @throws css::uno::RuntimeException + void saveContents( + const OUString &rPath, + std::vector < css::uno::Sequence < css::beans::PropertyValue > > &rManList, + ZipOutputStream & rZipOut, + const css::uno::Sequence< sal_Int8 > &rEncryptionKey, + sal_Int32 nPBKDF2IterationCount, + const rtlRandomPool & rRandomPool) const; + + // XNameContainer + virtual void SAL_CALL insertByName( const OUString& aName, const css::uno::Any& aElement ) override; + virtual void SAL_CALL removeByName( const OUString& Name ) override; + + // XEnumerationAccess + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration( ) override; + + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType( ) override; + virtual sal_Bool SAL_CALL hasElements( ) override; + + // XNameAccess + virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override; + virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override; + + // XNameReplace + virtual void SAL_CALL replaceByName( const OUString& aName, const css::uno::Any& aElement ) override; + + // XPropertySet + virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override; + virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override; + + // XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/ZipPackageStream.hxx b/package/inc/ZipPackageStream.hxx new file mode 100644 index 000000000..aa1507174 --- /dev/null +++ b/package/inc/ZipPackageStream.hxx @@ -0,0 +1,169 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_PACKAGE_INC_ZIPPACKAGESTREAM_HXX +#define INCLUDED_PACKAGE_INC_ZIPPACKAGESTREAM_HXX + +#include <com/sun/star/io/XActiveDataSink.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/packages/XDataSinkEncrSupport.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include "ZipPackageEntry.hxx" +#include <rtl/ref.hxx> +#include <cppuhelper/implbase.hxx> + +#include "EncryptionData.hxx" + +#define PACKAGE_STREAM_NOTSET 0 +#define PACKAGE_STREAM_PACKAGEMEMBER 1 +#define PACKAGE_STREAM_DETECT 2 +#define PACKAGE_STREAM_DATA 3 +#define PACKAGE_STREAM_RAW 4 + +class ZipPackage; +struct ZipEntry; +class ZipPackageStream final : public cppu::ImplInheritanceHelper +< + ZipPackageEntry, + css::io::XActiveDataSink, + css::packages::XDataSinkEncrSupport +> +{ +private: + css::uno::Reference < css::io::XInputStream > m_xStream; + ZipPackage &m_rZipPackage; + bool m_bToBeCompressed, m_bToBeEncrypted, m_bHaveOwnKey, m_bIsEncrypted; + + ::rtl::Reference< BaseEncryptionData > m_xBaseEncryptionData; + css::uno::Sequence< css::beans::NamedValue > m_aStorageEncryptionKeys; + css::uno::Sequence< sal_Int8 > m_aEncryptionKey; + + sal_Int32 m_nImportedStartKeyAlgorithm; + sal_Int32 m_nImportedEncryptionAlgorithm; + sal_Int32 m_nImportedChecksumAlgorithm; + sal_Int32 m_nImportedDerivedKeySize; + + sal_uInt8 m_nStreamMode; + sal_uInt32 m_nMagicalHackPos; + sal_uInt32 m_nMagicalHackSize; + sal_Int64 m_nOwnStreamOrigSize; + + bool m_bHasSeekable; + bool m_bCompressedIsSetFromOutside; + bool m_bFromManifest; + bool m_bUseWinEncoding; + bool m_bRawStream; + + /// Check that m_xStream implements io::XSeekable and return it + css::uno::Reference< css::io::XInputStream > const & GetOwnSeekStream(); + /// get raw data using unbuffered stream + /// @throws css::uno::RuntimeException + css::uno::Reference< css::io::XInputStream > getRawData(); + +public: + bool IsPackageMember () const { return m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER;} + + bool IsFromManifest() const { return m_bFromManifest; } + void SetFromManifest( bool bValue ) { m_bFromManifest = bValue; } + + enum class Bugs { None, WinEncodingWrongSHA1, WrongSHA1 }; + ::rtl::Reference<EncryptionData> GetEncryptionData(Bugs bugs = Bugs::None); + + css::uno::Sequence<sal_Int8> GetEncryptionKey(Bugs bugs = Bugs::None); + + sal_Int32 GetStartKeyGenID() const; + + sal_Int32 GetEncryptionAlgorithm() const; + sal_Int32 GetBlockSize() const; + + void SetToBeCompressed (bool bNewValue) { m_bToBeCompressed = bNewValue;} + void SetIsEncrypted (bool bNewValue) { m_bIsEncrypted = bNewValue;} + void SetImportedStartKeyAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedStartKeyAlgorithm = nAlgorithm; } + void SetImportedEncryptionAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedEncryptionAlgorithm = nAlgorithm; } + void SetImportedChecksumAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedChecksumAlgorithm = nAlgorithm; } + void SetImportedDerivedKeySize( sal_Int32 nSize ) { m_nImportedDerivedKeySize = nSize; } + void SetToBeEncrypted (bool bNewValue) + { + m_bToBeEncrypted = bNewValue; + if ( m_bToBeEncrypted && !m_xBaseEncryptionData.is()) + m_xBaseEncryptionData = new BaseEncryptionData; + else if ( !m_bToBeEncrypted && m_xBaseEncryptionData.is() ) + m_xBaseEncryptionData.clear(); + } + void SetPackageMember (bool bNewValue); + + void setInitialisationVector (const css::uno::Sequence < sal_Int8 >& rNewVector ) + { m_xBaseEncryptionData->m_aInitVector = rNewVector;} + void setSalt (const css::uno::Sequence < sal_Int8 >& rNewSalt ) + { m_xBaseEncryptionData->m_aSalt = rNewSalt;} + void setDigest (const css::uno::Sequence < sal_Int8 >& rNewDigest ) + { m_xBaseEncryptionData->m_aDigest = rNewDigest;} + void setIterationCount (const sal_Int32 nNewCount) + { m_xBaseEncryptionData->m_nIterationCount = nNewCount;} + void setSize (const sal_Int64 nNewSize); + + ZipPackageStream( ZipPackage & rNewPackage, + const css::uno::Reference < css::uno::XComponentContext >& xContext, + sal_Int32 nFormat, + bool bAllowRemoveOnInsert ); + virtual ~ZipPackageStream() override; + + css::uno::Reference< css::io::XInputStream > GetRawEncrStreamNoHeaderCopy(); + css::uno::Reference< css::io::XInputStream > TryToGetRawFromDataStream(bool bAddHeaderForEncr ); + + bool ParsePackageRawStream(); + virtual bool saveChild( const OUString &rPath, + std::vector < css::uno::Sequence < css::beans::PropertyValue > > &rManList, + ZipOutputStream & rZipOut, + const css::uno::Sequence < sal_Int8 >& rEncryptionKey, + sal_Int32 nPBKDF2IterationCount, + const rtlRandomPool &rRandomPool ) override; + + void setZipEntryOnLoading( const ZipEntry &rInEntry); + void successfullyWritten( ZipEntry const *pEntry ); + + static const css::uno::Sequence < sal_Int8 > & getUnoTunnelId(); + + // XActiveDataSink + virtual void SAL_CALL setInputStream( const css::uno::Reference< css::io::XInputStream >& aStream ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream( ) override; + + // XDataSinkEncrSupport + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getDataStream() override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getRawStream() override; + virtual void SAL_CALL setDataStream( + const css::uno::Reference< css::io::XInputStream >& aStream ) override; + virtual void SAL_CALL setRawStream( + const css::uno::Reference< css::io::XInputStream >& aStream ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getPlainRawStream() override; + + // XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; + + // XPropertySet + virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override; + virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/pch/precompiled_package2.cxx b/package/inc/pch/precompiled_package2.cxx new file mode 100644 index 000000000..63e41961d --- /dev/null +++ b/package/inc/pch/precompiled_package2.cxx @@ -0,0 +1,12 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "precompiled_package2.hxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/pch/precompiled_package2.hxx b/package/inc/pch/precompiled_package2.hxx new file mode 100644 index 000000000..7b1192067 --- /dev/null +++ b/package/inc/pch/precompiled_package2.hxx @@ -0,0 +1,178 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* + This file has been autogenerated by update_pch.sh. It is possible to edit it + manually (such as when an include file has been moved/renamed/removed). All such + manual changes will be rewritten by the next run of update_pch.sh (which presumably + also fixes all possible problems, so it's usually better to use it). + + Generated on 2021-04-08 13:55:58 using: + ./bin/update_pch package package2 --cutoff=3 --exclude:system --include:module --include:local + + If after updating build fails, use the following command to locate conflicting headers: + ./bin/update_pch_bisect ./package/inc/pch/precompiled_package2.hxx "make package.build" --find-conflicts +*/ + +#include <sal/config.h> +#if PCH_LEVEL >= 1 +#include <algorithm> +#include <cassert> +#include <chrono> +#include <cmath> +#include <cstddef> +#include <cstdlib> +#include <cstring> +#include <initializer_list> +#include <iomanip> +#include <limits> +#include <math.h> +#include <memory> +#include <new> +#include <ostream> +#include <stddef.h> +#include <string.h> +#include <string> +#include <string_view> +#include <type_traits> +#include <unordered_map> +#include <utility> +#include <vector> +#include <zlib.h> +#endif // PCH_LEVEL >= 1 +#if PCH_LEVEL >= 2 +#include <osl/diagnose.h> +#include <osl/diagnose.hxx> +#include <osl/doublecheckedlocking.h> +#include <osl/endian.h> +#include <osl/file.h> +#include <osl/getglobalmutex.hxx> +#include <osl/interlck.h> +#include <osl/mutex.h> +#include <osl/mutex.hxx> +#include <osl/thread.hxx> +#include <osl/time.h> +#include <rtl/alloc.h> +#include <rtl/cipher.h> +#include <rtl/crc.h> +#include <rtl/digest.h> +#include <rtl/instance.hxx> +#include <rtl/math.h> +#include <rtl/random.h> +#include <rtl/ref.hxx> +#include <rtl/strbuf.h> +#include <rtl/strbuf.hxx> +#include <rtl/string.h> +#include <rtl/string.hxx> +#include <rtl/stringconcat.hxx> +#include <rtl/stringutils.hxx> +#include <rtl/textcvt.h> +#include <rtl/textenc.h> +#include <rtl/uri.hxx> +#include <rtl/ustrbuf.h> +#include <rtl/ustrbuf.hxx> +#include <rtl/ustring.h> +#include <rtl/ustring.hxx> +#include <sal/log.hxx> +#include <sal/macros.h> +#include <sal/saldllapi.h> +#include <sal/types.h> +#include <sal/typesizes.h> +#endif // PCH_LEVEL >= 2 +#if PCH_LEVEL >= 3 +#include <basegfx/basegfxdllapi.h> +#include <basegfx/color/bcolor.hxx> +#include <basegfx/numeric/ftools.hxx> +#include <basegfx/tuple/b3dtuple.hxx> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/embed/StorageFormats.hpp> +#include <com/sun/star/io/TempFile.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/io/XStream.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/lang/EventObject.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/packages/zip/ZipConstants.hpp> +#include <com/sun/star/packages/zip/ZipIOException.hpp> +#include <com/sun/star/uno/Any.h> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Type.h> +#include <com/sun/star/uno/Type.hxx> +#include <com/sun/star/uno/TypeClass.hdl> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/uno/XWeak.hpp> +#include <com/sun/star/uno/genfunc.h> +#include <com/sun/star/uno/genfunc.hxx> +#include <com/sun/star/xml/crypto/CipherID.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> +#include <comphelper/comphelperdllapi.h> +#include <comphelper/processfactory.hxx> +#include <comphelper/refcountedmutex.hxx> +#include <comphelper/sequence.hxx> +#include <comphelper/servicehelper.hxx> +#include <comphelper/storagehelper.hxx> +#include <cppu/cppudllapi.h> +#include <cppu/unotype.hxx> +#include <cppuhelper/cppuhelperdllapi.h> +#include <cppuhelper/exc_hlp.hxx> +#include <cppuhelper/factory.hxx> +#include <cppuhelper/implbase.hxx> +#include <cppuhelper/implbase_ex.hxx> +#include <cppuhelper/implbase_ex_post.hxx> +#include <cppuhelper/implbase_ex_pre.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <cppuhelper/weak.hxx> +#include <o3tl/typed_flags_set.hxx> +#include <o3tl/underlyingenumvalue.hxx> +#include <salhelper/salhelperdllapi.h> +#include <salhelper/simplereferenceobject.hxx> +#include <tools/diagnose_ex.h> +#include <tools/toolsdllapi.h> +#include <typelib/typeclass.h> +#include <typelib/typedescription.h> +#include <typelib/uik.h> +#include <uno/any2.h> +#include <uno/data.h> +#include <uno/sequence2.h> +#include <unotools/options.hxx> +#include <unotools/unotoolsdllapi.h> +#endif // PCH_LEVEL >= 3 +#if PCH_LEVEL >= 4 +#include <CRC32.hxx> +#include <EncryptedDataHeader.hxx> +#include <EncryptionData.hxx> +#include <HashMaps.hxx> +#include <PackageConstants.hxx> +#include <ThreadedDeflater.hxx> +#include <ZipEntry.hxx> +#include <ZipEnumeration.hxx> +#include <ZipFile.hxx> +#include <ZipOutputEntry.hxx> +#include <ZipOutputStream.hxx> +#include <ZipPackageBuffer.hxx> +#include <ZipPackageFolder.hxx> +#include <ZipPackageStream.hxx> +#include <package/packagedllapi.hxx> +#endif // PCH_LEVEL >= 4 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/pch/precompiled_xstor.cxx b/package/inc/pch/precompiled_xstor.cxx new file mode 100644 index 000000000..10f1d920d --- /dev/null +++ b/package/inc/pch/precompiled_xstor.cxx @@ -0,0 +1,12 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "precompiled_xstor.hxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/pch/precompiled_xstor.hxx b/package/inc/pch/precompiled_xstor.hxx new file mode 100644 index 000000000..a1e548eb7 --- /dev/null +++ b/package/inc/pch/precompiled_xstor.hxx @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* + This file has been autogenerated by update_pch.sh. It is possible to edit it + manually (such as when an include file has been moved/renamed/removed). All such + manual changes will be rewritten by the next run of update_pch.sh (which presumably + also fixes all possible problems, so it's usually better to use it). + + Generated on 2021-03-08 13:14:06 using: + ./bin/update_pch package xstor --cutoff=2 --exclude:system --include:module --exclude:local + + If after updating build fails, use the following command to locate conflicting headers: + ./bin/update_pch_bisect ./package/inc/pch/precompiled_xstor.hxx "make package.build" --find-conflicts +*/ + +#include <sal/config.h> +#if PCH_LEVEL >= 1 +#include <algorithm> +#include <cassert> +#include <cstddef> +#include <cstdlib> +#include <iomanip> +#include <limits> +#include <memory> +#include <new> +#include <ostream> +#include <stddef.h> +#include <string.h> +#include <string> +#include <string_view> +#include <type_traits> +#include <utility> +#endif // PCH_LEVEL >= 1 +#if PCH_LEVEL >= 2 +#include <osl/diagnose.h> +#include <osl/interlck.h> +#include <osl/mutex.h> +#include <osl/mutex.hxx> +#include <rtl/alloc.h> +#include <rtl/digest.h> +#include <rtl/instance.hxx> +#include <rtl/string.h> +#include <rtl/string.hxx> +#include <rtl/stringconcat.hxx> +#include <rtl/stringutils.hxx> +#include <rtl/textcvt.h> +#include <rtl/textenc.h> +#include <rtl/ustring.h> +#include <rtl/ustring.hxx> +#include <sal/log.hxx> +#include <sal/macros.h> +#include <sal/saldllapi.h> +#include <sal/types.h> +#include <sal/typesizes.h> +#endif // PCH_LEVEL >= 2 +#if PCH_LEVEL >= 3 +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/embed/StorageFormats.hpp> +#include <com/sun/star/embed/StorageWrappedTargetException.hpp> +#include <com/sun/star/io/IOException.hpp> +#include <com/sun/star/io/NotConnectedException.hpp> +#include <com/sun/star/io/TempFile.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/packages/WrongPasswordException.hpp> +#include <com/sun/star/ucb/SimpleFileAccess.hpp> +#include <com/sun/star/uno/Any.h> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Type.h> +#include <com/sun/star/uno/Type.hxx> +#include <com/sun/star/uno/TypeClass.hdl> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/uno/XWeak.hpp> +#include <com/sun/star/uno/genfunc.h> +#include <com/sun/star/uno/genfunc.hxx> +#include <comphelper/comphelperdllapi.h> +#include <comphelper/ofopxmlhelper.hxx> +#include <comphelper/processfactory.hxx> +#include <comphelper/sequence.hxx> +#include <comphelper/storagehelper.hxx> +#include <cppu/cppudllapi.h> +#include <cppu/unotype.hxx> +#include <cppuhelper/cppuhelperdllapi.h> +#include <cppuhelper/exc_hlp.hxx> +#include <cppuhelper/queryinterface.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <salhelper/salhelperdllapi.h> +#include <salhelper/simplereferenceobject.hxx> +#include <tools/diagnose_ex.h> +#include <typelib/typeclass.h> +#include <typelib/typedescription.h> +#include <typelib/uik.h> +#include <uno/any2.h> +#include <uno/data.h> +#include <uno/sequence2.h> +#endif // PCH_LEVEL >= 3 +#if PCH_LEVEL >= 4 +#endif // PCH_LEVEL >= 4 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/inc/zipfileaccess.hxx b/package/inc/zipfileaccess.hxx new file mode 100644 index 000000000..5d85a846c --- /dev/null +++ b/package/inc/zipfileaccess.hxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_PACKAGE_INC_ZIPFILEACCESS_HXX +#define INCLUDED_PACKAGE_INC_ZIPFILEACCESS_HXX + +#include <com/sun/star/packages/zip/XZipFileAccess2.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> + +#include <comphelper/interfacecontainer3.hxx> +#include <comphelper/refcountedmutex.hxx> +#include <cppuhelper/implbase.hxx> + +#include "ZipFile.hxx" + +#include <memory> +#include <optional> + +class OZipFileAccess final : public ::cppu::WeakImplHelper< + css::packages::zip::XZipFileAccess2, + css::lang::XInitialization, + css::lang::XComponent, + css::lang::XServiceInfo > +{ + rtl::Reference<comphelper::RefCountedMutex> m_aMutexHolder; + css::uno::Reference< css::uno::XComponentContext > m_xContext; + css::uno::Reference< css::io::XInputStream > m_xContentStream; + std::optional<ZipFile> m_pZipFile; + std::unique_ptr<::comphelper::OInterfaceContainerHelper3<css::lang::XEventListener>> m_pListenersContainer; + bool m_bDisposed; + bool m_bOwnContent; + +public: + OZipFileAccess( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); + + virtual ~OZipFileAccess() override; + + static css::uno::Sequence< OUString > GetPatternsFromString_Impl( const OUString& aString ); + + static bool StringGoodForPattern_Impl( const OUString& aString, + const css::uno::Sequence< OUString >& aPattern ); + + // XInitialization + virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; + + // XNameAccess + virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override; + virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override; + virtual css::uno::Type SAL_CALL getElementType( ) override; + virtual sal_Bool SAL_CALL hasElements( ) override; + + // XZipFileAccess + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getStreamByPattern( const OUString& aPattern ) override; + + // XComponent + virtual void SAL_CALL dispose( ) override; + virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override; + virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |