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