xref: /aoo41x/main/package/inc/ZipPackage.hxx (revision f319bb99)
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 <osl/file.h>
41 #include <mutexholder.hxx>
42 
43 class ZipOutputStream;
44 class ZipPackageFolder;
45 class ZipFile;
46 class ByteGrabber;
47 namespace com { namespace sun { namespace star {
48     namespace container { class XNameContainer; }
49     namespace io { class XStream; class XOutputStream; class XInputStream; class XSeekable; class XActiveDataStreamer; }
50     namespace lang { class XMultiServiceFactory; }
51     namespace task { class XInteractionHandler; }
52 } } }
53 enum SegmentEnum
54 {
55     e_Aborted = -1000,
56     e_Retry,
57     e_Finished,
58     e_Success = 0
59 };
60 
61 enum InitialisationMode
62 {
63     e_IMode_None,
64     e_IMode_URL,
65     e_IMode_XInputStream,
66     e_IMode_XStream
67 };
68 
69 class ZipPackage : public cppu::WeakImplHelper7
70                     <
71                        com::sun::star::lang::XInitialization,
72                        com::sun::star::lang::XSingleServiceFactory,
73                        com::sun::star::lang::XUnoTunnel,
74                        com::sun::star::lang::XServiceInfo,
75                        com::sun::star::container::XHierarchicalNameAccess,
76                        com::sun::star::util::XChangesBatch,
77                        com::sun::star::beans::XPropertySet
78                     >
79 {
80 protected:
81     SotMutexHolderRef m_aMutexHolder;
82 
83     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > m_aStorageEncryptionKeys;
84     ::com::sun::star::uno::Sequence< sal_Int8 > m_aEncryptionKey;
85 
86     FolderHash        m_aRecent;
87     ::rtl::OUString   m_aURL;
88 
89     sal_Int32         m_nStartKeyGenerationID;
90     sal_Int32         m_nChecksumDigestID;
91     sal_Int32         m_nCommonEncryptionID;
92     sal_Bool          m_bHasEncryptedEntries;
93     sal_Bool          m_bHasNonEncryptedEntries;
94 
95     sal_Bool          m_bInconsistent;
96     sal_Bool          m_bForceRecovery;
97 
98     sal_Bool          m_bMediaTypeFallbackUsed;
99     sal_Int32         m_nFormat;
100     sal_Bool          m_bAllowRemoveOnInsert;
101 
102     InitialisationMode m_eMode;
103 
104     ::com::sun::star::uno::Reference < com::sun::star::container::XNameContainer > m_xRootFolder;
105     ::com::sun::star::uno::Reference < com::sun::star::io::XStream > m_xStream;
106     ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream > m_xContentStream;
107     ::com::sun::star::uno::Reference < com::sun::star::io::XSeekable > m_xContentSeek;
108     const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory;
109 
110     ZipPackageFolder *m_pRootFolder;
111     ZipFile          *m_pZipFile;
112 
113     void parseManifest();
114     void parseContentType();
115     void getZipFileContents();
116 
117     void WriteMimetypeMagicFile( ZipOutputStream& aZipOut );
118     void WriteManifest( ZipOutputStream& aZipOut, const ::std::vector< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& aManList );
119     void WriteContentTypes( ZipOutputStream& aZipOut, const ::std::vector< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& aManList );
120 
121     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > writeTempFile();
122     ::com::sun::star::uno::Reference < ::com::sun::star::io::XActiveDataStreamer > openOriginalForOutput();
123     void DisconnectFromTargetAndThrowException_Impl(
124             const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xTempStream );
125 
126 public:
127     ZipPackage( const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory );
128     virtual ~ZipPackage( void );
129     ZipFile& getZipFile() { return *m_pZipFile;}
130     sal_Int32 getFormat() const { return m_nFormat; }
131 
132     sal_Int32 GetStartKeyGenID() const { return m_nStartKeyGenerationID; }
133     sal_Int32 GetEncAlgID() const { return m_nCommonEncryptionID; }
134     sal_Int32 GetChecksumAlgID() const { return m_nChecksumDigestID; }
135     sal_Int32 GetDefaultDerivedKeySize() const { return m_nCommonEncryptionID == ::com::sun::star::xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 32 : 16; }
136 
137     SotMutexHolderRef GetSharedMutexRef() { return m_aMutexHolder; }
138 
139     void ConnectTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream );
140     const ::com::sun::star::uno::Sequence< sal_Int8 > GetEncryptionKey();
141 
142     // XInitialization
143     virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
144         throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
145     // XHierarchicalNameAccess
146     virtual ::com::sun::star::uno::Any SAL_CALL getByHierarchicalName( const ::rtl::OUString& aName )
147         throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
148     virtual sal_Bool SAL_CALL hasByHierarchicalName( const ::rtl::OUString& aName )
149         throw(::com::sun::star::uno::RuntimeException);
150     // XSingleServiceFactory
151     virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance(  )
152         throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
153     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 )
154         throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
155     // XChangesBatch
156     virtual void SAL_CALL commitChanges(  )
157         throw(::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
158     virtual sal_Bool SAL_CALL hasPendingChanges(  )
159         throw(::com::sun::star::uno::RuntimeException);
160     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::util::ElementChange > SAL_CALL getPendingChanges(  )
161         throw(::com::sun::star::uno::RuntimeException);
162     // XUnoTunnel
163     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
164         throw(::com::sun::star::uno::RuntimeException);
165     com::sun::star::uno::Sequence < sal_Int8 > getUnoTunnelImplementationId( void )
166         throw(::com::sun::star::uno::RuntimeException);
167     // XPropertySet
168     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  )
169         throw(::com::sun::star::uno::RuntimeException);
170     virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue )
171         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);
172     virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName )
173         throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
174     virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener )
175         throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
176     virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener )
177         throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
178     virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener )
179         throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
180     virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener )
181         throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
182 
183     // XServiceInfo
184     virtual ::rtl::OUString SAL_CALL getImplementationName(  )
185         throw (::com::sun::star::uno::RuntimeException);
186     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
187         throw (::com::sun::star::uno::RuntimeException);
188     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
189         throw (::com::sun::star::uno::RuntimeException);
190 
191     // Uno componentiseralation
192     static ::rtl::OUString static_getImplementationName();
193     static ::com::sun::star::uno::Sequence < ::rtl::OUString > static_getSupportedServiceNames();
194     static ::com::sun::star::uno::Reference < com::sun::star::lang::XSingleServiceFactory > createServiceFactory( com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > const & rServiceFactory );
195     sal_Bool SAL_CALL static_supportsService(rtl::OUString const & rServiceName);
196 };
197 #endif
198