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