LCOV - code coverage report
Current view: top level - package/source/manifest - ManifestImport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 184 207 88.9 %
Date: 2012-08-25 Functions: 18 20 90.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 228 437 52.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : // MARKER( update_precomp.py ): autogen include statement, do not remove
      21                 :            : #include <ManifestImport.hxx>
      22                 :            : #include <ManifestDefines.hxx>
      23                 :            : #include <sax/tools/converter.hxx>
      24                 :            : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      25                 :            : #include <com/sun/star/xml/crypto/DigestID.hpp>
      26                 :            : #include <com/sun/star/xml/crypto/CipherID.hpp>
      27                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      28                 :            : 
      29                 :            : using namespace com::sun::star::uno;
      30                 :            : using namespace com::sun::star::beans;
      31                 :            : using namespace com::sun::star;
      32                 :            : using namespace std;
      33                 :            : 
      34                 :            : using ::rtl::OUString;
      35                 :            : 
      36                 :            : // ---------------------------------------------------
      37                 :       1571 : ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManVector )
      38                 :            : : bIgnoreEncryptData    ( sal_False )
      39                 :            : , nDerivedKeySize( 0 )
      40                 :            : , rManVector ( rNewManVector )
      41                 :            : 
      42                 :            : , sFileEntryElement     ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) )
      43                 :            : , sManifestElement      ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) )
      44                 :            : , sEncryptionDataElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) )
      45                 :            : , sAlgorithmElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ALGORITHM ) )
      46                 :            : , sStartKeyAlgElement   ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_START_KEY_GENERATION ) )
      47                 :            : , sKeyDerivationElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_KEY_DERIVATION ) )
      48                 :            : 
      49                 :            : , sCdataAttribute               ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) )
      50                 :            : , sMediaTypeAttribute           ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_MEDIA_TYPE ) )
      51                 :            : , sVersionAttribute             ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) )
      52                 :            : , sFullPathAttribute            ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_FULL_PATH ) )
      53                 :            : , sSizeAttribute                ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SIZE ) )
      54                 :            : , sSaltAttribute                ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) )
      55                 :            : , sInitialisationVectorAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_INITIALISATION_VECTOR ) )
      56                 :            : , sIterationCountAttribute      ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) )
      57                 :            : , sKeySizeAttribute             ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_SIZE ) )
      58                 :            : , sAlgorithmNameAttribute       ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ALGORITHM_NAME ) )
      59                 :            : , sStartKeyAlgNameAttribute     ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_START_KEY_GENERATION_NAME ) )
      60                 :            : , sKeyDerivationNameAttribute   ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_DERIVATION_NAME ) )
      61                 :            : , sChecksumAttribute            ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM ) )
      62                 :            : , sChecksumTypeAttribute        ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM_TYPE ) )
      63                 :            : 
      64                 :            : , sFullPathProperty             ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) )
      65                 :            : , sMediaTypeProperty            ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) )
      66                 :            : , sVersionProperty              ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) )
      67                 :            : , sIterationCountProperty       ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) )
      68                 :            : , sDerivedKeySizeProperty       ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) )
      69                 :            : , sSaltProperty                 ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) )
      70                 :            : , sInitialisationVectorProperty ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) )
      71                 :            : , sSizeProperty                 ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) )
      72                 :            : , sDigestProperty               ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) )
      73                 :            : , sEncryptionAlgProperty        ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) )
      74                 :            : , sStartKeyAlgProperty          ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) )
      75                 :            : , sDigestAlgProperty            ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) )
      76                 :            : 
      77                 :            : , sWhiteSpace                   ( RTL_CONSTASCII_USTRINGPARAM ( " " ) )
      78                 :            : 
      79                 :            : , sSHA256_URL                   ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_URL ) )
      80                 :            : , sSHA1_Name                    ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_NAME ) )
      81                 :            : , sSHA1_URL                     ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_URL ) )
      82                 :            : 
      83                 :            : , sSHA256_1k_URL                ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_1K_URL ) )
      84                 :            : , sSHA1_1k_Name                 ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_NAME ) )
      85                 :            : , sSHA1_1k_URL                  ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_URL ) )
      86                 :            : 
      87                 :            : , sBlowfish_Name                ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_NAME ) )
      88                 :            : , sBlowfish_URL                 ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_URL ) )
      89                 :            : , sAES128_URL                   ( RTL_CONSTASCII_USTRINGPARAM ( AES128_URL ) )
      90                 :            : , sAES192_URL                   ( RTL_CONSTASCII_USTRINGPARAM ( AES192_URL ) )
      91                 :            : , sAES256_URL                   ( RTL_CONSTASCII_USTRINGPARAM ( AES256_URL ) )
      92                 :            : 
      93                 :            : , sPBKDF2_Name                  ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_NAME ) )
      94 [ +  - ][ +  - ]:       1571 : , sPBKDF2_URL                   ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_URL ) )
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      95                 :            : {
      96         [ +  - ]:       1571 :     aStack.reserve( 10 );
      97                 :       1571 : }
      98                 :            : 
      99                 :            : // ---------------------------------------------------
     100                 :       1571 : ManifestImport::~ManifestImport ( void )
     101                 :            : {
     102         [ -  + ]:       3142 : }
     103                 :            : 
     104                 :            : // ---------------------------------------------------
     105                 :       1571 : void SAL_CALL ManifestImport::startDocument(  )
     106                 :            :         throw( xml::sax::SAXException, uno::RuntimeException )
     107                 :            : {
     108                 :       1571 : }
     109                 :            : 
     110                 :            : // ---------------------------------------------------
     111                 :       1571 : void SAL_CALL ManifestImport::endDocument(  )
     112                 :            :         throw( xml::sax::SAXException, uno::RuntimeException )
     113                 :            : {
     114                 :       1571 : }
     115                 :            : 
     116                 :       9752 : void ManifestImport::doFileEntry(StringHashMap &rConvertedAttribs)
     117                 :            :         throw( uno::RuntimeException )
     118                 :            : {
     119         [ +  - ]:       9752 :     aSequence.resize(PKG_SIZE_ENCR_MNFST);
     120                 :            : 
     121                 :       9752 :     aSequence[PKG_MNFST_FULLPATH].Name = sFullPathProperty;
     122 [ +  - ][ +  - ]:       9752 :     aSequence[PKG_MNFST_FULLPATH].Value <<= rConvertedAttribs[sFullPathAttribute];
     123                 :       9752 :     aSequence[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty;
     124 [ +  - ][ +  - ]:       9752 :     aSequence[PKG_MNFST_MEDIATYPE].Value <<= rConvertedAttribs[sMediaTypeAttribute];
     125                 :            : 
     126         [ +  - ]:       9752 :     OUString sVersion = rConvertedAttribs[sVersionAttribute];
     127         [ +  + ]:       9752 :     if ( sVersion.getLength() )
     128                 :            :     {
     129                 :        273 :         aSequence[PKG_MNFST_VERSION].Name = sVersionProperty;
     130         [ +  - ]:        273 :         aSequence[PKG_MNFST_VERSION].Value <<= sVersion;
     131                 :            :     }
     132                 :            : 
     133         [ +  - ]:       9752 :     OUString sSize = rConvertedAttribs[sSizeAttribute];
     134         [ +  + ]:       9752 :     if ( sSize.getLength() )
     135                 :            :     {
     136                 :         30 :         sal_Int32 nSize = sSize.toInt32();
     137                 :         30 :         aSequence[PKG_MNFST_UCOMPSIZE].Name = sSizeProperty;
     138         [ +  - ]:         30 :         aSequence[PKG_MNFST_UCOMPSIZE].Value <<= nSize;
     139                 :       9752 :     }
     140                 :       9752 : }
     141                 :            : 
     142                 :         30 : void ManifestImport::doEncryptionData(StringHashMap &rConvertedAttribs)
     143                 :            :         throw( uno::RuntimeException )
     144                 :            : {
     145                 :            :     // If this element exists, then this stream is encrypted and we need
     146                 :            :     // to import the initialisation vector, salt and iteration count used
     147                 :         30 :     nDerivedKeySize = 0;
     148         [ +  - ]:         30 :     OUString aString = rConvertedAttribs[sChecksumTypeAttribute];
     149         [ +  - ]:         30 :     if ( !bIgnoreEncryptData )
     150                 :            :     {
     151 [ +  + ][ -  + ]:         30 :         if ( aString.equals( sSHA1_1k_Name ) || aString.equals( sSHA1_1k_URL ) )
                 [ +  + ]
     152                 :            :         {
     153                 :         15 :             aSequence[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty;
     154         [ +  - ]:         15 :             aSequence[PKG_MNFST_DIGESTALG].Value <<= xml::crypto::DigestID::SHA1_1K;
     155                 :            :         }
     156         [ +  - ]:         15 :         else if ( aString.equals( sSHA256_1k_URL ) )
     157                 :            :         {
     158                 :         15 :             aSequence[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty;
     159         [ +  - ]:         15 :             aSequence[PKG_MNFST_DIGESTALG].Value <<= xml::crypto::DigestID::SHA256_1K;
     160                 :            :         }
     161                 :            :         else
     162                 :          0 :             bIgnoreEncryptData = sal_True;
     163                 :            : 
     164         [ +  - ]:         30 :         if ( !bIgnoreEncryptData )
     165                 :            :         {
     166         [ +  - ]:         30 :             aString = rConvertedAttribs[sChecksumAttribute];
     167         [ +  - ]:         30 :             uno::Sequence < sal_Int8 > aDecodeBuffer;
     168         [ +  - ]:         30 :             ::sax::Converter::decodeBase64(aDecodeBuffer, aString);
     169                 :         30 :             aSequence[PKG_MNFST_DIGEST].Name = sDigestProperty;
     170 [ +  - ][ +  - ]:         30 :             aSequence[PKG_MNFST_DIGEST].Value <<= aDecodeBuffer;
     171                 :            :         }
     172                 :         30 :     }
     173                 :         30 : }
     174                 :            : 
     175                 :         30 : void ManifestImport::doAlgorithm(StringHashMap &rConvertedAttribs)
     176                 :            :         throw( uno::RuntimeException )
     177                 :            : {
     178         [ +  - ]:         30 :     if ( !bIgnoreEncryptData )
     179                 :            :     {
     180         [ +  - ]:         30 :         OUString aString = rConvertedAttribs[sAlgorithmNameAttribute];
     181 [ -  + ][ +  + ]:         30 :         if ( aString.equals( sBlowfish_Name ) || aString.equals( sBlowfish_URL ) )
                 [ +  + ]
     182                 :            :         {
     183                 :         15 :             aSequence[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
     184         [ +  - ]:         15 :             aSequence[PKG_MNFST_ENCALG].Value <<= xml::crypto::CipherID::BLOWFISH_CFB_8;
     185                 :            :         }
     186         [ +  - ]:         15 :         else if ( aString.equals( sAES256_URL ) )
     187                 :            :         {
     188                 :         15 :             aSequence[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
     189         [ +  - ]:         15 :             aSequence[PKG_MNFST_ENCALG].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
     190                 :            :             OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 32, "Unexpected derived key length!" );
     191                 :         15 :             nDerivedKeySize = 32;
     192                 :            :         }
     193         [ #  # ]:          0 :         else if ( aString.equals( sAES192_URL ) )
     194                 :            :         {
     195                 :          0 :             aSequence[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
     196         [ #  # ]:          0 :             aSequence[PKG_MNFST_ENCALG].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
     197                 :            :             OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 24, "Unexpected derived key length!" );
     198                 :          0 :             nDerivedKeySize = 24;
     199                 :            :         }
     200         [ #  # ]:          0 :         else if ( aString.equals( sAES128_URL ) )
     201                 :            :         {
     202                 :          0 :             aSequence[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
     203         [ #  # ]:          0 :             aSequence[PKG_MNFST_ENCALG].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
     204                 :            :             OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 16, "Unexpected derived key length!" );
     205                 :          0 :             nDerivedKeySize = 16;
     206                 :            :         }
     207                 :            :         else
     208                 :          0 :             bIgnoreEncryptData = sal_True;
     209                 :            : 
     210         [ +  - ]:         30 :         if ( !bIgnoreEncryptData )
     211                 :            :         {
     212         [ +  - ]:         30 :             aString = rConvertedAttribs[sInitialisationVectorAttribute];
     213         [ +  - ]:         30 :             uno::Sequence < sal_Int8 > aDecodeBuffer;
     214         [ +  - ]:         30 :             ::sax::Converter::decodeBase64(aDecodeBuffer, aString);
     215                 :         30 :             aSequence[PKG_MNFST_INIVECTOR].Name = sInitialisationVectorProperty;
     216 [ +  - ][ +  - ]:         30 :             aSequence[PKG_MNFST_INIVECTOR].Value <<= aDecodeBuffer;
     217                 :         30 :         }
     218                 :            :     }
     219                 :         30 : }
     220                 :            : 
     221                 :         30 : void ManifestImport::doKeyDerivation(StringHashMap &rConvertedAttribs)
     222                 :            :         throw( uno::RuntimeException )
     223                 :            : {
     224         [ +  - ]:         30 :     if ( !bIgnoreEncryptData )
     225                 :            :     {
     226         [ +  - ]:         30 :         OUString aString = rConvertedAttribs[sKeyDerivationNameAttribute];
     227 [ #  # ][ +  - ]:         30 :         if ( aString.equals( sPBKDF2_Name ) || aString.equals( sPBKDF2_URL ) )
                 [ -  + ]
     228                 :            :         {
     229         [ +  - ]:         30 :             aString = rConvertedAttribs[sSaltAttribute];
     230         [ +  - ]:         30 :             uno::Sequence < sal_Int8 > aDecodeBuffer;
     231         [ +  - ]:         30 :             ::sax::Converter::decodeBase64(aDecodeBuffer, aString);
     232                 :         30 :             aSequence[PKG_MNFST_SALT].Name = sSaltProperty;
     233         [ +  - ]:         30 :             aSequence[PKG_MNFST_SALT].Value <<= aDecodeBuffer;
     234                 :            : 
     235         [ +  - ]:         30 :             aString = rConvertedAttribs[sIterationCountAttribute];
     236                 :         30 :             aSequence[PKG_MNFST_ITERATION].Name = sIterationCountProperty;
     237         [ +  - ]:         30 :             aSequence[PKG_MNFST_ITERATION].Value <<= aString.toInt32();
     238                 :            : 
     239         [ +  - ]:         30 :             aString = rConvertedAttribs[sKeySizeAttribute];
     240         [ +  - ]:         30 :             if ( aString.getLength() )
     241                 :            :             {
     242                 :         30 :                 sal_Int32 nKey = aString.toInt32();
     243                 :            :                 OSL_ENSURE( !nDerivedKeySize || nKey == nDerivedKeySize , "Provided derived key length differs from the expected one!" );
     244                 :         30 :                 nDerivedKeySize = nKey;
     245                 :            :             }
     246         [ #  # ]:          0 :             else if ( !nDerivedKeySize )
     247                 :          0 :                 nDerivedKeySize = 16;
     248                 :          0 :             else if ( nDerivedKeySize != 16 )
     249                 :            :                 OSL_ENSURE( sal_False, "Default derived key length differs from the expected one!" );
     250                 :            : 
     251                 :         30 :             aSequence[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty;
     252 [ +  - ][ +  - ]:         30 :             aSequence[PKG_MNFST_DERKEYSIZE].Value <<= nDerivedKeySize;
     253                 :            :         }
     254                 :            :         else
     255                 :         30 :             bIgnoreEncryptData = sal_True;
     256                 :            :     }
     257                 :         30 : }
     258                 :            : 
     259                 :         30 : void ManifestImport::doStartKeyAlg(StringHashMap &rConvertedAttribs)
     260                 :            :         throw( uno::RuntimeException )
     261                 :            : {
     262         [ +  - ]:         30 :     OUString aString = rConvertedAttribs[sStartKeyAlgNameAttribute];
     263         [ +  + ]:         30 :     if ( aString.equals( sSHA256_URL ) )
     264                 :            :     {
     265                 :         15 :         aSequence[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
     266         [ +  - ]:         15 :         aSequence[PKG_MNFST_STARTALG].Value <<= xml::crypto::DigestID::SHA256;
     267                 :            :     }
     268 [ -  + ][ #  # ]:         15 :     else if ( aString.equals( sSHA1_Name ) || aString.equals( sSHA1_URL ) )
                 [ +  - ]
     269                 :            :     {
     270                 :         15 :         aSequence[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
     271         [ +  - ]:         15 :         aSequence[PKG_MNFST_STARTALG].Value <<= xml::crypto::DigestID::SHA1;
     272                 :            :     }
     273                 :            :     else
     274                 :         30 :         bIgnoreEncryptData = sal_True;
     275                 :         30 : }
     276                 :            : 
     277                 :            : // ---------------------------------------------------
     278                 :      11443 : void SAL_CALL ManifestImport::startElement( const OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs )
     279                 :            :         throw( xml::sax::SAXException, uno::RuntimeException )
     280                 :            : {
     281         [ +  - ]:      11443 :     StringHashMap aConvertedAttribs;
     282         [ +  - ]:      11443 :     ::rtl::OUString aConvertedName = PushNameAndNamespaces( aName, xAttribs, aConvertedAttribs );
     283                 :            : 
     284                 :      11443 :     size_t nLevel = aStack.size();
     285                 :            : 
     286                 :            :     assert(nLevel >= 1);
     287                 :            : 
     288   [ +  +  +  +  :      11443 :     switch (nLevel)
                      - ]
     289                 :            :     {
     290                 :            :         case 1:
     291                 :            :         {
     292         [ -  + ]:       1571 :             if (!aConvertedName.equalsAscii(ELEMENT_MANIFEST)) //manifest:manifest
     293         [ #  # ]:          0 :                 aStack.back().m_bValid = false;
     294                 :       1571 :             break;
     295                 :            :         }
     296                 :            :         case 2:
     297                 :            :         {
     298         [ +  - ]:       9752 :             if (aConvertedName == sFileEntryElement) //manifest:file-entry
     299         [ +  - ]:       9752 :                 doFileEntry(aConvertedAttribs);
     300                 :            :             else
     301         [ #  # ]:          0 :                 aStack.back().m_bValid = false;
     302                 :       9752 :             break;
     303                 :            :         }
     304                 :            :         case 3:
     305                 :            :         {
     306                 :         30 :             ManifestStack::reverse_iterator aIter = aStack.rbegin();
     307         [ +  - ]:         30 :             ++aIter;
     308                 :            : 
     309 [ +  - ][ -  + ]:         30 :             if (!aIter->m_bValid)
     310         [ #  # ]:          0 :                 aStack.back().m_bValid = false;
     311         [ +  - ]:         30 :             else if (aConvertedName.equals(sEncryptionDataElement))   //manifest:encryption-data
     312         [ +  - ]:         30 :                 doEncryptionData(aConvertedAttribs);
     313                 :            :             else
     314         [ #  # ]:         30 :                 aStack.back().m_bValid = false;
     315                 :            :             break;
     316                 :            :         }
     317                 :            :         case 4:
     318                 :            :         {
     319                 :         90 :             ManifestStack::reverse_iterator aIter = aStack.rbegin();
     320         [ +  - ]:         90 :             ++aIter;
     321                 :            : 
     322 [ +  - ][ -  + ]:         90 :             if (!aIter->m_bValid)
     323         [ #  # ]:          0 :                 aStack.back().m_bValid = false;
     324         [ +  + ]:         90 :             else if (aConvertedName.equals(sAlgorithmElement))   //manifest:algorithm,
     325         [ +  - ]:         30 :                 doAlgorithm(aConvertedAttribs);
     326         [ +  + ]:         60 :             else if (aConvertedName.equals(sKeyDerivationElement)) //manifest:key-derivation,
     327         [ +  - ]:         30 :                 doKeyDerivation(aConvertedAttribs);
     328         [ +  - ]:         30 :             else if (aConvertedName.equals(sStartKeyAlgElement))   //manifest:start-key-generation
     329         [ +  - ]:         30 :                 doStartKeyAlg(aConvertedAttribs);
     330                 :            :             else
     331         [ #  # ]:         90 :                 aStack.back().m_bValid = false;
     332                 :            :             break;
     333                 :            :         }
     334                 :            :         default:
     335         [ #  # ]:          0 :             aStack.back().m_bValid = false;
     336                 :          0 :             break;
     337         [ +  - ]:      11443 :     }
     338                 :      11443 : }
     339                 :            : 
     340                 :            : namespace
     341                 :            : {
     342                 :     117024 :     bool isEmpty(const com::sun::star::beans::PropertyValue &rProp)
     343                 :            :     {
     344                 :     117024 :         return rProp.Name.isEmpty();
     345                 :            :     }
     346                 :            : }
     347                 :            : 
     348                 :            : // ---------------------------------------------------
     349                 :      11443 : void SAL_CALL ManifestImport::endElement( const OUString& aName )
     350                 :            :     throw( xml::sax::SAXException, uno::RuntimeException )
     351                 :            : {
     352         [ +  - ]:      11443 :     ::rtl::OUString aConvertedName = ConvertName( aName );
     353 [ +  - ][ +  - ]:      11443 :     if ( !aStack.empty() && aStack.rbegin()->m_aConvertedName.equals( aConvertedName ) )
         [ +  - ][ +  - ]
           [ +  -  #  # ]
     354                 :            :     {
     355 [ +  + ][ +  - ]:      11443 :         if ( aConvertedName.equals( sFileEntryElement ) && aStack.back().m_bValid )
         [ +  - ][ +  + ]
     356                 :            :         {
     357                 :       9752 :             com::sun::star::beans::PropertyValue aEmpty;
     358                 :            :             aSequence.erase(std::remove_if(aSequence.begin(), aSequence.end(),
     359 [ +  - ][ +  - ]:       9752 :                 isEmpty), aSequence.end());
     360                 :            : 
     361                 :       9752 :             bIgnoreEncryptData = sal_False;
     362 [ +  - ][ +  - ]:       9752 :             rManVector.push_back ( aSequence.getAsConstList() );
                 [ +  - ]
     363                 :            : 
     364                 :       9752 :             aSequence.clear();
     365                 :            :         }
     366                 :            : 
     367         [ +  - ]:      11443 :         aStack.pop_back();
     368                 :      11443 :     }
     369                 :      11443 : }
     370                 :            : 
     371                 :            : // ---------------------------------------------------
     372                 :      21243 : void SAL_CALL ManifestImport::characters( const OUString& /*aChars*/ )
     373                 :            :         throw( xml::sax::SAXException, uno::RuntimeException )
     374                 :            : {
     375                 :      21243 : }
     376                 :            : 
     377                 :            : // ---------------------------------------------------
     378                 :          0 : void SAL_CALL ManifestImport::ignorableWhitespace( const OUString& /*aWhitespaces*/ )
     379                 :            :         throw( xml::sax::SAXException, uno::RuntimeException )
     380                 :            : {
     381                 :          0 : }
     382                 :            : 
     383                 :            : // ---------------------------------------------------
     384                 :          0 : void SAL_CALL ManifestImport::processingInstruction( const OUString& /*aTarget*/, const OUString& /*aData*/ )
     385                 :            :         throw( xml::sax::SAXException, uno::RuntimeException )
     386                 :            : {
     387                 :          0 : }
     388                 :            : 
     389                 :            : // ---------------------------------------------------
     390                 :       1571 : void SAL_CALL ManifestImport::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& /*xLocator*/ )
     391                 :            :         throw( xml::sax::SAXException, uno::RuntimeException )
     392                 :            : {
     393                 :       1571 : }
     394                 :            : 
     395                 :            : // ---------------------------------------------------
     396                 :      11443 : ::rtl::OUString ManifestImport::PushNameAndNamespaces( const ::rtl::OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs, StringHashMap& o_aConvertedAttribs )
     397                 :            : {
     398         [ +  - ]:      11443 :     StringHashMap aNamespaces;
     399         [ +  - ]:      11443 :     ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > > aAttribsStrs;
     400                 :            : 
     401         [ +  - ]:      11443 :     if ( xAttribs.is() )
     402                 :            :     {
     403 [ +  - ][ +  - ]:      11443 :         sal_Int16 nAttrCount = xAttribs.is() ? xAttribs->getLength() : 0;
                 [ +  - ]
     404         [ +  - ]:      11443 :         aAttribsStrs.reserve( nAttrCount );
     405                 :            : 
     406         [ +  + ]:      33201 :         for( sal_Int16 nInd = 0; nInd < nAttrCount; nInd++ )
     407                 :            :         {
     408 [ +  - ][ +  - ]:      21758 :             ::rtl::OUString aAttrName = xAttribs->getNameByIndex( nInd );
     409 [ +  - ][ +  - ]:      21758 :             ::rtl::OUString aAttrValue = xAttribs->getValueByIndex( nInd );
     410   [ +  -  +  +  :      46346 :             if ( aAttrName.getLength() >= 5
             +  -  +  - ]
                 [ +  + ]
     411                 :      21758 :               && aAttrName.compareToAscii( "xmlns", 5 ) == 0
     412                 :       2830 :               && ( aAttrName.getLength() == 5 || aAttrName.getStr()[5] == ( sal_Unicode )':' ) )
     413                 :            :             {
     414                 :            :                 // this is a namespace declaration
     415         [ -  + ]:       1415 :                 ::rtl::OUString aNsName( ( aAttrName.getLength() == 5 ) ? ::rtl::OUString() : aAttrName.copy( 6 ) );
     416         [ +  - ]:       1415 :                 aNamespaces[aNsName] = aAttrValue;
     417                 :            :             }
     418                 :            :             else
     419                 :            :             {
     420                 :            :                 // this is no namespace declaration
     421         [ +  - ]:      20343 :                 aAttribsStrs.push_back( pair< ::rtl::OUString, ::rtl::OUString >( aAttrName, aAttrValue ) );
     422                 :            :             }
     423                 :      21758 :         }
     424                 :            :     }
     425                 :            : 
     426         [ +  - ]:      11443 :     ::rtl::OUString aConvertedName = ConvertNameWithNamespace( aName, aNamespaces );
     427         [ +  + ]:      11443 :     if ( !aConvertedName.getLength() )
     428         [ +  - ]:      10028 :         aConvertedName = ConvertName( aName );
     429                 :            : 
     430 [ +  - ][ +  - ]:      11443 :     aStack.push_back( ManifestScopeEntry( aConvertedName, aNamespaces ) );
                 [ +  - ]
     431                 :            : 
     432         [ +  + ]:      31786 :     for ( sal_uInt16 nInd = 0; nInd < aAttribsStrs.size(); nInd++ )
     433                 :            :     {
     434                 :            :         // convert the attribute names on filling
     435 [ +  - ][ +  - ]:      20343 :         o_aConvertedAttribs[ConvertName( aAttribsStrs[nInd].first )] = aAttribsStrs[nInd].second;
     436                 :            :     }
     437                 :            : 
     438         [ +  - ]:      11443 :     return aConvertedName;
     439                 :            : }
     440                 :            : 
     441                 :            : // ---------------------------------------------------
     442                 :      50073 : ::rtl::OUString ManifestImport::ConvertNameWithNamespace( const ::rtl::OUString& aName, const StringHashMap& aNamespaces )
     443                 :            : {
     444                 :      50073 :     ::rtl::OUString aNsAlias;
     445                 :      50073 :     ::rtl::OUString aPureName = aName;
     446                 :            : 
     447                 :      50073 :     sal_Int32 nInd = aName.indexOf( ( sal_Unicode )':' );
     448 [ +  - ][ +  - ]:      50073 :     if ( nInd != -1 && nInd < aName.getLength() )
                 [ +  - ]
     449                 :            :     {
     450                 :      50073 :         aNsAlias = aName.copy( 0, nInd );
     451                 :      50073 :         aPureName = aName.copy( nInd + 1 );
     452                 :            :     }
     453                 :            : 
     454                 :      50073 :     ::rtl::OUString aResult;
     455                 :            : 
     456         [ +  - ]:      50073 :     StringHashMap::const_iterator aIter = aNamespaces.find( aNsAlias );
     457 [ +  - ][ +  +  :     103995 :     if ( aIter != aNamespaces.end()
             +  +  +  - ]
                 [ +  - ]
           [ +  +  #  # ]
     458 [ +  - ][ +  - ]:      53922 :       && ( aIter->second == MANIFEST_NAMESPACE || aIter->second == MANIFEST_OASIS_NAMESPACE ) )
     459                 :            :     {
     460                 :            :         // no check for manifest.xml consistency currently since the old versions have supported inconsistent documents as well
     461         [ +  - ]:      40045 :         aResult = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MANIFEST_NSPREFIX ) );
     462                 :      40045 :         aResult += aPureName;
     463                 :            :     }
     464                 :            : 
     465                 :      50073 :     return aResult;
     466                 :            : }
     467                 :            : 
     468                 :            : // ---------------------------------------------------
     469                 :      41814 : ::rtl::OUString ManifestImport::ConvertName( const ::rtl::OUString& aName )
     470                 :            : {
     471                 :      41814 :     ::rtl::OUString aConvertedName;
     472 [ +  - ][ +  + ]:     114411 :     for ( ManifestStack::reverse_iterator aIter = aStack.rbegin(); !aConvertedName.getLength() && aIter != aStack.rend(); ++aIter )
         [ +  - ][ +  + ]
                 [ +  + ]
           [ +  +  #  # ]
     473                 :            :     {
     474 [ +  - ][ +  + ]:      72597 :         if ( !aIter->m_aNamespaces.empty() )
     475 [ +  - ][ +  - ]:      38630 :             aConvertedName = ConvertNameWithNamespace( aName, aIter->m_aNamespaces );
     476                 :            :     }
     477                 :            : 
     478         [ +  + ]:      41814 :     if ( !aConvertedName.getLength() )
     479                 :       3184 :         aConvertedName = aName;
     480                 :            : 
     481                 :      41814 :     return aConvertedName;
     482                 :            : }
     483                 :            : 
     484                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10