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