1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _ZIP_PACKAGE_HXX 24 #define _ZIP_PACKAGE_HXX 25 26 #include <cppuhelper/implbase7.hxx> 27 #include <com/sun/star/lang/XInitialization.hpp> 28 #include <com/sun/star/container/XHierarchicalNameAccess.hpp> 29 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 30 #include <com/sun/star/util/XChangesBatch.hpp> 31 #include <com/sun/star/lang/XUnoTunnel.hpp> 32 #include <com/sun/star/beans/XPropertySet.hpp> 33 #include <com/sun/star/beans/PropertyValue.hpp> 34 #include <com/sun/star/beans/NamedValue.hpp> 35 #include <com/sun/star/lang/XServiceInfo.hpp> 36 #include <com/sun/star/xml/crypto/CipherID.hpp> 37 #include <com/sun/star/lang/IllegalArgumentException.hpp> 38 39 #include <HashMaps.hxx> 40 #include <vector> 41 #include <osl/file.h> 42 #include <mutexholder.hxx> 43 44 class ZipOutputStream; 45 class ZipPackageFolder; 46 class ZipFile; 47 class ByteGrabber; 48 namespace com { namespace sun { namespace star { 49 namespace container { class XNameContainer; } 50 namespace io { class XStream; class XOutputStream; class XInputStream; class XSeekable; class XActiveDataStreamer; } 51 namespace lang { class XMultiServiceFactory; } 52 namespace task { class XInteractionHandler; } 53 } } } 54 enum SegmentEnum 55 { 56 e_Aborted = -1000, 57 e_Retry, 58 e_Finished, 59 e_Success = 0 60 }; 61 62 enum InitialisationMode 63 { 64 e_IMode_None, 65 e_IMode_URL, 66 e_IMode_XInputStream, 67 e_IMode_XStream 68 }; 69 70 class ZipPackage : public cppu::WeakImplHelper7 71 < 72 com::sun::star::lang::XInitialization, 73 com::sun::star::lang::XSingleServiceFactory, 74 com::sun::star::lang::XUnoTunnel, 75 com::sun::star::lang::XServiceInfo, 76 com::sun::star::container::XHierarchicalNameAccess, 77 com::sun::star::util::XChangesBatch, 78 com::sun::star::beans::XPropertySet 79 > 80 { 81 protected: 82 SotMutexHolderRef m_aMutexHolder; 83 84 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > m_aStorageEncryptionKeys; 85 ::com::sun::star::uno::Sequence< sal_Int8 > m_aEncryptionKey; 86 87 FolderHash m_aRecent; 88 ::rtl::OUString m_aURL; 89 90 sal_Int32 m_nStartKeyGenerationID; 91 sal_Int32 m_nChecksumDigestID; 92 sal_Int32 m_nCommonEncryptionID; 93 sal_Bool m_bHasEncryptedEntries; 94 sal_Bool m_bHasNonEncryptedEntries; 95 96 sal_Bool m_bInconsistent; 97 sal_Bool m_bForceRecovery; 98 99 sal_Bool m_bMediaTypeFallbackUsed; 100 sal_Int32 m_nFormat; 101 sal_Bool m_bAllowRemoveOnInsert; 102 103 InitialisationMode m_eMode; 104 105 ::com::sun::star::uno::Reference < com::sun::star::container::XNameContainer > m_xRootFolder; 106 ::com::sun::star::uno::Reference < com::sun::star::io::XStream > m_xStream; 107 ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream > m_xContentStream; 108 ::com::sun::star::uno::Reference < com::sun::star::io::XSeekable > m_xContentSeek; 109 const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory; 110 111 ZipPackageFolder *m_pRootFolder; 112 ZipFile *m_pZipFile; 113 114 void parseManifest(); 115 void parseContentType(); 116 void getZipFileContents(); 117 118 void WriteMimetypeMagicFile( ZipOutputStream& aZipOut ); 119 void WriteManifest( ZipOutputStream& aZipOut, const ::std::vector< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& aManList ); 120 void WriteContentTypes( ZipOutputStream& aZipOut, const ::std::vector< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& aManList ); 121 122 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > writeTempFile(); 123 ::com::sun::star::uno::Reference < ::com::sun::star::io::XActiveDataStreamer > openOriginalForOutput(); 124 void DisconnectFromTargetAndThrowException_Impl( 125 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xTempStream ); 126 127 public: 128 ZipPackage( const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory ); 129 virtual ~ZipPackage( void ); getZipFile()130 ZipFile& getZipFile() { return *m_pZipFile;} getFormat() const131 sal_Int32 getFormat() const { return m_nFormat; } 132 GetStartKeyGenID() const133 sal_Int32 GetStartKeyGenID() const { return m_nStartKeyGenerationID; } GetEncAlgID() const134 sal_Int32 GetEncAlgID() const { return m_nCommonEncryptionID; } GetChecksumAlgID() const135 sal_Int32 GetChecksumAlgID() const { return m_nChecksumDigestID; } GetDefaultDerivedKeySize() const136 sal_Int32 GetDefaultDerivedKeySize() const { return m_nCommonEncryptionID == ::com::sun::star::xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 32 : 16; } 137 GetSharedMutexRef()138 SotMutexHolderRef GetSharedMutexRef() { return m_aMutexHolder; } 139 140 void ConnectTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream ); 141 const ::com::sun::star::uno::Sequence< sal_Int8 > GetEncryptionKey(); 142 143 // XInitialization 144 virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) 145 throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 146 // XHierarchicalNameAccess 147 virtual ::com::sun::star::uno::Any SAL_CALL getByHierarchicalName( const ::rtl::OUString& aName ) 148 throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); 149 virtual sal_Bool SAL_CALL hasByHierarchicalName( const ::rtl::OUString& aName ) 150 throw(::com::sun::star::uno::RuntimeException); 151 // XSingleServiceFactory 152 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( ) 153 throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 154 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) 155 throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 156 // XChangesBatch 157 virtual void SAL_CALL commitChanges( ) 158 throw(::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 159 virtual sal_Bool SAL_CALL hasPendingChanges( ) 160 throw(::com::sun::star::uno::RuntimeException); 161 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::util::ElementChange > SAL_CALL getPendingChanges( ) 162 throw(::com::sun::star::uno::RuntimeException); 163 // XUnoTunnel 164 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) 165 throw(::com::sun::star::uno::RuntimeException); 166 com::sun::star::uno::Sequence < sal_Int8 > getUnoTunnelImplementationId( void ) 167 throw(::com::sun::star::uno::RuntimeException); 168 // XPropertySet 169 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) 170 throw(::com::sun::star::uno::RuntimeException); 171 virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) 172 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 173 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) 174 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 175 virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) 176 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 177 virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) 178 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 179 virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) 180 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 181 virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) 182 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 183 184 // XServiceInfo 185 virtual ::rtl::OUString SAL_CALL getImplementationName( ) 186 throw (::com::sun::star::uno::RuntimeException); 187 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) 188 throw (::com::sun::star::uno::RuntimeException); 189 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) 190 throw (::com::sun::star::uno::RuntimeException); 191 192 // Uno componentiseralation 193 static ::rtl::OUString static_getImplementationName(); 194 static ::com::sun::star::uno::Sequence < ::rtl::OUString > static_getSupportedServiceNames(); 195 static ::com::sun::star::uno::Reference < com::sun::star::lang::XSingleServiceFactory > createServiceFactory( com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > const & rServiceFactory ); 196 sal_Bool SAL_CALL static_supportsService(rtl::OUString const & rServiceName); 197 }; 198 #endif 199