diff options
Diffstat (limited to 'package/source/manifest')
-rw-r--r-- | package/source/manifest/Base64Codec.cxx | 207 | ||||
-rw-r--r-- | package/source/manifest/Base64Codec.hxx | 48 | ||||
-rw-r--r-- | package/source/manifest/ManifestDefines.hxx | 70 | ||||
-rw-r--r-- | package/source/manifest/ManifestExport.cxx | 318 | ||||
-rw-r--r-- | package/source/manifest/ManifestExport.hxx | 48 | ||||
-rw-r--r-- | package/source/manifest/ManifestImport.cxx | 332 | ||||
-rw-r--r-- | package/source/manifest/ManifestImport.hxx | 132 | ||||
-rw-r--r-- | package/source/manifest/ManifestReader.cxx | 143 | ||||
-rw-r--r-- | package/source/manifest/ManifestReader.hxx | 72 | ||||
-rw-r--r-- | package/source/manifest/ManifestWriter.cxx | 128 | ||||
-rw-r--r-- | package/source/manifest/ManifestWriter.hxx | 72 | ||||
-rw-r--r-- | package/source/manifest/UnoRegister.cxx | 155 | ||||
-rw-r--r-- | package/source/manifest/makefile.mk | 55 |
13 files changed, 1780 insertions, 0 deletions
diff --git a/package/source/manifest/Base64Codec.cxx b/package/source/manifest/Base64Codec.cxx new file mode 100644 index 000000000000..f3c8152a3fad --- /dev/null +++ b/package/source/manifest/Base64Codec.cxx @@ -0,0 +1,207 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_package.hxx" +#include "Base64Codec.hxx" +#include <rtl/ustrbuf.hxx> +#include <osl/diagnose.h> +using namespace rtl; +using namespace osl; +using namespace com::sun::star; + +const + sal_Char aBase64EncodeTable[] = + { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; + +const + sal_uInt8 aBase64DecodeTable[] = + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0-15 + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16-31 + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, // 32-47 +// + / + + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, // 48-63 +// 0 1 2 3 4 5 6 7 8 9 = + + 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 64-79 +// A B C D E F G H I J K L M N O + + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, // 80-95 +// P Q R S T U V W X Y Z + + 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 96-111 +// a b c d e f g h i j k l m n o + + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0, // 112-127 +// p q r s t u v w x y z + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + + +void ThreeByteToFourByte (const sal_uInt8* pBuffer, const sal_Int32 nStart, const sal_Int32 nFullLen, rtl::OUStringBuffer& sBuffer) +{ + sal_Int32 nLen(nFullLen - nStart); + if (nLen > 3) + nLen = 3; + if (nLen == 0) + { + sBuffer.setLength(0); + return; + } + + sal_Int32 nBinaer; + switch (nLen) + { + case 1: + { + nBinaer = ((sal_uInt8)pBuffer[nStart + 0]) << 16; + } + break; + case 2: + { + nBinaer = (((sal_uInt8)pBuffer[nStart + 0]) << 16) + + (((sal_uInt8)pBuffer[nStart + 1]) << 8); + } + break; + default: + { + nBinaer = (((sal_uInt8)pBuffer[nStart + 0]) << 16) + + (((sal_uInt8)pBuffer[nStart + 1]) << 8) + + ((sal_uInt8)pBuffer[nStart + 2]); + } + break; + } + + sBuffer.appendAscii("===="); + + sal_uInt8 nIndex = static_cast< sal_uInt8 >((nBinaer & 0xFC0000) >> 18); + sBuffer.setCharAt(0, aBase64EncodeTable [nIndex]); + + nIndex = static_cast< sal_uInt8 >((nBinaer & 0x3F000) >> 12); + sBuffer.setCharAt(1, aBase64EncodeTable [nIndex]); + if (nLen == 1) + return; + + nIndex = static_cast< sal_uInt8 >((nBinaer & 0xFC0) >> 6); + sBuffer.setCharAt(2, aBase64EncodeTable [nIndex]); + if (nLen == 2) + return; + + nIndex = static_cast< sal_uInt8 >(nBinaer & 0x3F); + sBuffer.setCharAt(3, aBase64EncodeTable [nIndex]); +} + +void Base64Codec::encodeBase64(rtl::OUStringBuffer& aStrBuffer, const uno::Sequence < sal_uInt8 >& aPass) +{ + sal_Int32 i(0); + sal_Int32 nBufferLength(aPass.getLength()); + const sal_uInt8* pBuffer = aPass.getConstArray(); + while (i < nBufferLength) + { + rtl::OUStringBuffer sBuffer; + ThreeByteToFourByte (pBuffer, i, nBufferLength, sBuffer); + aStrBuffer.append(sBuffer); + i += 3; + } +} + +const rtl::OUString s2equal(RTL_CONSTASCII_USTRINGPARAM("==")); +const rtl::OUString s1equal(RTL_CONSTASCII_USTRINGPARAM("=")); + +void FourByteToThreeByte (sal_uInt8* pBuffer, sal_Int32& nLength, const sal_Int32 nStart, const rtl::OUString& sString) +{ + nLength = 0; + sal_Int32 nLen (sString.getLength()); + + OSL_ASSERT( nLen == 4 ); + if (nLen != 4) + return; + + if (sString.indexOf(s2equal) == 2) + nLength = 1; + else if (sString.indexOf(s1equal) == 3) + nLength = 2; + else + nLength = 3; + + sal_Int32 nBinaer ((aBase64DecodeTable [sString [0]] << 18) + + (aBase64DecodeTable [sString [1]] << 12) + + (aBase64DecodeTable [sString [2]] << 6) + + (aBase64DecodeTable [sString [3]])); + + sal_uInt8 OneByte = static_cast< sal_uInt8 >((nBinaer & 0xFF0000) >> 16); + pBuffer[nStart + 0] = (sal_uInt8)OneByte; + + if (nLength == 1) + return; + + OneByte = static_cast< sal_uInt8 >((nBinaer & 0xFF00) >> 8); + pBuffer[nStart + 1] = OneByte; + + if (nLength == 2) + return; + + OneByte = static_cast< sal_uInt8 >(nBinaer & 0xFF); + pBuffer[nStart + 2] = OneByte; +} + +void Base64Codec::decodeBase64(uno::Sequence< sal_uInt8 >& aBuffer, const rtl::OUString& sBuffer) +{ + sal_Int32 nFirstLength((sBuffer.getLength() / 4) * 3); + sal_uInt8* pBuffer = new sal_uInt8[nFirstLength]; + sal_Int32 nSecondLength(0); + sal_Int32 nLength(0); + sal_Int32 i = 0; + sal_Int32 k = 0; + while (i < sBuffer.getLength()) + { + FourByteToThreeByte (pBuffer, nLength, k, sBuffer.copy(i, 4)); + nSecondLength += nLength; + nLength = 0; + i += 4; + k += 3; + } + aBuffer = uno::Sequence<sal_uInt8>(pBuffer, nSecondLength); + delete[] pBuffer; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/Base64Codec.hxx b/package/source/manifest/Base64Codec.hxx new file mode 100644 index 000000000000..8cae2a7037fd --- /dev/null +++ b/package/source/manifest/Base64Codec.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _BASE64_CODEC_HXX +#define _BASE64_CODEC_HXX + +#include <com/sun/star/uno/Sequence.hxx> + +namespace rtl +{ +class OUString; +class OUStringBuffer; +} + +class Base64Codec +{ +public: + static void encodeBase64(rtl::OUStringBuffer& aStrBuffer, const com::sun::star::uno::Sequence<sal_uInt8>& aPass); + static void decodeBase64(com::sun::star::uno::Sequence<sal_uInt8>& aPass, const rtl::OUString& sBuffer); +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestDefines.hxx b/package/source/manifest/ManifestDefines.hxx new file mode 100644 index 000000000000..65b9c6181727 --- /dev/null +++ b/package/source/manifest/ManifestDefines.hxx @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _MANIFEST_DEFINES_HXX +#define _MANIFEST_DEFINES_HXX + +#include <PackageConstants.hxx> + +#define MANIFEST_NSPREFIX "manifest:" +#define ELEMENT_MANIFEST "manifest:manifest" +#define ATTRIBUTE_XMLNS "xmlns:manifest" +#define MANIFEST_NAMESPACE "http://openoffice.org/2001/manifest" +#define MANIFEST_OASIS_NAMESPACE "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" +#define MANIFEST_DOCTYPE "<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">" +#define ATTRIBUTE_CDATA "CDATA" + +#define ELEMENT_FILE_ENTRY "manifest:file-entry" +#define ATTRIBUTE_FULL_PATH "manifest:full-path" +#define ATTRIBUTE_VERSION "manifest:version" +#define ATTRIBUTE_MEDIA_TYPE "manifest:media-type" +#define ATTRIBUTE_SIZE "manifest:size" + +#define ELEMENT_ENCRYPTION_DATA "manifest:encryption-data" +#define ATTRIBUTE_CHECKSUM_TYPE "manifest:checksum-type" +#define ATTRIBUTE_CHECKSUM "manifest:checksum" + +#define ELEMENT_ALGORITHM "manifest:algorithm" +#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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestExport.cxx b/package/source/manifest/ManifestExport.cxx new file mode 100644 index 000000000000..04316e784c77 --- /dev/null +++ b/package/source/manifest/ManifestExport.cxx @@ -0,0 +1,318 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_package.hxx" +#include <ManifestExport.hxx> +#include <ManifestDefines.hxx> +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <rtl/ustrbuf.hxx> +#include <Base64Codec.hxx> +#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> + +#include <comphelper/documentconstants.hxx> +#include <comphelper/attributelist.hxx> + +using namespace rtl; +using namespace com::sun::star::beans; +using namespace com::sun::star::uno; +using namespace com::sun::star::xml::sax; + +ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const Sequence < Sequence < PropertyValue > > &rManList ) +{ + const OUString sFileEntryElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) ); + 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 ) ); + const OUString sMediaTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_MEDIA_TYPE ) ); + 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) ); + + const OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); + const OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); + const OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); + const OUString sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); + const OUString sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ); + const OUString sInitialisationVectorProperty( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ); + const OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); + const OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); + + const OUString sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) ); + 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(); + const sal_uInt32 nManLength = rManList.getLength(); + + // 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; + } + else if (pValue->Name.equals (sFullPathProperty) ) + { + pValue->Value >>= aPath; + } + else if (pValue->Name.equals (sVersionProperty) ) + { + pValue->Value >>= aVersion; + } + + 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 ) ) ) + || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII ) ) ) + || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII ) ) ) + || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII ) ) ) + || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII ) ) ) + || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII ) ) ) + || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII ) ) ) + || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII ) ) ) + || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII ) ) ) + + || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII ) ) ) + || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII ) ) ) + || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII ) ) ) + || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII ) ) ) + || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_TEMPLATE_ASCII ) ) ) + || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE_ASCII ) ) ) ) + + { + // oasis format + pRootAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_XMLNS ) ), + 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 + { + // even if it is no SO6 format the namespace must be specified + // thus SO6 format is used as default one + pRootAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_XMLNS ) ), + sCdataAttribute, + OUString( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_NAMESPACE ) ) ); + + bProvideDTD = sal_True; + } + } + + Reference < XAttributeList > xRootAttrList (pRootAttrList); + + xHandler->startDocument(); + Reference < XExtendedDocumentHandler > xExtHandler ( xHandler, UNO_QUERY ); + if ( xExtHandler.is() && bProvideDTD ) + { + OUString aDocType ( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_DOCTYPE ) ); + xExtHandler->unknown ( aDocType ); + xHandler->ignorableWhitespace ( sWhiteSpace ); + } + xHandler->startElement( sManifestElement, xRootAttrList ); + + for (sal_uInt32 i = 0 ; i < nManLength ; i++) + { + ::comphelper::AttributeList *pAttrList = new ::comphelper::AttributeList; + const PropertyValue *pValue = pSequence[i].getConstArray(); + OUString aString; + const PropertyValue *pVector = NULL, *pSalt = NULL, *pIterationCount = NULL, *pDigest = NULL; + for (sal_uInt32 j = 0, nNum = pSequence[i].getLength(); j < nNum; j++, pValue++) + { + if (pValue->Name.equals (sMediaTypeProperty) ) + { + pValue->Value >>= aString; + pAttrList->AddAttribute ( sMediaTypeAttribute, sCdataAttribute, aString ); + } + else if (pValue->Name.equals (sVersionProperty) ) + { + pValue->Value >>= aString; + // the version is stored only if it is not empty + if ( bAcceptNonemptyVersion && aString.getLength() ) + pAttrList->AddAttribute ( sVersionAttribute, sCdataAttribute, aString ); + } + else if (pValue->Name.equals (sFullPathProperty) ) + { + pValue->Value >>= aString; + pAttrList->AddAttribute ( sFullPathAttribute, sCdataAttribute, aString ); + } + else if (pValue->Name.equals (sSizeProperty) ) + { + sal_Int32 nSize = 0; + pValue->Value >>= nSize; + OUStringBuffer aBuffer; + aBuffer.append ( nSize ); + pAttrList->AddAttribute ( sSizeAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); + } + else if (pValue->Name.equals (sInitialisationVectorProperty) ) + pVector = pValue; + else if (pValue->Name.equals (sSaltProperty) ) + pSalt = pValue; + else if (pValue->Name.equals (sIterationCountProperty) ) + pIterationCount = pValue; + else if (pValue->Name.equals ( sDigestProperty ) ) + pDigest = pValue; + } + xHandler->ignorableWhitespace ( sWhiteSpace ); + Reference < XAttributeList > xAttrList ( pAttrList ); + xHandler->startElement( sFileEntryElement , xAttrList); + if ( pVector && pSalt && pIterationCount ) + { + // ==== Encryption Data + ::comphelper::AttributeList * pNewAttrList = new ::comphelper::AttributeList; + Reference < XAttributeList > xNewAttrList (pNewAttrList); + OUStringBuffer aBuffer; + Sequence < sal_uInt8 > aSequence; + + xHandler->ignorableWhitespace ( sWhiteSpace ); + if ( pDigest ) + { + pNewAttrList->AddAttribute ( sChecksumTypeAttribute, sCdataAttribute, sChecksumType ); + pDigest->Value >>= aSequence; + Base64Codec::encodeBase64 ( aBuffer, aSequence ); + pNewAttrList->AddAttribute ( sChecksumAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); + } + xHandler->startElement( sEncryptionDataElement , xNewAttrList); + + // ==== Algorithm + pNewAttrList = new ::comphelper::AttributeList; + xNewAttrList = pNewAttrList; + + pNewAttrList->AddAttribute ( sAlgorithmNameAttribute, sCdataAttribute, sBlowfish ); + + pVector->Value >>= aSequence; + Base64Codec::encodeBase64 ( aBuffer, aSequence ); + pNewAttrList->AddAttribute ( sInitialisationVectorAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); + + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->startElement( sAlgorithmElement , xNewAttrList); + 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); + pNewAttrList->AddAttribute ( sIterationCountAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); + + pSalt->Value >>= aSequence; + Base64Codec::encodeBase64 ( aBuffer, aSequence ); + pNewAttrList->AddAttribute ( sSaltAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); + + xHandler->ignorableWhitespace ( sWhiteSpace ); + 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 ); + } + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->endElement( sFileEntryElement ); + } + xHandler->ignorableWhitespace ( sWhiteSpace ); + xHandler->endElement( sManifestElement ); + xHandler->endDocument(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestExport.hxx b/package/source/manifest/ManifestExport.hxx new file mode 100644 index 000000000000..73b8cce89725 --- /dev/null +++ b/package/source/manifest/ManifestExport.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _MANIFEST_EXPORT_HXX +#define _MANIFEST_EXPORT_HXX + +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/uno/Reference.h> +#include <rtl/ustring.hxx> + +namespace com { namespace sun { namespace star { + namespace beans { struct PropertyValue;} + namespace xml { namespace sax { class XDocumentHandler; } } +} } } +class ManifestExport +{ +public: + ManifestExport(com::sun::star::uno::Reference < com::sun::star::xml::sax::XDocumentHandler > xHandler, const com::sun::star::uno::Sequence < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList ); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestImport.cxx b/package/source/manifest/ManifestImport.cxx new file mode 100644 index 000000000000..543a290b5857 --- /dev/null +++ b/package/source/manifest/ManifestImport.cxx @@ -0,0 +1,332 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER( update_precomp.py ): autogen include statement, do not remove +#include "precompiled_package.hxx" +#include <ManifestImport.hxx> +#include <ManifestDefines.hxx> +#include <Base64Codec.hxx> +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> + +using namespace com::sun::star::uno; +using namespace com::sun::star::beans; +using namespace com::sun::star; +using namespace rtl; +using namespace std; + +// --------------------------------------------------- +ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManVector ) +: nNumProperty ( 0 ) +, bIgnoreEncryptData ( sal_False ) +, rManVector ( rNewManVector ) + +, sFileEntryElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) ) +, sManifestElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) ) +, sEncryptionDataElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) ) +, sAlgorithmElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ALGORITHM ) ) +, sKeyDerivationElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_KEY_DERIVATION ) ) + +, sCdataAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) ) +, sMediaTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_MEDIA_TYPE ) ) +, sVersionAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) ) +, sFullPathAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_FULL_PATH ) ) +, sSizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SIZE ) ) +, sSaltAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) ) +, sInitialisationVectorAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_INITIALISATION_VECTOR ) ) +, sIterationCountAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) ) +, sAlgorithmNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ALGORITHM_NAME ) ) +, sKeyDerivationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_DERIVATION_NAME ) ) +, sChecksumAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM ) ) +, sChecksumTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM_TYPE ) ) + +, sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ) +, sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ) +, sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ) +, sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ) +, sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ) +, sInitialisationVectorProperty ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ) +, sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ) +, sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ) + +, sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) ) +, sBlowfish ( RTL_CONSTASCII_USTRINGPARAM ( "Blowfish CFB" ) ) +, sPBKDF2 ( RTL_CONSTASCII_USTRINGPARAM ( "PBKDF2" ) ) +, sChecksumType ( RTL_CONSTASCII_USTRINGPARAM ( CHECKSUM_TYPE ) ) +{ + aStack.reserve( 10 ); +} + +// --------------------------------------------------- +ManifestImport::~ManifestImport ( void ) +{ +} + +// --------------------------------------------------- +void SAL_CALL ManifestImport::startDocument( ) + throw( xml::sax::SAXException, uno::RuntimeException ) +{ +} + +// --------------------------------------------------- +void SAL_CALL ManifestImport::endDocument( ) + throw( xml::sax::SAXException, uno::RuntimeException ) +{ +} + +// --------------------------------------------------- +void SAL_CALL ManifestImport::startElement( const OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs ) + throw( xml::sax::SAXException, uno::RuntimeException ) +{ + StringHashMap aConvertedAttribs; + ::rtl::OUString aConvertedName = PushNameAndNamespaces( aName, xAttribs, aConvertedAttribs ); + + if ( aConvertedName == sFileEntryElement ) + { + aSequence.realloc ( PKG_SIZE_ENCR_MNFST ); + + // Put full-path property first for MBA + aSequence[nNumProperty].Name = sFullPathProperty; + aSequence[nNumProperty++].Value <<= aConvertedAttribs[sFullPathAttribute]; + aSequence[nNumProperty].Name = sMediaTypeProperty; + aSequence[nNumProperty++].Value <<= aConvertedAttribs[sMediaTypeAttribute]; + + OUString sVersion = aConvertedAttribs[sVersionAttribute]; + if ( sVersion.getLength() ) + { + aSequence[nNumProperty].Name = sVersionProperty; + aSequence[nNumProperty++].Value <<= sVersion; + } + + OUString sSize = aConvertedAttribs[sSizeAttribute]; + if ( sSize.getLength() ) + { + sal_Int32 nSize; + nSize = sSize.toInt32(); + aSequence[nNumProperty].Name = sSizeProperty; + aSequence[nNumProperty++].Value <<= nSize; + } + } + else if ( aStack.size() > 1 ) + { + ManifestStack::reverse_iterator aIter = aStack.rbegin(); + ++aIter; + + if ( aIter->m_aConvertedName.equals( sFileEntryElement ) ) + { + if ( aConvertedName.equals( sEncryptionDataElement ) ) + { + // If this element exists, then this stream is encrypted and we need + // to store the initialisation vector, salt and iteration count used + OUString aString = aConvertedAttribs[sChecksumTypeAttribute]; + if ( aString == sChecksumType && !bIgnoreEncryptData ) + { + aString = aConvertedAttribs[sChecksumAttribute]; + Sequence < sal_uInt8 > aDecodeBuffer; + Base64Codec::decodeBase64 ( aDecodeBuffer, aString ); + aSequence[nNumProperty].Name = sDigestProperty; + aSequence[nNumProperty++].Value <<= aDecodeBuffer; + } + } + } + else if ( aIter->m_aConvertedName.equals( sEncryptionDataElement ) ) + { + if ( aConvertedName == sAlgorithmElement ) + { + OUString aString = aConvertedAttribs[sAlgorithmNameAttribute]; + if ( aString == sBlowfish && !bIgnoreEncryptData ) + { + aString = aConvertedAttribs[sInitialisationVectorAttribute]; + Sequence < sal_uInt8 > aDecodeBuffer; + Base64Codec::decodeBase64 ( aDecodeBuffer, aString ); + aSequence[nNumProperty].Name = sInitialisationVectorProperty; + aSequence[nNumProperty++].Value <<= aDecodeBuffer; + } + else + // If we don't recognise the algorithm, then the key derivation info + // is useless to us + bIgnoreEncryptData = sal_True; + } + else if ( aConvertedName == sKeyDerivationElement ) + { + OUString aString = aConvertedAttribs[sKeyDerivationNameAttribute]; + if ( aString == sPBKDF2 && !bIgnoreEncryptData ) + { + aString = aConvertedAttribs[sSaltAttribute]; + Sequence < sal_uInt8 > aDecodeBuffer; + Base64Codec::decodeBase64 ( aDecodeBuffer, aString ); + aSequence[nNumProperty].Name = sSaltProperty; + aSequence[nNumProperty++].Value <<= aDecodeBuffer; + + aString = aConvertedAttribs[sIterationCountAttribute]; + aSequence[nNumProperty].Name = sIterationCountProperty; + aSequence[nNumProperty++].Value <<= aString.toInt32(); + } + else + // If we don't recognise the key derivation technique, then the + // algorithm info is useless to us + bIgnoreEncryptData = sal_True; + } + } + } +} + +// --------------------------------------------------- +void SAL_CALL ManifestImport::endElement( const OUString& aName ) + throw( xml::sax::SAXException, uno::RuntimeException ) +{ + ::rtl::OUString aConvertedName = ConvertName( aName ); + if ( !aStack.empty() && aStack.rbegin()->m_aConvertedName.equals( aConvertedName ) ) + { + if ( aConvertedName.equals( sFileEntryElement ) ) + { + aSequence.realloc ( nNumProperty ); + bIgnoreEncryptData = sal_False; + rManVector.push_back ( aSequence ); + nNumProperty = 0; + } + + aStack.pop_back(); + } +} + +// --------------------------------------------------- +void SAL_CALL ManifestImport::characters( const OUString& /*aChars*/ ) + throw( xml::sax::SAXException, uno::RuntimeException ) +{ +} + +// --------------------------------------------------- +void SAL_CALL ManifestImport::ignorableWhitespace( const OUString& /*aWhitespaces*/ ) + throw( xml::sax::SAXException, uno::RuntimeException ) +{ +} + +// --------------------------------------------------- +void SAL_CALL ManifestImport::processingInstruction( const OUString& /*aTarget*/, const OUString& /*aData*/ ) + throw( xml::sax::SAXException, uno::RuntimeException ) +{ +} + +// --------------------------------------------------- +void SAL_CALL ManifestImport::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& /*xLocator*/ ) + throw( xml::sax::SAXException, uno::RuntimeException ) +{ +} + +// --------------------------------------------------- +::rtl::OUString ManifestImport::PushNameAndNamespaces( const ::rtl::OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs, StringHashMap& o_aConvertedAttribs ) +{ + StringHashMap aNamespaces; + ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > > aAttribsStrs; + + if ( xAttribs.is() ) + { + sal_Int16 nAttrCount = xAttribs.is() ? xAttribs->getLength() : 0; + aAttribsStrs.reserve( nAttrCount ); + + for( sal_Int16 nInd = 0; nInd < nAttrCount; nInd++ ) + { + ::rtl::OUString aAttrName = xAttribs->getNameByIndex( nInd ); + ::rtl::OUString aAttrValue = xAttribs->getValueByIndex( nInd ); + if ( aAttrName.getLength() >= 5 + && aAttrName.compareToAscii( "xmlns", 5 ) == 0 + && ( aAttrName.getLength() == 5 || aAttrName.getStr()[5] == ( sal_Unicode )':' ) ) + { + // this is a namespace declaration + ::rtl::OUString aNsName( ( aAttrName.getLength() == 5 ) ? ::rtl::OUString() : aAttrName.copy( 6 ) ); + aNamespaces[aNsName] = aAttrValue; + } + else + { + // this is no namespace declaration + aAttribsStrs.push_back( pair< ::rtl::OUString, ::rtl::OUString >( aAttrName, aAttrValue ) ); + } + } + } + + ::rtl::OUString aConvertedName = ConvertNameWithNamespace( aName, aNamespaces ); + if ( !aConvertedName.getLength() ) + aConvertedName = ConvertName( aName ); + + aStack.push_back( ManifestScopeEntry( aConvertedName, aNamespaces ) ); + + for ( sal_uInt16 nInd = 0; nInd < aAttribsStrs.size(); nInd++ ) + { + // convert the attribute names on filling + o_aConvertedAttribs[ConvertName( aAttribsStrs[nInd].first )] = aAttribsStrs[nInd].second; + } + + return aConvertedName; +} + +// --------------------------------------------------- +::rtl::OUString ManifestImport::ConvertNameWithNamespace( const ::rtl::OUString& aName, const StringHashMap& aNamespaces ) +{ + ::rtl::OUString aNsAlias; + ::rtl::OUString aPureName = aName; + + sal_Int32 nInd = aName.indexOf( ( sal_Unicode )':' ); + if ( nInd != -1 && nInd < aName.getLength() ) + { + aNsAlias = aName.copy( 0, nInd ); + aPureName = aName.copy( nInd + 1 ); + } + + ::rtl::OUString aResult; + + StringHashMap::const_iterator aIter = aNamespaces.find( aNsAlias ); + if ( aIter != aNamespaces.end() + && ( aIter->second.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MANIFEST_NAMESPACE ) ) ) + || aIter->second.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MANIFEST_OASIS_NAMESPACE ) ) ) ) ) + { + // no check for manifest.xml consistency currently since the old versions have supported inconsistent documents as well + aResult = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MANIFEST_NSPREFIX ) ); + aResult += aPureName; + } + + return aResult; +} + +// --------------------------------------------------- +::rtl::OUString ManifestImport::ConvertName( const ::rtl::OUString& aName ) +{ + ::rtl::OUString aConvertedName; + for ( ManifestStack::reverse_iterator aIter = aStack.rbegin(); !aConvertedName.getLength() && aIter != aStack.rend(); ++aIter ) + { + if ( !aIter->m_aNamespaces.empty() ) + aConvertedName = ConvertNameWithNamespace( aName, aIter->m_aNamespaces ); + } + + if ( !aConvertedName.getLength() ) + aConvertedName = aName; + + return aConvertedName; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestImport.hxx b/package/source/manifest/ManifestImport.hxx new file mode 100644 index 000000000000..e875c46b8b9c --- /dev/null +++ b/package/source/manifest/ManifestImport.hxx @@ -0,0 +1,132 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _MANIFEST_IMPORT_HXX +#define _MANIFEST_IMPORT_HXX + +#include <cppuhelper/implbase1.hxx> // helper for implementations +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <vector> + +#include <HashMaps.hxx> + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } + namespace beans { struct PropertyValue; } +} } } + +typedef ::std::hash_map< ::rtl::OUString, ::rtl::OUString, ::rtl::OUStringHash, eqFunc > StringHashMap; + +struct ManifestScopeEntry +{ + ::rtl::OUString m_aConvertedName; + StringHashMap m_aNamespaces; + + ManifestScopeEntry( const ::rtl::OUString& aConvertedName, const StringHashMap& aNamespaces ) + : m_aConvertedName( aConvertedName ) + , m_aNamespaces( aNamespaces ) + {} + + ~ManifestScopeEntry() + {} +}; + +typedef ::std::vector< ManifestScopeEntry > ManifestStack; + +class ManifestImport : public cppu::WeakImplHelper1 < com::sun::star::xml::sax::XDocumentHandler > +{ +protected: + com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aSequence; + sal_Int16 nNumProperty; + ManifestStack aStack; + sal_Bool bIgnoreEncryptData; + ::std::vector < ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > > & rManVector; + + const ::rtl::OUString sFileEntryElement; + const ::rtl::OUString sManifestElement; + const ::rtl::OUString sEncryptionDataElement; + const ::rtl::OUString sAlgorithmElement; + const ::rtl::OUString sKeyDerivationElement; + + const ::rtl::OUString sCdataAttribute; + const ::rtl::OUString sMediaTypeAttribute; + const ::rtl::OUString sVersionAttribute; + const ::rtl::OUString sFullPathAttribute; + const ::rtl::OUString sSizeAttribute; + const ::rtl::OUString sSaltAttribute; + const ::rtl::OUString sInitialisationVectorAttribute; + const ::rtl::OUString sIterationCountAttribute; + const ::rtl::OUString sAlgorithmNameAttribute; + const ::rtl::OUString sKeyDerivationNameAttribute; + const ::rtl::OUString sChecksumAttribute; + const ::rtl::OUString sChecksumTypeAttribute; + + const ::rtl::OUString sFullPathProperty; + const ::rtl::OUString sMediaTypeProperty; + const ::rtl::OUString sVersionProperty; + const ::rtl::OUString sIterationCountProperty; + const ::rtl::OUString sSaltProperty; + const ::rtl::OUString sInitialisationVectorProperty; + const ::rtl::OUString sSizeProperty; + const ::rtl::OUString sDigestProperty; + + const ::rtl::OUString sWhiteSpace; + const ::rtl::OUString sBlowfish; + const ::rtl::OUString sPBKDF2; + const ::rtl::OUString sChecksumType; + + + ::rtl::OUString PushNameAndNamespaces( const ::rtl::OUString& aName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs, + StringHashMap& o_aConvertedAttribs ); + ::rtl::OUString ConvertNameWithNamespace( const ::rtl::OUString& aName, const StringHashMap& aNamespaces ); + ::rtl::OUString ConvertName( const ::rtl::OUString& aName ); + +public: + ManifestImport( std::vector < ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > > & rNewVector ); + ~ManifestImport( void ); + virtual void SAL_CALL startDocument( ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL endDocument( ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL endElement( const ::rtl::OUString& aName ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator ) + throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestReader.cxx b/package/source/manifest/ManifestReader.cxx new file mode 100644 index 000000000000..9e973a65d31e --- /dev/null +++ b/package/source/manifest/ManifestReader.cxx @@ -0,0 +1,143 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_package.hxx" +#include <ManifestReader.hxx> +#include <ManifestImport.hxx> +#include <cppuhelper/factory.hxx> +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <com/sun/star/xml/sax/SAXParseException.hpp> +#include <com/sun/star/xml/sax/XParser.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <vector> + +using namespace ::std; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::registry; +using namespace ::com::sun::star::packages; +using namespace ::com::sun::star::xml::sax; +using namespace ::com::sun::star::packages::manifest; +using ::rtl::OUString; + +ManifestReader::ManifestReader( const Reference < XMultiServiceFactory > & xNewFactory ) +: xFactory ( xNewFactory ) +{ +} +ManifestReader::~ManifestReader() +{ +} +Sequence< Sequence< PropertyValue > > SAL_CALL ManifestReader::readManifestSequence( const Reference< XInputStream >& rStream ) + throw (::com::sun::star::uno::RuntimeException) +{ + Sequence < Sequence < PropertyValue > > aManifestSequence; + Reference < XParser > xParser (xFactory->createInstance ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.xml.sax.Parser" ) ) ), UNO_QUERY ); + if (xParser.is()) + { + try + { + vector < Sequence < PropertyValue > > aManVector; + Reference < XDocumentHandler > xFilter = new ManifestImport( aManVector ); + InputSource aParserInput; + aParserInput.aInputStream = rStream; + aParserInput.sSystemId = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml" ) ); + xParser->setDocumentHandler ( xFilter ); + xParser->parseStream( aParserInput ); + aManifestSequence.realloc ( aManVector.size() ); + Sequence < PropertyValue > * pSequence = aManifestSequence.getArray(); + ::std::vector < Sequence < PropertyValue > >::const_iterator aIter = aManVector.begin(); + ::std::vector < Sequence < PropertyValue > >::const_iterator aEnd = aManVector.end(); + while( aIter != aEnd ) + *pSequence++ = (*aIter++); + } + catch (SAXParseException& ) + { + } + catch (SAXException& ) + { + } + catch (IOException& ) + { + } + } + xParser->setDocumentHandler ( Reference < XDocumentHandler > () ); + return aManifestSequence; +} +// Component functions + +Reference < XInterface > SAL_CALL ManifestReader_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory ) +{ + return *new ManifestReader( rServiceFactory ); +} +OUString ManifestReader::static_getImplementationName() +{ + return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.comp.ManifestReader" ) ); +} + +sal_Bool SAL_CALL ManifestReader::static_supportsService(OUString const & rServiceName) +{ + return rServiceName == getSupportedServiceNames()[0]; +} + +Sequence < OUString > ManifestReader::static_getSupportedServiceNames() +{ + Sequence < OUString > aNames(1); + aNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestReader" ) ); + return aNames; +} + +OUString ManifestReader::getImplementationName() + throw (RuntimeException) +{ + return static_getImplementationName(); +} + +sal_Bool SAL_CALL ManifestReader::supportsService(OUString const & rServiceName) + throw (RuntimeException) +{ + return static_supportsService ( rServiceName ); +} + +Sequence < OUString > ManifestReader::getSupportedServiceNames() + throw (RuntimeException) +{ + return static_getSupportedServiceNames(); +} +Reference < XSingleServiceFactory > ManifestReader::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory ) +{ + return cppu::createSingleFactory (rServiceFactory, + static_getImplementationName(), + ManifestReader_createInstance, + static_getSupportedServiceNames()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestReader.hxx b/package/source/manifest/ManifestReader.hxx new file mode 100644 index 000000000000..7454e26b0e98 --- /dev/null +++ b/package/source/manifest/ManifestReader.hxx @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _MANIFEST_READER_HXX +#define _MANIFEST_READER_HXX + +#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/packages/manifest/XManifestReader.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> + +namespace com { namespace sun { namespace star { + namespace lang { class XMultiServiceFactory; class XSingleServiceFactory; } +} } } + +class ManifestReader: public ::cppu::WeakImplHelper2 +< + ::com::sun::star::packages::manifest::XManifestReader, + ::com::sun::star::lang::XServiceInfo +> +{ +protected: + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory; +public: + ManifestReader( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xNewFactory ); + virtual ~ManifestReader(); + + // XManifestReader + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > SAL_CALL readManifestSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rStream ) + throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) + throw (::com::sun::star::uno::RuntimeException); + + // Component constructor + static ::rtl::OUString static_getImplementationName(); + static ::com::sun::star::uno::Sequence < ::rtl::OUString > static_getSupportedServiceNames(); + sal_Bool SAL_CALL static_supportsService(rtl::OUString const & rServiceName); + static ::com::sun::star::uno::Reference < com::sun::star::lang::XSingleServiceFactory > createServiceFactory( com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > const & rServiceFactory ); +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestWriter.cxx b/package/source/manifest/ManifestWriter.cxx new file mode 100644 index 000000000000..ef829ff5ac03 --- /dev/null +++ b/package/source/manifest/ManifestWriter.cxx @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_package.hxx" +#include <ManifestWriter.hxx> +#include <ManifestExport.hxx> +#include <cppuhelper/factory.hxx> +#include <com/sun/star/io/XActiveDataSource.hpp> +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/xml/sax/SAXException.hpp> + +#include <osl/diagnose.hxx> + +using namespace ::rtl; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::registry; +using namespace ::com::sun::star::packages; +using namespace ::com::sun::star::xml::sax; +using namespace ::com::sun::star::packages::manifest; + +ManifestWriter::ManifestWriter( const Reference < XMultiServiceFactory > & xNewFactory ) +: xFactory ( xNewFactory ) +{ +} +ManifestWriter::~ManifestWriter() +{ +} + +// XManifestWriter methods +void SAL_CALL ManifestWriter::writeManifestSequence( const Reference< XOutputStream >& rStream, const Sequence< Sequence< PropertyValue > >& rSequence ) + throw (RuntimeException) +{ + OUString sSaxWriter ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.xml.sax.Writer" ) ); + Reference < XActiveDataSource > xSource ( xFactory->createInstance ( sSaxWriter ), UNO_QUERY ); + if (xSource.is()) + { + xSource->setOutputStream ( rStream ); + Reference < XDocumentHandler > xHandler ( xSource, UNO_QUERY ); + if (xHandler.is()) + try { + ManifestExport aExporter ( xHandler, rSequence); + } + catch( SAXException& ) + { + throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + } + } +} + +// Component methods +Reference < XInterface > SAL_CALL ManifestWriter_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory ) +{ + return *new ManifestWriter( rServiceFactory ); +} + +OUString ManifestWriter::static_getImplementationName() +{ + return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.comp.ManifestWriter" ) ); +} + +sal_Bool SAL_CALL ManifestWriter::static_supportsService(OUString const & rServiceName) +{ + return rServiceName == getSupportedServiceNames()[0]; +} +Sequence < OUString > ManifestWriter::static_getSupportedServiceNames() +{ + Sequence < OUString > aNames(1); + aNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestWriter" ) ); + return aNames; +} + +OUString ManifestWriter::getImplementationName() + throw (RuntimeException) +{ + return static_getImplementationName(); +} + +sal_Bool SAL_CALL ManifestWriter::supportsService(OUString const & rServiceName) + throw (RuntimeException) +{ + return static_supportsService ( rServiceName ); +} +Sequence < OUString > ManifestWriter::getSupportedServiceNames() + throw (RuntimeException) +{ + return static_getSupportedServiceNames(); +} +Reference < XSingleServiceFactory > ManifestWriter::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory ) +{ + return cppu::createSingleFactory (rServiceFactory, + static_getImplementationName(), + ManifestWriter_createInstance, + static_getSupportedServiceNames()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestWriter.hxx b/package/source/manifest/ManifestWriter.hxx new file mode 100644 index 000000000000..eac775b08ad2 --- /dev/null +++ b/package/source/manifest/ManifestWriter.hxx @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _MANIFEST_WRITER_HXX +#define _MANIFEST_WRITER_HXX + +#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/packages/manifest/XManifestWriter.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> + +namespace com { namespace sun { namespace star { + namespace lang { class XMultiServiceFactory; class XSingleServiceFactory; } +} } } + +class ManifestWriter: public ::cppu::WeakImplHelper2 +< + ::com::sun::star::packages::manifest::XManifestWriter, + ::com::sun::star::lang::XServiceInfo +> +{ +protected: + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory; +public: + ManifestWriter( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xNewFactory ); + virtual ~ManifestWriter(); + + // XManifestWriter + virtual void SAL_CALL writeManifestSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rStream, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& rSequence ) + throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) + throw (::com::sun::star::uno::RuntimeException); + + // Component constructor + static ::rtl::OUString static_getImplementationName(); + static ::com::sun::star::uno::Sequence < ::rtl::OUString > static_getSupportedServiceNames(); + static ::com::sun::star::uno::Reference < com::sun::star::lang::XSingleServiceFactory > createServiceFactory( com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > const & rServiceFactory ); + sal_Bool SAL_CALL static_supportsService(rtl::OUString const & rServiceName); +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/UnoRegister.cxx b/package/source/manifest/UnoRegister.cxx new file mode 100644 index 000000000000..51b7ea431de5 --- /dev/null +++ b/package/source/manifest/UnoRegister.cxx @@ -0,0 +1,155 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_package.hxx" +#include <ManifestReader.hxx> +#include <ManifestWriter.hxx> +#include <cppuhelper/factory.hxx> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <osl/diagnose.h> +#include <ZipPackage.hxx> + +#include <zipfileaccess.hxx> + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::registry; +using namespace ::com::sun::star::packages; +using namespace ::com::sun::star::packages::manifest; + +using rtl::OUString; + +static sal_Bool writeInfo( void * pRegistryKey, + const OUString & rImplementationName, + Sequence< OUString > const & rServiceNames ) +{ + OUString aKeyName( OUString(RTL_CONSTASCII_USTRINGPARAM( "/" )) ); + aKeyName += rImplementationName; + aKeyName += OUString(RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES" )); + + Reference< XRegistryKey > xKey; + try + { + xKey = static_cast< XRegistryKey * >( + pRegistryKey )->createKey( aKeyName ); + } + catch ( InvalidRegistryException const & ) + { + } + + if ( !xKey.is() ) + return sal_False; + + sal_Bool bSuccess = sal_True; + + for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n ) + { + try + { + xKey->createKey( rServiceNames[ n ] ); + } + catch ( InvalidRegistryException const & ) + { + bSuccess = sal_False; + break; + } + } + return bSuccess; +} +// C functions to implement this as a component + +extern "C" void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +/** + * This function creates an implementation section in the registry and another subkey + * for each supported service. + * @param pServiceManager generic uno interface providing a service manager + * @param pRegistryKey generic uno interface providing registry key to write + */ +extern "C" sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/, void* pRegistryKey ) +{ + return pRegistryKey && + writeInfo (pRegistryKey, + ManifestReader::static_getImplementationName(), + ManifestReader::static_getSupportedServiceNames() ) && + writeInfo (pRegistryKey, + ManifestWriter::static_getImplementationName(), + ManifestWriter::static_getSupportedServiceNames() ) && + writeInfo (pRegistryKey, + ZipPackage::static_getImplementationName(), + ZipPackage::static_getSupportedServiceNames() ) && + + writeInfo (pRegistryKey, + OZipFileAccess::impl_staticGetImplementationName(), + OZipFileAccess::impl_staticGetSupportedServiceNames() ); + +} + + +/** + * This function is called to get service factories for an implementation. + * @param pImplName name of implementation + * @param pServiceManager generic uno interface providing a service manager to instantiate components + * @param pRegistryKey registry data key to read and write component persistent data + * @return a component factory (generic uno interface) + */ +extern "C" void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) +{ + void * pRet = 0; + Reference< XMultiServiceFactory > xSMgr( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) ); + Reference< XSingleServiceFactory > xFactory; + + if (ManifestReader::static_getImplementationName().compareToAscii( pImplName ) == 0) + xFactory = ManifestReader::createServiceFactory ( xSMgr ); + else if (ManifestWriter::static_getImplementationName().compareToAscii( pImplName ) == 0) + xFactory = ManifestWriter::createServiceFactory ( xSMgr ); + else if (ZipPackage::static_getImplementationName().compareToAscii( pImplName ) == 0) + xFactory = ZipPackage::createServiceFactory ( xSMgr ); + else if ( OZipFileAccess::impl_staticGetImplementationName().compareToAscii( pImplName ) == 0 ) + xFactory = ::cppu::createSingleFactory( xSMgr, + OZipFileAccess::impl_staticGetImplementationName(), + OZipFileAccess::impl_staticCreateSelfInstance, + OZipFileAccess::impl_staticGetSupportedServiceNames() ); + + if ( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + return pRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/makefile.mk b/package/source/manifest/makefile.mk new file mode 100644 index 000000000000..abc61848fc45 --- /dev/null +++ b/package/source/manifest/makefile.mk @@ -0,0 +1,55 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=package +TARGET=manifest +AUTOSEG=true + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +.IF "$(L10N_framework)"=="" + +SLOFILES= \ + $(SLO)$/ManifestReader.obj \ + $(SLO)$/ManifestWriter.obj \ + $(SLO)$/ManifestImport.obj \ + $(SLO)$/ManifestExport.obj \ + $(SLO)$/Base64Codec.obj \ + $(SLO)$/UnoRegister.obj + +.ENDIF # L10N_framework + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk |