diff options
author | Ivo Hinkelmann <ihi@openoffice.org> | 2009-09-17 13:53:54 +0000 |
---|---|---|
committer | Ivo Hinkelmann <ihi@openoffice.org> | 2009-09-17 13:53:54 +0000 |
commit | 10ab1790956131e93f58090a30417187e6624775 (patch) | |
tree | be83359068ccc07d91edc8469ceacfabf4ce9f26 /package | |
parent | 23e1e999ad0d394a8b295491145c28d46e70f3d1 (diff) |
CWS-TOOLING: integrate CWS encsig09
2009-09-14 15:11:29 +0200 oc r276125 : #i105049# MacroSignatur needs Macro
2009-09-09 17:09:46 +0200 jl r276005 : #i103989# could not signe encrypted doc containing a formular object
2009-09-09 13:11:24 +0200 jl r275985 : #i103989# could not signe encrypted doc containing a formular object
2009-09-08 15:54:02 +0200 mav r275934 : #i103906# fix the automation test scenario ( tempfile should be writable for the user )
2009-09-07 14:01:39 +0200 mav r275895 : #i103906# fix the problem with reload
2009-09-07 09:34:48 +0200 mav r275871 : #i104786# do the ODF version check only for ODF documents
2009-09-07 08:19:06 +0200 mav r275870 : #i104389# fix text
2009-09-06 22:24:21 +0200 mav r275867 : #i104786# check the consistency of ODF version
2009-09-06 22:23:24 +0200 mav r275866 : #i104786# check the consistency of ODF version
2009-09-06 22:23:00 +0200 mav r275865 : #i104786# check the consistency of ODF version
2009-09-06 22:22:36 +0200 mav r275864 : #i104786# check the consistency of ODF version
2009-09-06 22:22:03 +0200 mav r275863 : #i104786# check the consistency of ODF version
2009-09-02 17:09:30 +0200 mav r275722 : #i104715# let repairing mechanics use the streams correctly
2009-09-01 16:52:49 +0200 mav r275670 : #i104389# notify user not to trust the corrupted document
2009-09-01 16:31:37 +0200 mav r275668 : #i104389# use vnd.sun.star.zip: protocol to access zip files
2009-09-01 16:30:32 +0200 mav r275667 : #i104389# use vnd.sun.star.zip: protocol to access zip files
2009-09-01 16:22:13 +0200 jl r275666 : #i104339# small content change
2009-09-01 14:20:42 +0200 jl r275660 : #i103519# remove some debug output
2009-09-01 13:51:52 +0200 jl r275659 : #i103519# NSS uses '\' for escaping in distinguished names
2009-09-01 12:49:47 +0200 mav r275655 : #i104389# use zip-mode to read from jar files
2009-09-01 12:40:22 +0200 mav r275653 : #i104389# use zip-mode to read from jar files
2009-09-01 12:32:29 +0200 mav r275652 : #i104389# use constants
2009-08-31 21:58:00 +0200 mav r275637 : #i10000# fix warning
2009-08-31 21:11:17 +0200 mav r275636 : #i104227# adding of scripting signature removes the document signature
2009-08-31 20:55:05 +0200 mav r275635 : #i103905# ZipStorage supports Compressed property
2009-08-31 20:53:55 +0200 mav r275634 : #i103905# adjust macro signature transfer to usage of ZipStorage
2009-08-31 15:30:49 +0200 jl r275609 : #i103989# warning is shown as long the user does not click 'OK'
2009-08-31 14:36:10 +0200 jl r275608 : #i103989# changed warning text when signing macro and there is a document signature. This warning is only displayed once
2009-08-31 13:34:41 +0200 mav r275603 : #i104452# disable macros in repaired documents
2009-08-31 13:33:42 +0200 mav r275602 : #i104452# disable macros in repaired documents
2009-08-31 13:03:56 +0200 jl r275600 : #i45212# signature dialog could not be started when using read-only documents
2009-08-31 09:26:13 +0200 mav r275583 : #i104578# store the additional entry as the last one to workaround parsing problem in OOo3.1 and later
2009-08-30 20:54:25 +0200 mav r275562 : #i10000# adopt for unix
2009-08-30 10:56:00 +0200 mav r275561 : CWS-TOOLING: rebase CWS encsig09 to trunk@275331 (milestone: DEV300:m56)
2009-08-28 16:34:00 +0200 mav r275539 : #i104578# write necessary info in manifest.xml for ODF1.2 encrypted document
2009-08-28 14:04:22 +0200 mav r275533 : #104587# fix handling of readonly streams
2009-08-28 13:58:10 +0200 mav r275531 : #i104389# fix the broken document handling
2009-08-28 11:40:39 +0200 mav r275522 : #i104389# fix the signature streams check
2009-08-27 21:48:12 +0200 mav r275509 : #i103927# show the warning
2009-08-27 21:47:48 +0200 mav r275508 : #i103927# show the warning
2009-08-27 16:45:59 +0200 jl r275495 : #i45212# remove unused variable
2009-08-27 16:34:00 +0200 jl r275494 : #i103989#
2009-08-27 13:54:28 +0200 jl r275482 : #i103519# fixed replacement of 'S' by 'ST'
2009-08-27 12:32:21 +0200 mav r275472 : #i10000# fix warning
2009-08-27 11:58:11 +0200 mav r275467 : #i104389# handle the entry path correctly
2009-08-26 17:18:35 +0200 jl r275438 : #i103519# subject and issuer distinguished names were not properly displayed. The strings were obtained by system functions (Windows, NSS), which use quotes to escape the values, when they contain special characters
2009-08-26 11:00:20 +0200 mav r275403 : #i10000# fix warnings
2009-08-26 08:25:45 +0200 mav r275392 : #i10000# fix warning
2009-08-26 08:02:22 +0200 mav r275391 : #i10000# adopt for linux
2009-08-26 07:40:30 +0200 mav r275390 : #i10000# fix warning
2009-08-26 07:35:28 +0200 mav r275389 : #i10000# use correct include file name
2009-08-25 15:01:41 +0200 jl r275356 : #i103989# better check for mimetype of streams
2009-08-25 09:07:09 +0200 mav r275335 : CWS-TOOLING: rebase CWS encsig09 to trunk@274622 (milestone: DEV300:m54)
2009-08-24 18:17:02 +0200 mav r275329 : #i103927# check the nonencrypted streams
2009-08-24 18:14:14 +0200 mav r275328 : #i103927# check the nonencrypted streams
2009-08-24 17:59:34 +0200 mav r275327 : #i103927#,#i104389# check the package consistency and nonencrypted streams
2009-08-24 16:18:28 +0200 jl r275323 : #i103989# added comment
2009-08-24 13:08:47 +0200 jl r275305 : #i45212# #i66276# only write the X509Certificate element once and allow to add remove several certificates at a time
2009-08-21 12:57:28 +0200 ufi r275239 : 104339
2009-08-21 08:39:05 +0200 jl r275213 : #i10398# comparing URIs of signed files with the 'element list'
2009-08-20 13:39:47 +0200 jl r275178 : #i10398# displaying 'new partially signed' status in the status bar
2009-08-20 13:35:39 +0200 jl r275177 : #i10398# displaying 'new partially signed' status in the status bar
2009-08-20 13:29:06 +0200 jl r275176 : #i10398# displaying 'new partially signed' status in the status bar
2009-08-20 13:26:21 +0200 jl r275175 : #i10398# displaying 'new partially signed' status in the status bar
2009-08-20 12:05:09 +0200 ufi r275170 : i104339
2009-08-19 12:24:54 +0200 jl r275146 : #i10398# displaying 'old signature' icon and status in signature dialog
2009-08-18 15:18:48 +0200 jl r275111 : #i103989# document signatures containing manifest.xml are now validated according to the final ODF1.2 spec
2009-08-18 11:41:06 +0200 mav r275087 : #i103927# detect if encrypted ODF1.2 document contains nonencrypted streams
2009-08-18 11:35:13 +0200 mav r275085 : #i103927# detect if encrypted ODF1.2 document contains nonencrypted streams
2009-08-14 17:32:41 +0200 jl r274999 : #i103989# using c14n tranformation for XML streams
2009-08-14 15:27:43 +0200 jl r274987 : #i103989# remove special handling for encrypted document streams in UriBindingHelper::OpenInputStream, since we use zip storage this is not necessary anymore
2009-08-14 15:08:10 +0200 jl r274983 : #i103989# Showing a message when adding or removing a macro signature, that the document signature will be removed
2009-08-14 14:57:27 +0200 jl r274982 : #i103989# accesing Sequence at invalid index
2009-08-11 08:55:02 +0200 mav r274846 : #i103905# let signing service know if there is already a valid document signature
2009-08-10 11:33:37 +0200 jl r274799 : #i103905# do not truncate the stream
2009-08-10 10:43:47 +0200 mav r274797 : #i103905# provide the storage version
2009-08-07 16:58:46 +0200 jl r274780 : #i103989#
2009-08-07 16:56:19 +0200 jl r274779 : #i103989# using odf version string etc.
2009-08-07 15:20:53 +0200 mav r274771 : #i103905# provide the storage version
2009-08-07 15:19:12 +0200 mav r274770 : #i103905# provide the storage version
2009-08-07 12:41:45 +0200 mav r274758 : #103930# do not store thumbnail in case of encrypted document
2009-08-07 12:36:52 +0200 mav r274757 : #i103905# provide the storage version
2009-08-07 12:15:54 +0200 mav r274754 : #i103760# the signed state is not lost on saving
2009-08-07 12:06:19 +0200 mav r274753 : #i103760# avoid warning regarding signature removal on export
2009-08-07 12:06:01 +0200 mav r274752 : #i103760# avoid warning regarding signature removal on export
2009-08-06 08:47:34 +0200 mav r274703 : #i103905# allow to transport ODF version to the signing component
2009-08-05 21:34:42 +0200 mav r274701 : #i103905# allow to transport ODF version to the signing component
2009-08-05 15:48:17 +0200 mav r274683 : #i103905# allow to transport ODF version to the signing component
2009-08-05 14:58:12 +0200 jl r274673 : #i103989# documentsignature now signes all streams except documentsignatures.xml, all streams are processed as binary files
2009-08-05 12:00:32 +0200 mav r274648 : #i103905# allow to transport ODF version to the signing component
2009-08-04 10:57:04 +0200 jl r274612 : #i103989# added XInitialization
2009-07-31 10:32:27 +0200 mav r274516 : #i103905# use zip storage to sign documents
2009-07-30 14:01:33 +0200 mav r274489 : #i103906# optimize the usage of temporary medium
2009-07-30 14:00:28 +0200 mav r274488 : #i103906# optimize the usage of temporary medium
2009-07-30 13:59:09 +0200 mav r274487 : #i103906# optimize the usage of temporary medium
2009-07-30 13:50:44 +0200 mav r274485 : #i103906# optimize the usage of temporary medium
2009-07-30 13:49:53 +0200 mav r274484 : #i103906# optimize the usage of temporary medium
2009-07-30 13:49:13 +0200 mav r274483 : #i103906# optimize the usage of temporary medium
2009-07-30 13:47:09 +0200 mav r274482 : #i103905#,#i103906# let the signing process use zip-storage; optimize the usage of temporary medium
2009-07-21 09:10:31 +0200 mav r274159 : CWS-TOOLING: rebase CWS encsig09 to trunk@273468 (milestone: DEV300:m51)
2009-05-05 08:39:01 +0200 mav r271496 : #i100832# allow to sign macros only when there are any
Diffstat (limited to 'package')
-rw-r--r-- | package/inc/ZipEntry.hxx | 4 | ||||
-rw-r--r-- | package/inc/ZipFile.hxx | 1 | ||||
-rw-r--r-- | package/inc/ZipPackage.hxx | 33 | ||||
-rw-r--r-- | package/inc/ZipPackageFolder.hxx | 2 | ||||
-rw-r--r-- | package/source/manifest/ManifestDefines.hxx | 7 | ||||
-rw-r--r-- | package/source/manifest/ManifestExport.cxx | 47 | ||||
-rw-r--r-- | package/source/xstor/owriteablestream.cxx | 5 | ||||
-rw-r--r-- | package/source/xstor/xstorage.cxx | 8 | ||||
-rw-r--r-- | package/source/zipapi/ZipFile.cxx | 66 | ||||
-rw-r--r-- | package/source/zipapi/ZipOutputStream.cxx | 8 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackage.cxx | 370 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageEntry.cxx | 14 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageEntry.hxx | 1 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageFolder.cxx | 77 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageStream.cxx | 13 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageStream.hxx | 6 | ||||
-rw-r--r-- | package/source/zippackage/zipfileaccess.cxx | 4 |
17 files changed, 418 insertions, 248 deletions
diff --git a/package/inc/ZipEntry.hxx b/package/inc/ZipEntry.hxx index aa311cc14ae9..eed7a7a7cff5 100644 --- a/package/inc/ZipEntry.hxx +++ b/package/inc/ZipEntry.hxx @@ -42,8 +42,8 @@ struct ZipEntry sal_Int32 nCompressedSize; sal_Int32 nSize; sal_Int32 nOffset; - sal_Int16 nNameLen; + sal_Int16 nPathLen; sal_Int16 nExtraLen; - ::rtl::OUString sName; + ::rtl::OUString sPath; }; #endif diff --git a/package/inc/ZipFile.hxx b/package/inc/ZipFile.hxx index aaabda3181f0..a954a1691c4b 100644 --- a/package/inc/ZipFile.hxx +++ b/package/inc/ZipFile.hxx @@ -65,7 +65,6 @@ class EncryptionData; class ZipFile { protected: - ::rtl::OUString sName; /* zip file name */ ::rtl::OUString sComment; /* zip file comment */ EntryHash aEntries; ByteGrabber aGrabber; diff --git a/package/inc/ZipPackage.hxx b/package/inc/ZipPackage.hxx index b733171edc4b..0549c06b6bb7 100644 --- a/package/inc/ZipPackage.hxx +++ b/package/inc/ZipPackage.hxx @@ -86,27 +86,28 @@ class ZipPackage : public cppu::WeakImplHelper7 protected: SotMutexHolderRef m_aMutexHolder; - ::com::sun::star::uno::Sequence < sal_Int8 > aEncryptionKey; - FolderHash aRecent; - ::rtl::OUString sURL; - sal_Bool bHasEncryptedEntries; - sal_Bool bUseManifest; - sal_Bool bForceRecovery; + ::com::sun::star::uno::Sequence < sal_Int8 > m_aEncryptionKey; + FolderHash m_aRecent; + ::rtl::OUString m_aURL; + sal_Bool m_bHasEncryptedEntries; + sal_Bool m_bHasNonEncryptedEntries; + sal_Bool m_bUseManifest; + sal_Bool m_bForceRecovery; sal_Bool m_bMediaTypeFallbackUsed; sal_Int16 m_nFormat; sal_Bool m_bAllowRemoveOnInsert; - InitialisationMode eMode; + InitialisationMode m_eMode; - ::com::sun::star::uno::Reference < com::sun::star::container::XNameContainer > xRootFolder; - ::com::sun::star::uno::Reference < com::sun::star::io::XStream > xStream; - ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xContentStream; - ::com::sun::star::uno::Reference < com::sun::star::io::XSeekable > xContentSeek; - const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xFactory; + ::com::sun::star::uno::Reference < com::sun::star::container::XNameContainer > m_xRootFolder; + ::com::sun::star::uno::Reference < com::sun::star::io::XStream > m_xStream; + ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream > m_xContentStream; + ::com::sun::star::uno::Reference < com::sun::star::io::XSeekable > m_xContentSeek; + const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory; - ZipPackageFolder *pRootFolder; - ZipFile *pZipFile; + ZipPackageFolder *m_pRootFolder; + ZipFile *m_pZipFile; void parseManifest(); void parseContentType(); @@ -124,8 +125,8 @@ protected: public: ZipPackage (const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory); virtual ~ZipPackage( void ); - ZipFile& getZipFile() { return *pZipFile;} - const com::sun::star::uno::Sequence < sal_Int8 > & getEncryptionKey ( ) {return aEncryptionKey;} + ZipFile& getZipFile() { return *m_pZipFile;} + const com::sun::star::uno::Sequence < sal_Int8 > & getEncryptionKey ( ) {return m_aEncryptionKey;} sal_Int16 getFormat() const { return m_nFormat; } SotMutexHolderRef GetSharedMutexRef() { return m_aMutexHolder; } diff --git a/package/inc/ZipPackageFolder.hxx b/package/inc/ZipPackageFolder.hxx index dfe72a6975b9..1edbae7f5d3d 100644 --- a/package/inc/ZipPackageFolder.hxx +++ b/package/inc/ZipPackageFolder.hxx @@ -74,6 +74,8 @@ public: ::rtl::OUString& GetVersion() { return m_sVersion; } void SetVersion( const ::rtl::OUString& aVersion ) { m_sVersion = aVersion; } + sal_Bool LookForUnexpectedODF12Streams( const ::rtl::OUString& aPath ); + void setChildStreamsTypeByExtension( const ::com::sun::star::beans::StringPair& aPair ); void doInsertByName ( ZipPackageEntry *pEntry, sal_Bool bSetParent ) diff --git a/package/source/manifest/ManifestDefines.hxx b/package/source/manifest/ManifestDefines.hxx index 78d262358a0f..e64c650a386c 100644 --- a/package/source/manifest/ManifestDefines.hxx +++ b/package/source/manifest/ManifestDefines.hxx @@ -54,10 +54,17 @@ #define ATTRIBUTE_ALGORITHM_NAME "manifest:algorithm-name" #define ATTRIBUTE_INITIALISATION_VECTOR "manifest:initialisation-vector" +#define ELEMENT_START_KEY_GENERATION "manifest:start-key-generation" +#define ATTRIBUTE_START_KEY_GENERATION_NAME "manifest:start-key-generation-name" +#define ALGORITHM_SHA1 "SHA1" +#define ATTRIBUTE_KEY_SIZE "manifest:key-size" +#define START_KEY_SIZE "20" + #define ELEMENT_KEY_DERIVATION "manifest:key-derivation" #define ATTRIBUTE_KEY_DERIVATION_NAME "manifest:key-derivation-name" #define ATTRIBUTE_SALT "manifest:salt" #define ATTRIBUTE_ITERATION_COUNT "manifest:iteration-count" #define CHECKSUM_TYPE "SHA1/1K" +#define DERIVED_KEY_SIZE "16" #endif diff --git a/package/source/manifest/ManifestExport.cxx b/package/source/manifest/ManifestExport.cxx index 6ca9972cf729..4ae1785a0d8b 100644 --- a/package/source/manifest/ManifestExport.cxx +++ b/package/source/manifest/ManifestExport.cxx @@ -61,6 +61,7 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S const OUString sManifestElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) ); const OUString sEncryptionDataElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) ); const OUString sAlgorithmElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ALGORITHM ) ); + const OUString sStartKeyGenerationElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_START_KEY_GENERATION ) ); const OUString sKeyDerivationElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_KEY_DERIVATION ) ); const OUString sCdataAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) ); @@ -68,10 +69,12 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S const OUString sVersionAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) ); const OUString sFullPathAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_FULL_PATH ) ); const OUString sSizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SIZE ) ); + const OUString sKeySizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_SIZE ) ); const OUString sSaltAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) ); const OUString sInitialisationVectorAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_INITIALISATION_VECTOR ) ); const OUString sIterationCountAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) ); const OUString sAlgorithmNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ALGORITHM_NAME ) ); + const OUString sStartKeyGenerationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_START_KEY_GENERATION_NAME ) ); const OUString sKeyDerivationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_DERIVATION_NAME ) ); const OUString sChecksumTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM_TYPE ) ); const OUString sChecksumAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM) ); @@ -89,6 +92,9 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S const OUString sBlowfish ( RTL_CONSTASCII_USTRINGPARAM ( "Blowfish CFB" ) ); const OUString sPBKDF2 ( RTL_CONSTASCII_USTRINGPARAM ( "PBKDF2" ) ); const OUString sChecksumType ( RTL_CONSTASCII_USTRINGPARAM ( CHECKSUM_TYPE ) ); + const OUString sStartKeySize ( RTL_CONSTASCII_USTRINGPARAM ( START_KEY_SIZE ) ); + const OUString sDerivedKeySize ( RTL_CONSTASCII_USTRINGPARAM ( DERIVED_KEY_SIZE ) ); + const OUString sSHA1 ( RTL_CONSTASCII_USTRINGPARAM ( ALGORITHM_SHA1 ) ); ::comphelper::AttributeList * pRootAttrList = new ::comphelper::AttributeList; const Sequence < PropertyValue > *pSequence = rManList.getConstArray(); @@ -96,15 +102,16 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S // find the mediatype of the document if any OUString aDocMediaType; + OUString aDocVersion; for (sal_uInt32 nInd = 0; nInd < nManLength ; nInd++ ) { OUString aMediaType; OUString aPath; + OUString aVersion; const PropertyValue *pValue = pSequence[nInd].getConstArray(); for (sal_uInt32 j = 0, nNum = pSequence[nInd].getLength(); j < nNum; j++, pValue++) { - if (pValue->Name.equals (sMediaTypeProperty) ) { pValue->Value >>= aMediaType; @@ -113,20 +120,26 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S { pValue->Value >>= aPath; } + else if (pValue->Name.equals (sVersionProperty) ) + { + pValue->Value >>= aVersion; + } - if ( aPath.getLength() && aMediaType.getLength() ) + if ( aPath.getLength() && aMediaType.getLength() && aVersion.getLength() ) break; } if ( aPath.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ) ) { aDocMediaType = aMediaType; + aDocVersion = aVersion; break; } } sal_Bool bProvideDTD = sal_False; sal_Bool bAcceptNonemptyVersion = sal_False; + sal_Bool bStoreStartKeyGeneration = sal_False; if ( aDocMediaType.getLength() ) { if ( aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII ) ) ) @@ -152,6 +165,11 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_OASIS_NAMESPACE ) ) ); bAcceptNonemptyVersion = sal_True; + if ( aDocVersion.compareTo( ODFVER_012_TEXT ) >= 0 ) + { + // this is ODF12 generation, let encrypted streams contain start-key-generation entry + bStoreStartKeyGeneration = sal_True; + } } else { @@ -224,6 +242,7 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S xHandler->startElement( sFileEntryElement , xAttrList); if ( pVector && pSalt && pIterationCount ) { + // ==== Encryption Data ::comphelper::AttributeList * pNewAttrList = new ::comphelper::AttributeList; Reference < XAttributeList > xNewAttrList (pNewAttrList); OUStringBuffer aBuffer; @@ -239,6 +258,7 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S } xHandler->startElement( sEncryptionDataElement , xNewAttrList); + // ==== Algorithm pNewAttrList = new ::comphelper::AttributeList; xNewAttrList = pNewAttrList; @@ -253,11 +273,15 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S xHandler->ignorableWhitespace ( sWhiteSpace ); xHandler->endElement( sAlgorithmElement ); + // ==== Key Derivation pNewAttrList = new ::comphelper::AttributeList; xNewAttrList = pNewAttrList; pNewAttrList->AddAttribute ( sKeyDerivationNameAttribute, sCdataAttribute, sPBKDF2 ); + if ( bStoreStartKeyGeneration ) + pNewAttrList->AddAttribute ( sKeySizeAttribute, sCdataAttribute, sDerivedKeySize ); + sal_Int32 nCount = 0; pIterationCount->Value >>= nCount; aBuffer.append (nCount); @@ -271,6 +295,25 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S xHandler->startElement( sKeyDerivationElement , xNewAttrList); xHandler->ignorableWhitespace ( sWhiteSpace ); xHandler->endElement( sKeyDerivationElement ); + + // we have to store start-key-generation element as the last one to workaround the parsing problem + // in OOo3.1 and older versions + if ( bStoreStartKeyGeneration ) + { + // ==== Start Key Generation + pNewAttrList = new ::comphelper::AttributeList; + xNewAttrList = pNewAttrList; + + // currently SHA1 is used to generate 20-bytes start key + pNewAttrList->AddAttribute ( sStartKeyGenerationNameAttribute, sCdataAttribute, sSHA1 ); + pNewAttrList->AddAttribute ( sKeySizeAttribute, sCdataAttribute, sStartKeySize ); + + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->startElement( sStartKeyGenerationElement , xNewAttrList); + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->endElement( sStartKeyGenerationElement ); + } + xHandler->ignorableWhitespace ( sWhiteSpace ); xHandler->endElement( sEncryptionDataElement ); } diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx index 2b63d452a5bb..67e71baf8533 100644 --- a/package/source/xstor/owriteablestream.cxx +++ b/package/source/xstor/owriteablestream.cxx @@ -3171,7 +3171,7 @@ void SAL_CALL OWriteStream::setPropertyValue( const ::rtl::OUString& aPropertyNa m_pImpl->m_aProps[nInd].Value <<= bCompressedValueFromType; } } - else if ( m_pData->m_nStorageType == PACKAGE_STORAGE && aPropertyName.equalsAscii( "Compressed" ) ) + else if ( aPropertyName.equals( aCompressedString ) ) { // if the "Compressed" property is not set explicitly, the MediaType can change the default value m_pImpl->m_bCompressedSetExplicit = sal_True; @@ -3206,8 +3206,7 @@ void SAL_CALL OWriteStream::setPropertyValue( const ::rtl::OUString& aPropertyNa else throw lang::IllegalArgumentException(); //TODO } - else if ( m_pData->m_nStorageType == OFOPXML_STORAGE - && ( aPropertyName.equalsAscii( "MediaType" ) || aPropertyName.equalsAscii( "Compressed" ) ) ) + else if ( m_pData->m_nStorageType == OFOPXML_STORAGE && aPropertyName.equals( aMediaTypeString ) ) { for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ ) { diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx index b49fbd67b98d..4d0af7bb7619 100644 --- a/package/source/xstor/xstorage.cxx +++ b/package/source/xstor/xstorage.cxx @@ -3224,7 +3224,7 @@ sal_Bool SAL_CALL OStorage::isStreamElement( const ::rtl::OUString& aElementName m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't detect whether it is a stream!" ) ), + throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't detect whether it is a stream!" ) ), uno::Reference< io::XInputStream >(), aCaught ); } @@ -3293,7 +3293,7 @@ sal_Bool SAL_CALL OStorage::isStorageElement( const ::rtl::OUString& aElementNam m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't detect whether it is a storage" ) ), + throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "can't detect whether it is a storage" ) ), uno::Reference< io::XInputStream >(), aCaught ); } @@ -4804,6 +4804,7 @@ void SAL_CALL OStorage::setPropertyValue( const ::rtl::OUString& aPropertyName, m_pImpl->m_bIsModified = sal_True; } else if ( m_pData->m_bIsRoot && ( aPropertyName.equalsAscii( "HasEncryptedEntries" ) + || aPropertyName.equalsAscii( "HasNonEncryptedEntries" ) || aPropertyName.equalsAscii( "URL" ) || aPropertyName.equalsAscii( "RepairPackage" ) ) || aPropertyName.equalsAscii( "IsRoot" ) @@ -4937,7 +4938,8 @@ uno::Any SAL_CALL OStorage::getPropertyValue( const ::rtl::OUString& aPropertyNa return uno::makeAny( sal_False ); // RepairPackage } - else if ( m_pData->m_nStorageType == PACKAGE_STORAGE && aPropertyName.equalsAscii( "HasEncryptedEntries" ) ) + else if ( m_pData->m_nStorageType == PACKAGE_STORAGE + && ( aPropertyName.equalsAscii( "HasEncryptedEntries" ) || aPropertyName.equalsAscii( "HasNonEncryptedEntries" ) ) ) { try { m_pImpl->ReadContents(); diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx index 936ab2acd1bc..246cbd889015 100644 --- a/package/source/zipapi/ZipFile.cxx +++ b/package/source/zipapi/ZipFile.cxx @@ -608,7 +608,7 @@ sal_Bool ZipFile::readLOC( ZipEntry &rEntry ) throw(IOException, ZipException, RuntimeException) { sal_Int32 nTestSig, nTime, nCRC, nSize, nCompressedSize; - sal_Int16 nVersion, nFlag, nHow, nNameLen, nExtraLen; + sal_Int16 nVersion, nFlag, nHow, nPathLen, nExtraLen; sal_Int32 nPos = -rEntry.nOffset; aGrabber.seek(nPos); @@ -623,18 +623,32 @@ sal_Bool ZipFile::readLOC( ZipEntry &rEntry ) aGrabber >> nCRC; aGrabber >> nCompressedSize; aGrabber >> nSize; - aGrabber >> nNameLen; + aGrabber >> nPathLen; aGrabber >> nExtraLen; - rEntry.nOffset = static_cast < sal_Int32 > (aGrabber.getPosition()) + nNameLen + nExtraLen; + rEntry.nOffset = static_cast < sal_Int32 > (aGrabber.getPosition()) + nPathLen + nExtraLen; - if ( rEntry.nNameLen == -1 ) // the file was created - rEntry.nNameLen = nNameLen; + // read always in UTF8, some tools seem not to set UTF8 bit + uno::Sequence < sal_Int8 > aNameBuffer( nPathLen ); + sal_Int32 nRead = aGrabber.readBytes( aNameBuffer, nPathLen ); + if ( nRead < aNameBuffer.getLength() ) + aNameBuffer.realloc( nRead ); + + ::rtl::OUString sLOCPath = rtl::OUString::intern( (sal_Char *) aNameBuffer.getArray(), + aNameBuffer.getLength(), + RTL_TEXTENCODING_UTF8 ); + + if ( rEntry.nPathLen == -1 ) // the file was created + { + rEntry.nPathLen = nPathLen; + rEntry.sPath = sLOCPath; + } // the method can be reset for internal use so it is not checked sal_Bool bBroken = rEntry.nVersion != nVersion || rEntry.nFlag != nFlag || rEntry.nTime != nTime - || rEntry.nNameLen != nNameLen; + || rEntry.nPathLen != nPathLen + || !rEntry.sPath.equals( sLOCPath ); if ( bBroken && !bRecoveryMode ) throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "The stream seems to be broken!" ) ), @@ -749,7 +763,7 @@ sal_Int32 ZipFile::readCEN() aMemGrabber >> aEntry.nCrc; aMemGrabber >> aEntry.nCompressedSize; aMemGrabber >> aEntry.nSize; - aMemGrabber >> aEntry.nNameLen; + aMemGrabber >> aEntry.nPathLen; aMemGrabber >> aEntry.nExtraLen; aMemGrabber >> nCommentLen; aMemGrabber.skipBytes ( 8 ); @@ -758,7 +772,7 @@ sal_Int32 ZipFile::readCEN() aEntry.nOffset += nLocPos; aEntry.nOffset *= -1; - if ( aEntry.nNameLen < 0 || aEntry.nNameLen > ZIP_MAXNAMELEN ) + if ( aEntry.nPathLen < 0 || aEntry.nPathLen > ZIP_MAXNAMELEN ) throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "name length exceeds ZIP_MAXNAMELEN bytes" ) ), Reference < XInterface > () ); if ( nCommentLen < 0 || nCommentLen > ZIP_MAXNAMELEN ) @@ -768,15 +782,15 @@ sal_Int32 ZipFile::readCEN() throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "extra header info exceeds ZIP_MAXEXTRA bytes") ), Reference < XInterface > () ); // read always in UTF8, some tools seem not to set UTF8 bit - aEntry.sName = rtl::OUString::intern ( (sal_Char *) aMemGrabber.getCurrentPos(), - aEntry.nNameLen, + aEntry.sPath = rtl::OUString::intern ( (sal_Char *) aMemGrabber.getCurrentPos(), + aEntry.nPathLen, RTL_TEXTENCODING_UTF8 ); - if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aEntry.sName, sal_True ) ) + if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aEntry.sPath, sal_True ) ) throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip entry has an invalid name.") ), Reference < XInterface > () ); - aMemGrabber.skipBytes( aEntry.nNameLen + aEntry.nExtraLen + nCommentLen ); - aEntries[aEntry.sName] = aEntry; + aMemGrabber.skipBytes( aEntry.nPathLen + aEntry.nExtraLen + nCommentLen ); + aEntries[aEntry.sPath] = aEntry; } if (nCount != nTotal) @@ -830,7 +844,7 @@ sal_Int32 ZipFile::recover() aMemGrabber >> aEntry.nCrc; aMemGrabber >> aEntry.nCompressedSize; aMemGrabber >> aEntry.nSize; - aMemGrabber >> aEntry.nNameLen; + aMemGrabber >> aEntry.nPathLen; aMemGrabber >> aEntry.nExtraLen; sal_Int32 nDescrLength = @@ -842,32 +856,32 @@ sal_Int32 ZipFile::recover() // For OOo2.0 the whole package must be switched to unsigned values if ( aEntry.nCompressedSize < 0 ) aEntry.nCompressedSize = 0x7FFFFFFF; if ( aEntry.nSize < 0 ) aEntry.nSize = 0x7FFFFFFF; - if ( aEntry.nNameLen < 0 ) aEntry.nNameLen = 0x7FFF; + if ( aEntry.nPathLen < 0 ) aEntry.nPathLen = 0x7FFF; if ( aEntry.nExtraLen < 0 ) aEntry.nExtraLen = 0x7FFF; // End of quick fix - sal_Int32 nBlockLength = aEntry.nSize + aEntry.nNameLen + aEntry.nExtraLen + 30 + nDescrLength; - if ( aEntry.nNameLen <= ZIP_MAXNAMELEN && aEntry.nExtraLen < ZIP_MAXEXTRA + sal_Int32 nBlockLength = aEntry.nSize + aEntry.nPathLen + aEntry.nExtraLen + 30 + nDescrLength; + if ( aEntry.nPathLen <= ZIP_MAXNAMELEN && aEntry.nExtraLen < ZIP_MAXEXTRA && ( nGenPos + nPos + nBlockLength ) <= nLength ) { // read always in UTF8, some tools seem not to set UTF8 bit - if( nPos + 30 + aEntry.nNameLen <= nBufSize ) - aEntry.sName = OUString ( (sal_Char *) &pBuffer[nPos + 30], - aEntry.nNameLen, + if( nPos + 30 + aEntry.nPathLen <= nBufSize ) + aEntry.sPath = OUString ( (sal_Char *) &pBuffer[nPos + 30], + aEntry.nPathLen, RTL_TEXTENCODING_UTF8 ); else { Sequence < sal_Int8 > aFileName; aGrabber.seek( nGenPos + nPos + 30 ); - aGrabber.readBytes( aFileName, aEntry.nNameLen ); - aEntry.sName = OUString ( (sal_Char *) aFileName.getArray(), + aGrabber.readBytes( aFileName, aEntry.nPathLen ); + aEntry.sPath = OUString ( (sal_Char *) aFileName.getArray(), aFileName.getLength(), RTL_TEXTENCODING_UTF8 ); - aEntry.nNameLen = static_cast< sal_Int16 >(aFileName.getLength()); + aEntry.nPathLen = static_cast< sal_Int16 >(aFileName.getLength()); } - aEntry.nOffset = nGenPos + nPos + 30 + aEntry.nNameLen + aEntry.nExtraLen; + aEntry.nOffset = nGenPos + nPos + 30 + aEntry.nPathLen + aEntry.nExtraLen; if ( ( aEntry.nSize || aEntry.nCompressedSize ) && !checkSizeAndCRC( aEntry ) ) { @@ -876,8 +890,8 @@ sal_Int32 ZipFile::recover() aEntry.nSize = 0; } - if ( aEntries.find( aEntry.sName ) == aEntries.end() ) - aEntries[aEntry.sName] = aEntry; + if ( aEntries.find( aEntry.sPath ) == aEntries.end() ) + aEntries[aEntry.sPath] = aEntry; } } } diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx index 65e8369e9095..1faa37176271 100644 --- a/package/source/zipapi/ZipOutputStream.cxx +++ b/package/source/zipapi/ZipOutputStream.cxx @@ -295,10 +295,10 @@ void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength) void ZipOutputStream::writeCEN( const ZipEntry &rEntry ) throw(IOException, RuntimeException) { - if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sName, sal_True ) ) + if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, sal_True ) ) throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), Reference< XInterface >() ); - ::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sName, RTL_TEXTENCODING_UTF8 ); + ::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 ); sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() ); aChucker << CENSIG; @@ -344,10 +344,10 @@ void ZipOutputStream::writeEXT( const ZipEntry &rEntry ) sal_Int32 ZipOutputStream::writeLOC( const ZipEntry &rEntry ) throw(IOException, RuntimeException) { - if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sName, sal_True ) ) + if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, sal_True ) ) throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), Reference< XInterface >() ); - ::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sName, RTL_TEXTENCODING_UTF8 ); + ::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 ); sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() ); aChucker << LOCSIG; diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index a8c3d20be274..b95711778e77 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -199,39 +199,40 @@ class DummyInputStream : public ::cppu::WeakImplHelper1< XInputStream > ZipPackage::ZipPackage (const uno::Reference < XMultiServiceFactory > &xNewFactory) : m_aMutexHolder( new SotMutexHolder ) -, bHasEncryptedEntries ( sal_False ) -, bUseManifest ( sal_True ) -, bForceRecovery ( sal_False ) +, m_bHasEncryptedEntries ( sal_False ) +, m_bHasNonEncryptedEntries ( sal_False ) +, m_bUseManifest ( sal_True ) +, m_bForceRecovery ( sal_False ) , m_bMediaTypeFallbackUsed ( sal_False ) , m_nFormat( PACKAGE_FORMAT ) // package is the default format , m_bAllowRemoveOnInsert( sal_True ) -, eMode ( e_IMode_None ) -, xFactory( xNewFactory ) -, pRootFolder( NULL ) -, pZipFile( NULL ) +, m_eMode ( e_IMode_None ) +, m_xFactory( xNewFactory ) +, m_pRootFolder( NULL ) +, m_pZipFile( NULL ) { - xRootFolder = pRootFolder = new ZipPackageFolder( xFactory, m_nFormat, m_bAllowRemoveOnInsert ); + m_xRootFolder = m_pRootFolder = new ZipPackageFolder( m_xFactory, m_nFormat, m_bAllowRemoveOnInsert ); } ZipPackage::~ZipPackage( void ) { - delete pZipFile; + delete m_pZipFile; // All folders and streams contain pointers to their parents, when a parent diappeares // it should disconnect all the children from itself during destruction automatically. - // So there is no need in explicit pRootFolder->releaseUpwardRef() call here any more - // since pRootFolder has no parent and cleaning of it's children will be done automatically - // during pRootFolder dieing by refcount. + // So there is no need in explicit m_pRootFolder->releaseUpwardRef() call here any more + // since m_pRootFolder has no parent and cleaning of it's children will be done automatically + // during m_pRootFolder dieing by refcount. #if 0 // As all folders and streams contain references to their parents, // we must remove these references so that they will be deleted when // the hash_map of the root folder is cleared, releasing all subfolders - // and substreams which in turn release theirs, etc. When xRootFolder is + // and substreams which in turn release theirs, etc. When m_xRootFolder is // released when this destructor completes, the folder tree should be // deleted fully (and automagically). - pRootFolder->releaseUpwardRef(); + m_pRootFolder->releaseUpwardRef(); #endif } @@ -241,13 +242,13 @@ void ZipPackage::parseManifest() { sal_Bool bManifestParsed = sal_False; const OUString sMeta ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF" ) ); - if ( xRootFolder->hasByName( sMeta ) ) + if ( m_xRootFolder->hasByName( sMeta ) ) { const OUString sManifest (RTL_CONSTASCII_USTRINGPARAM( "manifest.xml") ); try { uno::Reference< XUnoTunnel > xTunnel; - Any aAny = xRootFolder->getByName( sMeta ); + Any aAny = m_xRootFolder->getByName( sMeta ); aAny >>= xTunnel; uno::Reference< XNameContainer > xMetaInfFolder( xTunnel, UNO_QUERY ); if ( xMetaInfFolder.is() && xMetaInfFolder->hasByName( sManifest ) ) @@ -258,7 +259,7 @@ void ZipPackage::parseManifest() if (xSink.is()) { OUString sManifestReader ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestReader" ) ); - uno::Reference < XManifestReader > xReader (xFactory->createInstance( sManifestReader ), UNO_QUERY ); + uno::Reference < XManifestReader > xReader (m_xFactory->createInstance( sManifestReader ), UNO_QUERY ); if ( xReader.is() ) { const OUString sPropFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); @@ -300,6 +301,7 @@ void ZipPackage::parseManifest() else if (pValue[j].Name.equals( sPropDigest ) ) pDigest = &(pValue[j].Value); } + if (sPath.getLength() && hasByHierarchicalName ( sPath ) ) { aAny = getByHierarchicalName( sPath ); @@ -316,6 +318,7 @@ void ZipPackage::parseManifest() { pStream = reinterpret_cast < ZipPackageStream* > ( xUnoTunnel->getSomething(ZipPackageStream::static_getImplementationId())); pStream->SetMediaType ( sMediaType ); + pStream->SetFromManifest( sal_True ); if (pSalt && pVector && pCount && pSize) { @@ -344,9 +347,12 @@ void ZipPackage::parseManifest() pStream->SetToBeCompressed ( sal_True ); pStream->SetToBeEncrypted ( sal_True ); pStream->SetIsEncrypted ( sal_True ); - if ( !bHasEncryptedEntries && pStream->getName().compareToAscii ( "content.xml" ) == 0 ) - bHasEncryptedEntries = sal_True; + if ( !m_bHasEncryptedEntries + && pStream->getName().equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "content.xml" ) ) ) ) + m_bHasEncryptedEntries = sal_True; } + else + m_bHasNonEncryptedEntries = sal_True; } } } @@ -354,7 +360,7 @@ void ZipPackage::parseManifest() bManifestParsed = sal_True; } else - VOS_ENSURE ( 0, "Couldn't get a ManifestReader!" ); // throw RuntimeException? + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No manifes parser!" ) ), uno::Reference< uno::XInterface >() ); } // now hide the manifest.xml file from user @@ -363,46 +369,76 @@ void ZipPackage::parseManifest() } catch( Exception& ) { - if ( !bForceRecovery ) + if ( !m_bForceRecovery ) throw; } } + if ( !bManifestParsed && !m_bForceRecovery ) + throw ZipIOException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Could not parse manifest.xml\n" ) ), + uno::Reference< uno::XInterface >() ); + const OUString sMimetype ( RTL_CONSTASCII_USTRINGPARAM ( "mimetype" ) ); - if ( xRootFolder->hasByName( sMimetype ) ) + if ( m_xRootFolder->hasByName( sMimetype ) ) { - if ( !bManifestParsed ) + // get mediatype from the "mimetype" stream + ::rtl::OUString aPackageMediatype; + uno::Reference< lang::XUnoTunnel > xMimeTypeTunnel; + m_xRootFolder->getByName( sMimetype ) >>= xMimeTypeTunnel; + uno::Reference < io::XActiveDataSink > xMimeSink( xMimeTypeTunnel, UNO_QUERY ); + if ( xMimeSink.is() ) { - // try to get mediatype from the "mimetype" stream - uno::Reference< lang::XUnoTunnel > xMimeTypeTunnel; - xRootFolder->getByName( sMimetype ) >>= xMimeTypeTunnel; - uno::Reference < io::XActiveDataSink > xMimeSink( xMimeTypeTunnel, UNO_QUERY ); - if ( xMimeSink.is() ) + uno::Reference< io::XInputStream > xMimeInStream = xMimeSink->getInputStream(); + if ( xMimeInStream.is() ) { - uno::Reference< io::XInputStream > xMimeInStream = xMimeSink->getInputStream(); - if ( xMimeInStream.is() ) - { - // Mediatypes longer than 1024 symbols should not appear here - uno::Sequence< sal_Int8 > aData( 1024 ); - sal_Int32 nRead = xMimeInStream->readBytes( aData, 1024 ); - OSL_ENSURE( nRead == aData.getLength(), "Difference between reading result and data!\n" ); - if ( nRead > aData.getLength() ) - nRead = aData.getLength(); - if ( nRead ) - { - ::rtl::OUString aFallBack( (sal_Char*)aData.getConstArray(), nRead, RTL_TEXTENCODING_ASCII_US ); - if ( aFallBack.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "application/vnd." ) ) == 0 ) - { - // accept only types that look similar to own mediatypes - pRootFolder->SetMediaType( aFallBack ); - m_bMediaTypeFallbackUsed = sal_True; - } - } - } + // Mediatypes longer than 1024 symbols should not appear here + uno::Sequence< sal_Int8 > aData( 1024 ); + sal_Int32 nRead = xMimeInStream->readBytes( aData, 1024 ); + if ( nRead > aData.getLength() ) + nRead = aData.getLength(); + + if ( nRead ) + aPackageMediatype = ::rtl::OUString( (sal_Char*)aData.getConstArray(), nRead, RTL_TEXTENCODING_ASCII_US ); } + } + + if ( !bManifestParsed ) + { + // the manifest.xml could not be successfuly parsed, this is an inconsistent package + if ( aPackageMediatype.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "application/vnd." ) ) == 0 ) + { + // accept only types that look similar to own mediatypes + m_pRootFolder->SetMediaType( aPackageMediatype ); + m_bMediaTypeFallbackUsed = sal_True; + } + } + else if ( !m_bForceRecovery ) + { + // the mimetype stream should contain the information from manifest.xml + if ( !m_pRootFolder->GetMediaType().equals( aPackageMediatype ) ) + throw ZipIOException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "mimetype conflicts with manifest.xml\n" ) ), + uno::Reference< uno::XInterface >() ); } - xRootFolder->removeByName( sMimetype ); + + m_xRootFolder->removeByName( sMimetype ); + } + + sal_Bool bODF12AndOlder = ( m_pRootFolder->GetVersion().compareTo( ODFVER_012_TEXT ) >= 0 ); + if ( !m_bForceRecovery && bODF12AndOlder && m_pRootFolder->LookForUnexpectedODF12Streams( ::rtl::OUString() ) ) + { + // this is an ODF1.2 document that contains streams not referred in the manifest.xml + throw ZipIOException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "there are streams not referred in manifest.xml\n" ) ), + uno::Reference< uno::XInterface >() ); + } + + if ( bODF12AndOlder ) + { + // it is ODF1.2 or later, let the META-INF folder be unavailable for user + m_xRootFolder->removeByName( sMeta ); } } } @@ -414,12 +450,12 @@ void ZipPackage::parseContentType() const ::rtl::OUString aContentTypes( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml" ) ); try { // the content type must exist in OFOPXML format! - if ( !xRootFolder->hasByName( aContentTypes ) ) + if ( !m_xRootFolder->hasByName( aContentTypes ) ) throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong format!" ) ), uno::Reference< uno::XInterface >() ); uno::Reference< lang::XUnoTunnel > xTunnel; - uno::Any aAny = xRootFolder->getByName( aContentTypes ); + uno::Any aAny = m_xRootFolder->getByName( aContentTypes ); aAny >>= xTunnel; uno::Reference < io::XActiveDataSink > xSink( xTunnel, UNO_QUERY ); if ( xSink.is() ) @@ -430,14 +466,14 @@ void ZipPackage::parseContentType() sal_Int32 nInd = 0; // here aContentTypeInfo[0] - Defaults, and aContentTypeInfo[1] - Overrides uno::Sequence< uno::Sequence< beans::StringPair > > aContentTypeInfo = - ::comphelper::OFOPXMLHelper::ReadContentTypeSequence( xInStream, xFactory ); + ::comphelper::OFOPXMLHelper::ReadContentTypeSequence( xInStream, m_xFactory ); if ( aContentTypeInfo.getLength() != 2 ) throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // set the implicit types fist for ( nInd = 0; nInd < aContentTypeInfo[0].getLength(); nInd++ ) - pRootFolder->setChildStreamsTypeByExtension( aContentTypeInfo[0][nInd] ); + m_pRootFolder->setChildStreamsTypeByExtension( aContentTypeInfo[0][nInd] ); // now set the explicit types for ( nInd = 0; nInd < aContentTypeInfo[1].getLength(); nInd++ ) @@ -465,11 +501,11 @@ void ZipPackage::parseContentType() } } - xRootFolder->removeByName( aContentTypes ); + m_xRootFolder->removeByName( aContentTypes ); } catch( uno::Exception& ) { - if ( !bForceRecovery ) + if ( !m_bForceRecovery ) throw; } } @@ -477,7 +513,7 @@ void ZipPackage::parseContentType() void ZipPackage::getZipFileContents() { - auto_ptr < ZipEnumeration > pEnum ( pZipFile->entries() ); + auto_ptr < ZipEnumeration > pEnum ( m_pZipFile->entries() ); ZipPackageStream *pPkgStream; ZipPackageFolder *pPkgFolder, *pCurrent; OUString sTemp, sDirName; @@ -487,20 +523,20 @@ void ZipPackage::getZipFileContents() while (pEnum->hasMoreElements()) { nIndex = nOldIndex = 0; - pCurrent = pRootFolder; + pCurrent = m_pRootFolder; const ZipEntry & rEntry = *pEnum->nextElement(); - const OUString & rName = rEntry.sName; + const OUString & rName = rEntry.sPath; nStreamIndex = rName.lastIndexOf ( '/' ); if ( nStreamIndex != -1 ) { sDirName = rName.copy ( 0, nStreamIndex); - aIter = aRecent.find ( sDirName ); - if ( aIter != aRecent.end() ) + aIter = m_aRecent.find ( sDirName ); + if ( aIter != m_aRecent.end() ) pCurrent = (*aIter).second; } - if ( pCurrent == pRootFolder ) + if ( pCurrent == m_pRootFolder ) { while ( (nIndex = rName.indexOf('/', nOldIndex) ) != -1 ) { @@ -509,7 +545,7 @@ void ZipPackage::getZipFileContents() break; if ( !pCurrent->hasByName( sTemp ) ) { - pPkgFolder = new ZipPackageFolder( xFactory, m_nFormat, m_bAllowRemoveOnInsert ); + pPkgFolder = new ZipPackageFolder( m_xFactory, m_nFormat, m_bAllowRemoveOnInsert ); pPkgFolder->setName( sTemp ); pPkgFolder->doSetParent( pCurrent, sal_True ); pCurrent = pPkgFolder; @@ -519,13 +555,13 @@ void ZipPackage::getZipFileContents() nOldIndex = nIndex+1; } if ( nStreamIndex != -1 && sDirName.getLength() ) - aRecent [ sDirName ] = pCurrent; + m_aRecent [ sDirName ] = pCurrent; } if ( rName.getLength() -1 != nStreamIndex ) { nStreamIndex++; sTemp = rName.copy( nStreamIndex, rName.getLength() - nStreamIndex); - pPkgStream = new ZipPackageStream( *this, xFactory, m_bAllowRemoveOnInsert ); + pPkgStream = new ZipPackageStream( *this, m_xFactory, m_bAllowRemoveOnInsert ); pPkgStream->SetPackageMember( sal_True ); pPkgStream->setZipEntryOnLoading( rEntry ); pPkgStream->setName( sTemp ); @@ -555,13 +591,13 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) OUString aParamUrl; if ( (aArguments[ind] >>= aParamUrl)) { - eMode = e_IMode_URL; + m_eMode = e_IMode_URL; try { sal_Int32 nParam = aParamUrl.indexOf( '?' ); if ( nParam >= 0 ) { - sURL = aParamUrl.copy( 0, nParam ); + m_aURL = aParamUrl.copy( 0, nParam ); OUString aParam = aParamUrl.copy( nParam + 1 ); sal_Int32 nIndex = 0; @@ -570,28 +606,28 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) ::rtl::OUString aCommand = aParam.getToken( 0, '&', nIndex ); if ( aCommand.equals( OUString::createFromAscii( "repairpackage" ) ) ) { - bForceRecovery = sal_True; + m_bForceRecovery = sal_True; break; } else if ( aCommand.equals( OUString::createFromAscii( "purezip" ) ) ) { m_nFormat = ZIP_FORMAT; - pRootFolder->setPackageFormat_Impl( m_nFormat ); + m_pRootFolder->setPackageFormat_Impl( m_nFormat ); break; } else if ( aCommand.equals( OUString::createFromAscii( "ofopxml" ) ) ) { m_nFormat = OFOPXML_FORMAT; - pRootFolder->setPackageFormat_Impl( m_nFormat ); + m_pRootFolder->setPackageFormat_Impl( m_nFormat ); break; } } while ( nIndex >= 0 ); } else - sURL = aParamUrl; + m_aURL = aParamUrl; - Content aContent ( sURL, uno::Reference < XCommandEnvironment >() ); + Content aContent ( m_aURL, uno::Reference < XCommandEnvironment >() ); Any aAny = aContent.getPropertyValue( OUString::createFromAscii( "Size" ) ); sal_uInt64 aSize = 0; // kind of optimisation: treat empty files as nonexistent files @@ -601,7 +637,7 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) { uno::Reference < XActiveDataSink > xSink = new ZipPackageSink; if (aContent.openStream ( xSink ) ) - xContentStream = xSink->getInputStream(); + m_xContentStream = xSink->getInputStream(); } else bHaveZipFile = sal_False; @@ -614,20 +650,20 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) bHaveZipFile = sal_False; } } - else if ( (aArguments[ind] >>= xStream ) ) + else if ( (aArguments[ind] >>= m_xStream ) ) { // a writable stream can implement both XStream & XInputStream - eMode = e_IMode_XStream; - xContentStream = xStream->getInputStream(); + m_eMode = e_IMode_XStream; + m_xContentStream = m_xStream->getInputStream(); } - else if ( (aArguments[ind] >>= xContentStream) ) + else if ( (aArguments[ind] >>= m_xContentStream) ) { - eMode = e_IMode_XInputStream; + m_eMode = e_IMode_XInputStream; } else if ( ( aArguments[ind] >>= aNamedValue ) ) { if ( aNamedValue.Name.equalsAscii( "RepairPackage" ) ) - aNamedValue.Value >>= bForceRecovery; + aNamedValue.Value >>= m_bForceRecovery; else if ( aNamedValue.Name.equalsAscii( "PackageFormat" ) ) { // setting this argument to true means Package format @@ -638,27 +674,27 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) if ( !bPackFormat ) m_nFormat = ZIP_FORMAT; - pRootFolder->setPackageFormat_Impl( m_nFormat ); + m_pRootFolder->setPackageFormat_Impl( m_nFormat ); } else if ( aNamedValue.Name.equalsAscii( "StorageFormat" ) ) { ::rtl::OUString aFormatName; aNamedValue.Value >>= aFormatName; - if ( aFormatName.equalsAscii( "PackageFormat" ) ) + if ( aFormatName.equals( PACKAGE_STORAGE_FORMAT_STRING ) ) m_nFormat = PACKAGE_FORMAT; - else if ( aFormatName.equalsAscii( "ZipFormat" ) ) + else if ( aFormatName.equals( ZIP_STORAGE_FORMAT_STRING ) ) m_nFormat = ZIP_FORMAT; - else if ( aFormatName.equalsAscii( "OFOPXMLFormat" ) ) + else if ( aFormatName.equals( OFOPXML_STORAGE_FORMAT_STRING ) ) m_nFormat = OFOPXML_FORMAT; else throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - pRootFolder->setPackageFormat_Impl( m_nFormat ); + m_pRootFolder->setPackageFormat_Impl( m_nFormat ); } else if ( aNamedValue.Name.equalsAscii( "AllowRemoveOnInsert" ) ) { aNamedValue.Value >>= m_bAllowRemoveOnInsert; - pRootFolder->setRemoveOnInsertMode_Impl( m_bAllowRemoveOnInsert ); + m_pRootFolder->setRemoveOnInsertMode_Impl( m_bAllowRemoveOnInsert ); } // for now the progress handler is not used, probably it will never be @@ -674,16 +710,16 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) try { - if (xContentStream.is()) + if (m_xContentStream.is()) { // the stream must be seekable, if it is not it will be wrapped - xContentStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( xContentStream, xFactory ); - xContentSeek = uno::Reference < XSeekable > ( xContentStream, UNO_QUERY ); - if ( ! xContentSeek.is() ) + m_xContentStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( m_xContentStream, m_xFactory ); + m_xContentSeek = uno::Reference < XSeekable > ( m_xContentStream, UNO_QUERY ); + if ( ! m_xContentSeek.is() ) throw com::sun::star::uno::Exception ( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "The package component _requires_ an XSeekable interface!" ) ), static_cast < ::cppu::OWeakObject * > ( this ) ); - if ( !xContentSeek->getLength() ) + if ( !m_xContentSeek->getLength() ) bHaveZipFile = sal_False; } else @@ -700,7 +736,7 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) { try { - pZipFile = new ZipFile ( xContentStream, xFactory, sal_True, bForceRecovery, xProgressHandler ); + m_pZipFile = new ZipFile ( m_xContentStream, m_xFactory, sal_True, m_bForceRecovery, xProgressHandler ); getZipFileContents(); } catch ( IOException & ) @@ -713,14 +749,14 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) } catch ( Exception & ) { - if( pZipFile ) { delete pZipFile; pZipFile = NULL; } + if( m_pZipFile ) { delete m_pZipFile; m_pZipFile = NULL; } throw; } if ( bBadZipFile ) { // clean up the memory, and tell the UCB about the error - if( pZipFile ) { delete pZipFile; pZipFile = NULL; } + if( m_pZipFile ) { delete m_pZipFile; m_pZipFile = NULL; } throw com::sun::star::packages::zip::ZipIOException ( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Bad Zip File." ) ), @@ -740,7 +776,7 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) FolderHash::iterator aIter; if ( (nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) - return makeAny ( uno::Reference < XUnoTunnel > (pRootFolder) ); + return makeAny ( uno::Reference < XUnoTunnel > (m_pRootFolder) ); else { nStreamIndex = aName.lastIndexOf ( '/' ); @@ -748,8 +784,8 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) if ( nStreamIndex != -1 ) { sDirName = aName.copy ( 0, nStreamIndex); - aIter = aRecent.find ( sDirName ); - if ( aIter != aRecent.end() ) + aIter = m_aRecent.find ( sDirName ); + if ( aIter != m_aRecent.end() ) { if ( bFolder ) { @@ -758,7 +794,7 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) if ( sTemp == (*aIter).second->getName() ) return makeAny ( uno::Reference < XUnoTunnel > ( (*aIter).second ) ); else - aRecent.erase ( aIter ); + m_aRecent.erase ( aIter ); } else { @@ -766,17 +802,17 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) if ( (*aIter).second->hasByName( sTemp ) ) return (*aIter).second->getByName( sTemp ); else - aRecent.erase( aIter ); + m_aRecent.erase( aIter ); } } } else { - if ( pRootFolder->hasByName ( aName ) ) - return pRootFolder->getByName ( aName ); + if ( m_pRootFolder->hasByName ( aName ) ) + return m_pRootFolder->getByName ( aName ); } nOldIndex = 0; - ZipPackageFolder * pCurrent = pRootFolder; + ZipPackageFolder * pCurrent = m_pRootFolder; ZipPackageFolder * pPrevious = NULL; while ( ( nIndex = aName.indexOf('/', nOldIndex)) != -1) { @@ -795,7 +831,7 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) if ( bFolder ) { if (nStreamIndex != -1 ) - aRecent[sDirName] = pPrevious; + m_aRecent[sDirName] = pPrevious; return makeAny ( uno::Reference < XUnoTunnel > ( pCurrent ) ); } else @@ -804,7 +840,7 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) if ( pCurrent->hasByName ( sTemp ) ) { if (nStreamIndex != -1 ) - aRecent[sDirName] = pCurrent; + m_aRecent[sDirName] = pCurrent; return pCurrent->getByName( sTemp ); } else @@ -829,8 +865,8 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) if ( nStreamIndex != -1 ) { sDirName = aName.copy ( 0, nStreamIndex); - aIter = aRecent.find ( sDirName ); - if ( aIter != aRecent.end() ) + aIter = m_aRecent.find ( sDirName ); + if ( aIter != m_aRecent.end() ) { if ( bFolder ) { @@ -839,7 +875,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) if ( sTemp == (*aIter).second->getName() ) return sal_True; else - aRecent.erase ( aIter ); + m_aRecent.erase ( aIter ); } else { @@ -847,16 +883,16 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) if ( (*aIter).second->hasByName( sTemp ) ) return sal_True; else - aRecent.erase( aIter ); + m_aRecent.erase( aIter ); } } } else { - if ( pRootFolder->hasByName ( aName ) ) + if ( m_pRootFolder->hasByName ( aName ) ) return sal_True; } - ZipPackageFolder * pCurrent = pRootFolder; + ZipPackageFolder * pCurrent = m_pRootFolder; ZipPackageFolder * pPrevious = NULL; nOldIndex = 0; while ( ( nIndex = aName.indexOf('/', nOldIndex)) != -1) @@ -875,7 +911,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) } if ( bFolder ) { - aRecent[sDirName] = pPrevious; + m_aRecent[sDirName] = pPrevious; return sal_True; } else @@ -884,7 +920,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) if ( pCurrent->hasByName( sTemp ) ) { - aRecent[sDirName] = pCurrent; + m_aRecent[sDirName] = pCurrent; return sal_True; } } @@ -896,7 +932,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) uno::Reference< XInterface > SAL_CALL ZipPackage::createInstance( ) throw(Exception, RuntimeException) { - uno::Reference < XInterface > xRef = *(new ZipPackageStream ( *this, xFactory, m_bAllowRemoveOnInsert )); + uno::Reference < XInterface > xRef = *(new ZipPackageStream ( *this, m_xFactory, m_bAllowRemoveOnInsert )); return xRef; } uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( const Sequence< Any >& aArguments ) @@ -907,9 +943,9 @@ uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( c if ( aArguments.getLength() ) aArguments[0] >>= bArg; if (bArg) - xRef = *new ZipPackageFolder ( xFactory, m_nFormat, m_bAllowRemoveOnInsert ); + xRef = *new ZipPackageFolder ( m_xFactory, m_nFormat, m_bAllowRemoveOnInsert ); else - xRef = *new ZipPackageStream ( *this, xFactory, m_bAllowRemoveOnInsert ); + xRef = *new ZipPackageStream ( *this, m_xFactory, m_bAllowRemoveOnInsert ); return xRef; } @@ -917,17 +953,17 @@ uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( c void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut ) { const OUString sMime ( RTL_CONSTASCII_USTRINGPARAM ( "mimetype" ) ); - if (xRootFolder->hasByName( sMime ) ) - xRootFolder->removeByName( sMime ); + if (m_xRootFolder->hasByName( sMime ) ) + m_xRootFolder->removeByName( sMime ); ZipEntry * pEntry = new ZipEntry; - sal_Int32 nBufferLength = pRootFolder->GetMediaType( ).getLength(); - OString sMediaType = OUStringToOString( pRootFolder->GetMediaType(), RTL_TEXTENCODING_ASCII_US ); + sal_Int32 nBufferLength = m_pRootFolder->GetMediaType( ).getLength(); + OString sMediaType = OUStringToOString( m_pRootFolder->GetMediaType(), RTL_TEXTENCODING_ASCII_US ); Sequence< sal_Int8 > aType( (sal_Int8*)sMediaType.getStr(), nBufferLength ); - pEntry->sName = sMime; + pEntry->sPath = sMime; pEntry->nMethod = STORED; pEntry->nSize = pEntry->nCompressedSize = nBufferLength; pEntry->nTime = ZipOutputStream::getCurrentDosTime(); @@ -958,14 +994,14 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< Sequence // Write the manifest uno::Reference < XOutputStream > xManOutStream; OUString sManifestWriter( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestWriter" ) ); - uno::Reference < XManifestWriter > xWriter ( xFactory->createInstance( sManifestWriter ), UNO_QUERY ); + uno::Reference < XManifestWriter > xWriter ( m_xFactory->createInstance( sManifestWriter ), UNO_QUERY ); if ( xWriter.is() ) { ZipEntry * pEntry = new ZipEntry; ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize ); xManOutStream = uno::Reference < XOutputStream > (*pBuffer, UNO_QUERY); - pEntry->sName = OUString( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml") ); + pEntry->sPath = OUString( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml") ); pEntry->nMethod = DEFLATED; pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1; pEntry->nTime = ZipOutputStream::getCurrentDosTime(); @@ -1008,7 +1044,7 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequ ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize ); uno::Reference< io::XOutputStream > xConTypeOutStream( *pBuffer, UNO_QUERY ); - pEntry->sName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml") ); + pEntry->sPath = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml") ); pEntry->nMethod = DEFLATED; pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1; pEntry->nTime = ZipOutputStream::getCurrentDosTime(); @@ -1040,7 +1076,7 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequ aOverridesSequence.realloc( nSeqLength ); ::comphelper::OFOPXMLHelper::WriteContentSequence( - xConTypeOutStream, aDefaultsSequence, aOverridesSequence, xFactory ); + xConTypeOutStream, aDefaultsSequence, aOverridesSequence, m_xFactory ); sal_Int32 nBufferLength = static_cast < sal_Int32 > ( pBuffer->getPosition() ); pBuffer->realloc( nBufferLength ); @@ -1054,15 +1090,15 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequ void ZipPackage::ConnectTo( const uno::Reference< io::XInputStream >& xInStream ) { - xContentSeek.set( xInStream, uno::UNO_QUERY_THROW ); - xContentStream = xInStream; + m_xContentSeek.set( xInStream, uno::UNO_QUERY_THROW ); + m_xContentStream = xInStream; // seek back to the beginning of the temp file so we can read segments from it - xContentSeek->seek( 0 ); - if ( pZipFile ) - pZipFile->setInputStream( xContentStream ); + m_xContentSeek->seek( 0 ); + if ( m_pZipFile ) + m_pZipFile->setInputStream( m_xContentStream ); else - pZipFile = new ZipFile ( xContentStream, xFactory, sal_False ); + m_pZipFile = new ZipFile ( m_xContentStream, m_xFactory, sal_False ); } uno::Reference< io::XInputStream > ZipPackage::writeTempFile() @@ -1079,7 +1115,7 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() uno::Reference < io::XOutputStream > xTempOut; uno::Reference< io::XActiveDataStreamer > xSink; - if ( eMode == e_IMode_URL && !pZipFile && isLocalFile_Impl( sURL ) ) + if ( m_eMode == e_IMode_URL && !m_pZipFile && isLocalFile_Impl( m_aURL ) ) { xSink = openOriginalForOutput(); if( xSink.is() ) @@ -1093,10 +1129,10 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() } } } - else if ( eMode == e_IMode_XStream && !pZipFile ) + else if ( m_eMode == e_IMode_XStream && !m_pZipFile ) { // write directly to an empty stream - xTempOut = xStream->getOutputStream(); + xTempOut = m_xStream->getOutputStream(); if( xTempOut.is() ) bUseTemp = sal_False; } @@ -1105,7 +1141,7 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() { // create temporary file const OUString sServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) ); - uno::Reference < io::XStream > xTempFile( xFactory->createInstance ( sServiceName ), UNO_QUERY_THROW ); + uno::Reference < io::XStream > xTempFile( m_xFactory->createInstance ( sServiceName ), UNO_QUERY_THROW ); xTempOut.set( xTempFile->getOutputStream(), UNO_SET_THROW ); xTempIn.set( xTempFile->getInputStream(), UNO_SET_THROW ); } @@ -1124,12 +1160,12 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() // META-INF directory implicitly created if does not exist const OUString sMeta ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF" ) ); - if ( xRootFolder->hasByName( sMeta ) ) + if ( m_xRootFolder->hasByName( sMeta ) ) { const OUString sManifest (RTL_CONSTASCII_USTRINGPARAM( "manifest.xml") ); uno::Reference< XUnoTunnel > xTunnel; - Any aAny = xRootFolder->getByName( sMeta ); + Any aAny = m_xRootFolder->getByName( sMeta ); aAny >>= xTunnel; uno::Reference< XNameContainer > xMetaInfFolder( xTunnel, UNO_QUERY ); if ( xMetaInfFolder.is() && xMetaInfFolder->hasByName( sManifest ) ) @@ -1146,8 +1182,8 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() const ::rtl::OUString aContentTypes( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml" ) ); - if ( xRootFolder->hasByName( aContentTypes ) ) - xRootFolder->removeByName( aContentTypes ); + if ( m_xRootFolder->hasByName( aContentTypes ) ) + m_xRootFolder->removeByName( aContentTypes ); } // Create a vector to store data for the manifest.xml file @@ -1161,9 +1197,9 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() { Sequence < PropertyValue > aPropSeq ( PKG_SIZE_NOENCR_MNFST ); aPropSeq [PKG_MNFST_MEDIATYPE].Name = sMediaType; - aPropSeq [PKG_MNFST_MEDIATYPE].Value <<= pRootFolder->GetMediaType( ); + aPropSeq [PKG_MNFST_MEDIATYPE].Value <<= m_pRootFolder->GetMediaType( ); aPropSeq [PKG_MNFST_VERSION].Name = sVersion; - aPropSeq [PKG_MNFST_VERSION].Value <<= pRootFolder->GetVersion( ); + aPropSeq [PKG_MNFST_VERSION].Value <<= m_pRootFolder->GetVersion( ); aPropSeq [PKG_MNFST_FULLPATH].Name = sFullPath; aPropSeq [PKG_MNFST_FULLPATH].Value <<= OUString ( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); @@ -1181,12 +1217,12 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() // call saveContents (it will recursively save sub-directories OUString aEmptyString; - pRootFolder->saveContents( aEmptyString, aManList, aZipOut, aEncryptionKey, aRandomPool ); + m_pRootFolder->saveContents( aEmptyString, aManList, aZipOut, m_aEncryptionKey, aRandomPool ); // Clean up random pool memory rtl_random_destroyPool ( aRandomPool ); - if( bUseManifest && m_nFormat == PACKAGE_FORMAT ) + if( m_bUseManifest && m_nFormat == PACKAGE_FORMAT ) { WriteManifest( aZipOut, aManList ); } @@ -1214,10 +1250,10 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() // no need to postpone switching to the new stream since the target was written directly uno::Reference< io::XInputStream > xNewStream; - if ( eMode == e_IMode_URL ) + if ( m_eMode == e_IMode_URL ) xNewStream = xSink->getStream()->getInputStream(); - else if ( eMode == e_IMode_XStream && xStream.is() ) - xNewStream = xStream->getInputStream(); + else if ( m_eMode == e_IMode_XStream && m_xStream.is() ) + xNewStream = m_xStream->getInputStream(); if ( xNewStream.is() ) ConnectTo( xNewStream ); @@ -1258,10 +1294,10 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() uno::Reference< XActiveDataStreamer > ZipPackage::openOriginalForOutput() { // open and truncate the original file - Content aOriginalContent (sURL, uno::Reference < XCommandEnvironment >() ); + Content aOriginalContent (m_aURL, uno::Reference < XCommandEnvironment >() ); uno::Reference< XActiveDataStreamer > xSink = new ActiveDataStreamer; - if ( eMode == e_IMode_URL ) + if ( m_eMode == e_IMode_URL ) { try { @@ -1313,7 +1349,7 @@ void SAL_CALL ZipPackage::commitChanges() // lock the component for the time of commiting ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); - if ( eMode == e_IMode_XInputStream ) + if ( m_eMode == e_IMode_XInputStream ) { IOException aException; throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package is read only!" ) ), @@ -1331,9 +1367,9 @@ void SAL_CALL ZipPackage::commitChanges() uno::Reference< io::XSeekable > xTempSeek( xTempInStream, uno::UNO_QUERY_THROW ); // switch to the new temporary stream only after the transfer - PostinitializationGuard( xTempInStream, *this ); + PostinitializationGuard aPostInitGuard( xTempInStream, *this ); - if ( eMode == e_IMode_XStream ) + if ( m_eMode == e_IMode_XStream ) { // First truncate our output stream uno::Reference < XOutputStream > xOutputStream; @@ -1343,7 +1379,7 @@ void SAL_CALL ZipPackage::commitChanges() { xTempSeek->seek( 0 ); - xOutputStream = xStream->getOutputStream(); + xOutputStream = m_xStream->getOutputStream(); uno::Reference < XTruncate > xTruncate ( xOutputStream, UNO_QUERY ); if ( !xTruncate.is() ) throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -1376,16 +1412,16 @@ void SAL_CALL ZipPackage::commitChanges() DisconnectFromTargetAndThrowException_Impl( xTempInStream ); } } - else if ( eMode == e_IMode_URL ) + else if ( m_eMode == e_IMode_URL ) { uno::Reference< XOutputStream > aOrigFileStream; sal_Bool bCanBeCorrupted = sal_False; - if( isLocalFile_Impl( sURL ) ) + if( isLocalFile_Impl( m_aURL ) ) { // write directly in case of local file uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xSimpleAccess( - xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), + m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), uno::UNO_QUERY ); OSL_ENSURE( xSimpleAccess.is(), "Can't instatiate SimpleFileAccess service!\n" ); uno::Reference< io::XTruncate > xOrigTruncate; @@ -1393,7 +1429,7 @@ void SAL_CALL ZipPackage::commitChanges() { try { - aOrigFileStream = xSimpleAccess->openFileWrite( sURL ); + aOrigFileStream = xSimpleAccess->openFileWrite( m_aURL ); xOrigTruncate = uno::Reference< io::XTruncate >( aOrigFileStream, uno::UNO_QUERY_THROW ); // after successful truncation the file is already corrupted xOrigTruncate->truncate(); @@ -1431,7 +1467,7 @@ void SAL_CALL ZipPackage::commitChanges() if ( !xPropSet.is() ) throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - OUString sTargetFolder = sURL.copy ( 0, sURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) ); + OUString sTargetFolder = m_aURL.copy ( 0, m_aURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) ); Content aContent ( sTargetFolder, uno::Reference < XCommandEnvironment > () ); OUString sTempURL; @@ -1442,7 +1478,7 @@ void SAL_CALL ZipPackage::commitChanges() aInfo.NameClash = NameClash::OVERWRITE; aInfo.MoveData = sal_False; aInfo.SourceURL = sTempURL; - aInfo.NewTitle = rtl::Uri::decode ( sURL.copy ( 1 + sURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) ), + aInfo.NewTitle = rtl::Uri::decode ( m_aURL.copy ( 1 + m_aURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) ), rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); aAny <<= aInfo; @@ -1472,11 +1508,11 @@ void SAL_CALL ZipPackage::commitChanges() void ZipPackage::DisconnectFromTargetAndThrowException_Impl( const uno::Reference< io::XInputStream >& xTempStream ) { - xStream = uno::Reference< io::XStream >( xTempStream, uno::UNO_QUERY ); - if ( xStream.is() ) - eMode = e_IMode_XStream; + m_xStream = uno::Reference< io::XStream >( xTempStream, uno::UNO_QUERY ); + if ( m_xStream.is() ) + m_eMode = e_IMode_XStream; else - eMode = e_IMode_XInputStream; + m_eMode = e_IMode_XInputStream; ::rtl::OUString aTempURL; try { @@ -1596,16 +1632,17 @@ void SAL_CALL ZipPackage::setPropertyValue( const OUString& aPropertyName, const throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("HasEncryptedEntries") ) + ||aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("HasNonEncryptedEntries") ) ||aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MediaTypeFallbackUsed") ) ) throw PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("EncryptionKey") ) ) { - if (!( aValue >>= aEncryptionKey ) ) + if (!( aValue >>= m_aEncryptionKey ) ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); } else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseManifest") ) ) { - if (!( aValue >>= bUseManifest ) ) + if (!( aValue >>= m_bUseManifest ) ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); } else @@ -1621,17 +1658,22 @@ Any SAL_CALL ZipPackage::getPropertyValue( const OUString& PropertyName ) Any aAny; if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "EncryptionKey" ) ) ) { - aAny <<= aEncryptionKey; + aAny <<= m_aEncryptionKey; return aAny; } else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "HasEncryptedEntries" ) ) ) { - aAny <<= bHasEncryptedEntries; + aAny <<= m_bHasEncryptedEntries; + return aAny; + } + else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "HasNonEncryptedEntries" ) ) ) + { + aAny <<= m_bHasNonEncryptedEntries; return aAny; } else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "UseManifest" ) ) ) { - aAny <<= bUseManifest; + aAny <<= m_bUseManifest; return aAny; } else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "MediaTypeFallbackUsed" ) ) ) diff --git a/package/source/zippackage/ZipPackageEntry.cxx b/package/source/zippackage/ZipPackageEntry.cxx index 78fbb7423aa7..b233e34c2a28 100644 --- a/package/source/zippackage/ZipPackageEntry.cxx +++ b/package/source/zippackage/ZipPackageEntry.cxx @@ -65,20 +65,20 @@ ZipPackageEntry::~ZipPackageEntry() OUString SAL_CALL ZipPackageEntry::getName( ) throw(RuntimeException) { - return aEntry.sName; + return msName; } void SAL_CALL ZipPackageEntry::setName( const OUString& aName ) throw(RuntimeException) { - if ( pParent && pParent->hasByName ( aEntry.sName ) ) - pParent->removeByName ( aEntry.sName ); + if ( pParent && msName.getLength() && pParent->hasByName ( msName ) ) + pParent->removeByName ( msName ); // unfortunately no other exception than RuntimeException can be thrown here // usually the package is used through storage implementation, the problem should be detected there if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, sal_True ) ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected character is used in file name." ) ), Reference< XInterface >() ); - aEntry.sName = aName; + msName = aName; if ( pParent ) pParent->doInsertByName ( this, sal_False ); @@ -94,7 +94,7 @@ void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent, sal_Bool bIns { // xParent = pParent = pNewParent; pParent = pNewParent; - if ( bInsert && !pNewParent->hasByName ( aEntry.sName ) ) + if ( bInsert && msName.getLength() && !pNewParent->hasByName ( msName ) ) pNewParent->doInsertByName ( this, sal_False ); } @@ -110,8 +110,8 @@ void SAL_CALL ZipPackageEntry::setParent( const Reference< XInterface >& xNewPar if ( pNewParent != pParent ) { - if ( pParent && pParent->hasByName ( aEntry.sName ) && mbAllowRemoveOnInsert ) - pParent->removeByName( aEntry.sName ); + if ( pParent && msName.getLength() && pParent->hasByName ( msName ) && mbAllowRemoveOnInsert ) + pParent->removeByName( msName ); doSetParent ( pNewParent, sal_True ); } } diff --git a/package/source/zippackage/ZipPackageEntry.hxx b/package/source/zippackage/ZipPackageEntry.hxx index 89fe4c6f225b..01b47d71f728 100644 --- a/package/source/zippackage/ZipPackageEntry.hxx +++ b/package/source/zippackage/ZipPackageEntry.hxx @@ -53,6 +53,7 @@ class ZipPackageEntry : public cppu::WeakImplHelper5 > { protected: + ::rtl::OUString msName; bool mbIsFolder:1; bool mbAllowRemoveOnInsert:1; // com::sun::star::uno::Reference < com::sun::star::container::XNameContainer > xParent; diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx index 2787ad938df9..5215c07579d2 100644 --- a/package/source/zippackage/ZipPackageFolder.cxx +++ b/package/source/zippackage/ZipPackageFolder.cxx @@ -93,6 +93,60 @@ ZipPackageFolder::~ZipPackageFolder() { } +sal_Bool ZipPackageFolder::LookForUnexpectedODF12Streams( const ::rtl::OUString& aPath ) +{ + sal_Bool bHasUnexpected = sal_False; + + for ( ContentHash::const_iterator aCI = maContents.begin(), aEnd = maContents.end(); + !bHasUnexpected && aCI != aEnd; + aCI++) + { + const OUString &rShortName = (*aCI).first; + const ContentInfo &rInfo = *(*aCI).second; + + if ( rInfo.bFolder ) + { + if ( aPath.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "META-INF/" ) ) ) ) + { + // META-INF is not allowed to contain subfolders + bHasUnexpected = sal_True; + } + else + { + OUString sOwnPath = aPath + rShortName + OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); + bHasUnexpected = rInfo.pFolder->LookForUnexpectedODF12Streams( sOwnPath ); + } + } + else + { + if ( aPath.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "META-INF/" ) ) ) ) + { + if ( !rShortName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "manifest.xml" ) ) ) + && rShortName.indexOf( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "signatures" ) ) ) == -1 ) + { + // a stream from META-INF with unexpected name + bHasUnexpected = sal_True; + } + + // streams from META-INF with expected names are allowed not to be registered in manifest.xml + } + else if ( !rInfo.pStream->IsFromManifest() ) + { + // the stream is not in META-INF and ist notregistered in manifest.xml, + // check whether it is an internal part of the package format + if ( aPath.getLength() + || !rShortName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "mimetype" ) ) ) ) + { + // if it is not "mimetype" from the root it is not a part of the package + bHasUnexpected = sal_True; + } + } + } + } + + return bHasUnexpected; +} + void ZipPackageFolder::setChildStreamsTypeByExtension( const beans::StringPair& aPair ) { ::rtl::OUString aExt; @@ -112,9 +166,9 @@ void ZipPackageFolder::setChildStreamsTypeByExtension( const beans::StringPair& rInfo.pFolder->setChildStreamsTypeByExtension( aPair ); else { - sal_Int32 nNameLength = rShortName.getLength(); + sal_Int32 nPathLength = rShortName.getLength(); sal_Int32 nExtLength = aExt.getLength(); - if ( nNameLength >= nExtLength && rShortName.match( aExt, nNameLength - nExtLength ) ) + if ( nPathLength >= nExtLength && rShortName.match( aExt, nPathLength - nExtLength ) ) rInfo.pStream->SetMediaType( aPair.Second ); } } @@ -130,8 +184,8 @@ void ZipPackageFolder::copyZipEntry( ZipEntry &rDest, const ZipEntry &rSource) rDest.nCompressedSize = rSource.nCompressedSize; rDest.nSize = rSource.nSize; rDest.nOffset = rSource.nOffset; - rDest.sName = rSource.sName; - rDest.nNameLen = rSource.nNameLen; + rDest.sPath = rSource.sPath; + rDest.nPathLen = rSource.nPathLen; rDest.nExtraLen = rSource.nExtraLen; } @@ -271,9 +325,9 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr // it is an empty subfolder, use workaround to store it ZipEntry* pTempEntry = new ZipEntry(); ZipPackageFolder::copyZipEntry ( *pTempEntry, aEntry ); - pTempEntry->nNameLen = (sal_Int16)( ::rtl::OUStringToOString( rPath, RTL_TEXTENCODING_UTF8 ).getLength() ); + pTempEntry->nPathLen = (sal_Int16)( ::rtl::OUStringToOString( rPath, RTL_TEXTENCODING_UTF8 ).getLength() ); pTempEntry->nExtraLen = -1; - pTempEntry->sName = rPath; + pTempEntry->sPath = rPath; try { @@ -332,8 +386,8 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr // store the ZipEntry data in pTempEntry ZipPackageFolder::copyZipEntry ( *pTempEntry, pStream->aEntry ); - pTempEntry->sName = rPath + rShortName; - pTempEntry->nNameLen = (sal_Int16)( ::rtl::OUStringToOString( pTempEntry->sName, RTL_TEXTENCODING_UTF8 ).getLength() ); + pTempEntry->sPath = rPath + rShortName; + pTempEntry->nPathLen = (sal_Int16)( ::rtl::OUStringToOString( pTempEntry->sPath, RTL_TEXTENCODING_UTF8 ).getLength() ); sal_Bool bToBeEncrypted = pStream->IsToBeEncrypted() && (bHaveEncryptionKey || pStream->HasOwnKey()); sal_Bool bToBeCompressed = bToBeEncrypted ? sal_True : pStream->IsToBeCompressed(); @@ -343,7 +397,7 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr pValue[PKG_MNFST_VERSION].Name = sVersionProperty; pValue[PKG_MNFST_VERSION].Value <<= ::rtl::OUString(); // no version is stored for streams currently pValue[PKG_MNFST_FULLPATH].Name = sFullPathProperty; - pValue[PKG_MNFST_FULLPATH].Value <<= pTempEntry->sName; + pValue[PKG_MNFST_FULLPATH].Value <<= pTempEntry->sPath; OSL_ENSURE( pStream->GetStreamMode() != PACKAGE_STREAM_NOTSET, "Unacceptable ZipPackageStream mode!" ); @@ -633,7 +687,6 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr if ( pStream->IsEncrypted() ) pStream->setSize( nOwnStreamOrigSize ); - pStream->aEntry.sName = rShortName; pStream->aEntry.nOffset *= -1; } } @@ -726,9 +779,9 @@ void ZipPackageFolder::doInsertByName ( ZipPackageEntry *pEntry, sal_Bool bSetPa throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException) { if ( pEntry->IsFolder() ) - maContents[pEntry->aEntry.sName] = new ContentInfo ( static_cast < ZipPackageFolder *> ( pEntry ) ); + maContents[pEntry->getName()] = new ContentInfo ( static_cast < ZipPackageFolder *> ( pEntry ) ); else - maContents[pEntry->aEntry.sName] = new ContentInfo ( static_cast < ZipPackageStream *> ( pEntry ) ); + maContents[pEntry->getName()] = new ContentInfo ( static_cast < ZipPackageStream *> ( pEntry ) ); if ( bSetParent ) pEntry->setParent ( *this ); diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx index b42a0e8ecde6..242e37bfb764 100644 --- a/package/source/zippackage/ZipPackageStream.cxx +++ b/package/source/zippackage/ZipPackageStream.cxx @@ -76,6 +76,7 @@ ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage, , m_nMagicalHackSize( 0 ) , m_bHasSeekable( sal_False ) , m_bCompressedIsSetFromOutside( sal_False ) +, m_bFromManifest( sal_False ) { OSL_ENSURE( m_xFactory.is(), "No factory is provided to ZipPackageStream!\n" ); @@ -90,7 +91,7 @@ ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage, aEntry.nCompressedSize = -1; aEntry.nSize = -1; aEntry.nOffset = -1; - aEntry.nNameLen = -1; + aEntry.nPathLen = -1; aEntry.nExtraLen = -1; if ( !aImplementationId.getLength() ) @@ -113,8 +114,8 @@ void ZipPackageStream::setZipEntryOnLoading( const ZipEntry &rInEntry) aEntry.nCompressedSize = rInEntry.nCompressedSize; aEntry.nSize = rInEntry.nSize; aEntry.nOffset = rInEntry.nOffset; - aEntry.sName = rInEntry.sName; - aEntry.nNameLen = rInEntry.nNameLen; + aEntry.sPath = rInEntry.sPath; + aEntry.nPathLen = rInEntry.nPathLen; aEntry.nExtraLen = rInEntry.nExtraLen; if ( aEntry.nMethod == STORED ) @@ -676,11 +677,11 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, OUString sTempString; if ( ( aValue >>= sTempString ) ) { - sal_Int32 nNameLength = sTempString.getLength(); - Sequence < sal_Int8 > aSequence ( nNameLength ); + sal_Int32 nPathLength = sTempString.getLength(); + Sequence < sal_Int8 > aSequence ( nPathLength ); sal_Int8 *pArray = aSequence.getArray(); const sal_Unicode *pChar = sTempString.getStr(); - for ( sal_Int16 i = 0; i < nNameLength; i++) + for ( sal_Int16 i = 0; i < nPathLength; i++) pArray[i] = static_cast < const sal_Int8 > (pChar[i]); aNewKey = aSequence; } diff --git a/package/source/zippackage/ZipPackageStream.hxx b/package/source/zippackage/ZipPackageStream.hxx index dd4cc7edb81b..e5aa1d24fcca 100644 --- a/package/source/zippackage/ZipPackageStream.hxx +++ b/package/source/zippackage/ZipPackageStream.hxx @@ -74,6 +74,8 @@ protected: sal_Bool m_bCompressedIsSetFromOutside; + sal_Bool m_bFromManifest; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& GetOwnSeekStream(); public: @@ -82,6 +84,10 @@ public: sal_Bool IsToBeEncrypted () const { return bToBeEncrypted;} sal_Bool IsEncrypted () const { return bIsEncrypted;} sal_Bool IsPackageMember () const { return m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER;} + + sal_Bool IsFromManifest() const { return m_bFromManifest; } + void SetFromManifest( sal_Bool bValue ) { m_bFromManifest = bValue; } + vos::ORef < EncryptionData > & getEncryptionData () { return xEncryptionData;} const com::sun::star::uno::Sequence < sal_Int8 >& getKey () const diff --git a/package/source/zippackage/zipfileaccess.cxx b/package/source/zippackage/zipfileaccess.cxx index 0a70c8d32b88..42f95d3a268f 100644 --- a/package/source/zippackage/zipfileaccess.cxx +++ b/package/source/zippackage/zipfileaccess.cxx @@ -289,7 +289,7 @@ uno::Sequence< ::rtl::OUString > SAL_CALL OZipFileAccess::getElementNames() aNames.realloc( nLen ); } - aNames[nLen-1] = (*aIter).second.sName; + aNames[nLen-1] = (*aIter).second.sPath; } if ( aNames.getLength() != nLen ) @@ -368,7 +368,7 @@ uno::Reference< io::XInputStream > SAL_CALL OZipFileAccess::getStreamByPattern( for ( EntryHash::iterator aIter = m_pZipFile->GetEntryHash().begin(); aIter != m_pZipFile->GetEntryHash().end(); aIter++ ) { - if ( StringGoodForPattern_Impl( (*aIter).second.sName, aPattern ) ) + if ( StringGoodForPattern_Impl( (*aIter).second.sPath, aPattern ) ) { uno::Reference< io::XInputStream > xEntryStream( m_pZipFile->getDataStream( (*aIter).second, new EncryptionData(), |