1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef _ZIP_PACKAGE_HXX 28 #define _ZIP_PACKAGE_HXX 29 30 #include <cppuhelper/implbase7.hxx> 31 #include <com/sun/star/lang/XInitialization.hpp> 32 #include <com/sun/star/container/XHierarchicalNameAccess.hpp> 33 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 34 #include <com/sun/star/util/XChangesBatch.hpp> 35 #include <com/sun/star/lang/XUnoTunnel.hpp> 36 #include <com/sun/star/beans/XPropertySet.hpp> 37 #include <com/sun/star/beans/PropertyValue.hpp> 38 #include <com/sun/star/beans/NamedValue.hpp> 39 #include <com/sun/star/lang/XServiceInfo.hpp> 40 #include <com/sun/star/xml/crypto/CipherID.hpp> 41 #include <com/sun/star/lang/IllegalArgumentException.hpp> 42 43 #include <HashMaps.hxx> 44 #include <osl/file.h> 45 #include <mutexholder.hxx> 46 47 class ZipOutputStream; 48 class ZipPackageFolder; 49 class ZipFile; 50 class ByteGrabber; 51 namespace com { namespace sun { namespace star { 52 namespace container { class XNameContainer; } 53 namespace io { class XStream; class XOutputStream; class XInputStream; class XSeekable; class XActiveDataStreamer; } 54 namespace lang { class XMultiServiceFactory; } 55 namespace task { class XInteractionHandler; } 56 } } } 57 enum SegmentEnum 58 { 59 e_Aborted = -1000, 60 e_Retry, 61 e_Finished, 62 e_Success = 0 63 }; 64 65 enum InitialisationMode 66 { 67 e_IMode_None, 68 e_IMode_URL, 69 e_IMode_XInputStream, 70 e_IMode_XStream 71 }; 72 73 class ZipPackage : public cppu::WeakImplHelper7 74 < 75 com::sun::star::lang::XInitialization, 76 com::sun::star::lang::XSingleServiceFactory, 77 com::sun::star::lang::XUnoTunnel, 78 com::sun::star::lang::XServiceInfo, 79 com::sun::star::container::XHierarchicalNameAccess, 80 com::sun::star::util::XChangesBatch, 81 com::sun::star::beans::XPropertySet 82 > 83 { 84 protected: 85 SotMutexHolderRef m_aMutexHolder; 86 87 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > m_aStorageEncryptionKeys; 88 ::com::sun::star::uno::Sequence< sal_Int8 > m_aEncryptionKey; 89 90 FolderHash m_aRecent; 91 ::rtl::OUString m_aURL; 92 93 sal_Int32 m_nStartKeyGenerationID; 94 sal_Int32 m_nChecksumDigestID; 95 sal_Int32 m_nCommonEncryptionID; 96 sal_Bool m_bHasEncryptedEntries; 97 sal_Bool m_bHasNonEncryptedEntries; 98 99 sal_Bool m_bInconsistent; 100 sal_Bool m_bForceRecovery; 101 102 sal_Bool m_bMediaTypeFallbackUsed; 103 sal_Int32 m_nFormat; 104 sal_Bool m_bAllowRemoveOnInsert; 105 106 InitialisationMode m_eMode; 107 108 ::com::sun::star::uno::Reference < com::sun::star::container::XNameContainer > m_xRootFolder; 109 ::com::sun::star::uno::Reference < com::sun::star::io::XStream > m_xStream; 110 ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream > m_xContentStream; 111 ::com::sun::star::uno::Reference < com::sun::star::io::XSeekable > m_xContentSeek; 112 const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory; 113 114 ZipPackageFolder *m_pRootFolder; 115 ZipFile *m_pZipFile; 116 117 void parseManifest(); 118 void parseContentType(); 119 void getZipFileContents(); 120 121 void WriteMimetypeMagicFile( ZipOutputStream& aZipOut ); 122 void WriteManifest( ZipOutputStream& aZipOut, const ::std::vector< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& aManList ); 123 void WriteContentTypes( ZipOutputStream& aZipOut, const ::std::vector< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& aManList ); 124 125 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > writeTempFile(); 126 ::com::sun::star::uno::Reference < ::com::sun::star::io::XActiveDataStreamer > openOriginalForOutput(); 127 void DisconnectFromTargetAndThrowException_Impl( 128 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xTempStream ); 129 130 public: 131 ZipPackage( const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory ); 132 virtual ~ZipPackage( void ); 133 ZipFile& getZipFile() { return *m_pZipFile;} 134 sal_Int32 getFormat() const { return m_nFormat; } 135 136 sal_Int32 GetStartKeyGenID() const { return m_nStartKeyGenerationID; } 137 sal_Int32 GetEncAlgID() const { return m_nCommonEncryptionID; } 138 sal_Int32 GetChecksumAlgID() const { return m_nChecksumDigestID; } 139 sal_Int32 GetDefaultDerivedKeySize() const { return m_nCommonEncryptionID == ::com::sun::star::xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 32 : 16; } 140 141 SotMutexHolderRef GetSharedMutexRef() { return m_aMutexHolder; } 142 143 void ConnectTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream ); 144 const ::com::sun::star::uno::Sequence< sal_Int8 > GetEncryptionKey(); 145 146 // XInitialization 147 virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) 148 throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 149 // XHierarchicalNameAccess 150 virtual ::com::sun::star::uno::Any SAL_CALL getByHierarchicalName( const ::rtl::OUString& aName ) 151 throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); 152 virtual sal_Bool SAL_CALL hasByHierarchicalName( const ::rtl::OUString& aName ) 153 throw(::com::sun::star::uno::RuntimeException); 154 // XSingleServiceFactory 155 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( ) 156 throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 157 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 ) 158 throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 159 // XChangesBatch 160 virtual void SAL_CALL commitChanges( ) 161 throw(::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 162 virtual sal_Bool SAL_CALL hasPendingChanges( ) 163 throw(::com::sun::star::uno::RuntimeException); 164 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::util::ElementChange > SAL_CALL getPendingChanges( ) 165 throw(::com::sun::star::uno::RuntimeException); 166 // XUnoTunnel 167 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) 168 throw(::com::sun::star::uno::RuntimeException); 169 com::sun::star::uno::Sequence < sal_Int8 > getUnoTunnelImplementationId( void ) 170 throw(::com::sun::star::uno::RuntimeException); 171 // XPropertySet 172 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) 173 throw(::com::sun::star::uno::RuntimeException); 174 virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) 175 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); 176 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) 177 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 178 virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) 179 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 180 virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) 181 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 182 virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) 183 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 184 virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) 185 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 186 187 // XServiceInfo 188 virtual ::rtl::OUString SAL_CALL getImplementationName( ) 189 throw (::com::sun::star::uno::RuntimeException); 190 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) 191 throw (::com::sun::star::uno::RuntimeException); 192 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) 193 throw (::com::sun::star::uno::RuntimeException); 194 195 // Uno componentiseralation 196 static ::rtl::OUString static_getImplementationName(); 197 static ::com::sun::star::uno::Sequence < ::rtl::OUString > static_getSupportedServiceNames(); 198 static ::com::sun::star::uno::Reference < com::sun::star::lang::XSingleServiceFactory > createServiceFactory( com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > const & rServiceFactory ); 199 sal_Bool SAL_CALL static_supportsService(rtl::OUString const & rServiceName); 200 }; 201 #endif 202