xref: /trunk/main/package/inc/ZipPackage.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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     // XHierarchicalNameAccess
146     virtual ::com::sun::star::uno::Any SAL_CALL getByHierarchicalName( const ::rtl::OUString& aName );
147     virtual sal_Bool SAL_CALL hasByHierarchicalName( const ::rtl::OUString& aName );
148     // XSingleServiceFactory
149     virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance(  );
150     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 );
151     // XChangesBatch
152     virtual void SAL_CALL commitChanges(  );
153     virtual sal_Bool SAL_CALL hasPendingChanges(  );
154     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::util::ElementChange > SAL_CALL getPendingChanges(  );
155     // XUnoTunnel
156     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier );
157     com::sun::star::uno::Sequence < sal_Int8 > getUnoTunnelImplementationId( void );
158     // XPropertySet
159     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  );
160     virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue );
161     virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName );
162     virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener );
163     virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener );
164     virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener );
165     virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener );
166 
167     // XServiceInfo
168     virtual ::rtl::OUString SAL_CALL getImplementationName(  );
169     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
170     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  );
171 
172     // Uno componentiseralation
173     static ::rtl::OUString static_getImplementationName();
174     static ::com::sun::star::uno::Sequence < ::rtl::OUString > static_getSupportedServiceNames();
175     static ::com::sun::star::uno::Reference < com::sun::star::lang::XSingleServiceFactory > createServiceFactory( com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > const & rServiceFactory );
176     sal_Bool SAL_CALL static_supportsService(rtl::OUString const & rServiceName);
177 };
178 #endif
179