LCOV - code coverage report
Current view: top level - xmlsecurity/source/helper - xmlsignaturehelper2.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 89 0.0 %
Date: 2014-04-14 Functions: 0 19 0.0 %
Legend: Lines: hit not hit

          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             : #include <xmlsecurity/xmlsignaturehelper.hxx>
      21             : #include <xmlsignaturehelper2.hxx>
      22             : 
      23             : #include <tools/solar.h>
      24             : #include <unotools/streamhelper.hxx>
      25             : 
      26             : #include <com/sun/star/embed/XStorage.hpp>
      27             : #include <com/sun/star/embed/XStorageRawAccess.hpp>
      28             : #include <com/sun/star/embed/ElementModes.hpp>
      29             : #include <com/sun/star/beans/XPropertySet.hpp>
      30             : #include "rtl/uri.hxx"
      31             : 
      32             : using namespace com::sun::star;
      33             : 
      34           0 : ImplXMLSignatureListener::ImplXMLSignatureListener( const Link& rCreationResultListenerListener, const Link rVerifyResultListenerListener, const Link rStartSignatureElement )
      35             : {
      36           0 :     maCreationResultListenerListener = rCreationResultListenerListener;
      37           0 :     maVerifyResultListenerListener = rVerifyResultListenerListener;
      38           0 :     maStartVerifySignatureElementListener = rStartSignatureElement;
      39             : 
      40           0 : }
      41           0 : ImplXMLSignatureListener::~ImplXMLSignatureListener()
      42             : {
      43           0 : }
      44             : 
      45           0 : void ImplXMLSignatureListener::setNextHandler(
      46             :     uno::Reference< xml::sax::XDocumentHandler > xNextHandler)
      47             : {
      48           0 :     m_xNextHandler = xNextHandler;
      49           0 : }
      50             : 
      51           0 : void SAL_CALL ImplXMLSignatureListener::signatureCreated( sal_Int32 securityId, com::sun::star::xml::crypto::SecurityOperationStatus nResult )
      52             :         throw (com::sun::star::uno::RuntimeException, std::exception)
      53             : {
      54           0 :     XMLSignatureCreationResult aResult( securityId, nResult );
      55           0 :     maCreationResultListenerListener.Call( &aResult );
      56           0 : }
      57             : 
      58           0 : void SAL_CALL ImplXMLSignatureListener::signatureVerified( sal_Int32 securityId, com::sun::star::xml::crypto::SecurityOperationStatus nResult )
      59             :         throw (com::sun::star::uno::RuntimeException, std::exception)
      60             : {
      61           0 :     XMLSignatureVerifyResult aResult( securityId, nResult );
      62           0 :     maVerifyResultListenerListener.Call( &aResult );
      63           0 : }
      64             : 
      65             : // XDocumentHandler
      66           0 : void SAL_CALL ImplXMLSignatureListener::startDocument(  )
      67             :     throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException, std::exception)
      68             : {
      69           0 :     if (m_xNextHandler.is())
      70             :     {
      71           0 :         m_xNextHandler->startDocument();
      72             :     }
      73           0 : }
      74             : 
      75           0 : void SAL_CALL ImplXMLSignatureListener::endDocument(  )
      76             :     throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException, std::exception)
      77             : {
      78           0 :     if (m_xNextHandler.is())
      79             :     {
      80           0 :         m_xNextHandler->endDocument();
      81             :     }
      82           0 : }
      83             : 
      84           0 : void SAL_CALL ImplXMLSignatureListener::startElement( const OUString& aName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttribs )
      85             :         throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException, std::exception)
      86             : {
      87           0 :     if ( aName == "Signature" )
      88             :     {
      89           0 :             maStartVerifySignatureElementListener.Call( (void*)&xAttribs );
      90             :     }
      91             : 
      92           0 :     if (m_xNextHandler.is())
      93             :     {
      94           0 :         m_xNextHandler->startElement( aName, xAttribs );
      95             :     }
      96           0 : }
      97             : 
      98           0 : void SAL_CALL ImplXMLSignatureListener::endElement( const OUString& aName )
      99             :     throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException, std::exception)
     100             : {
     101           0 :     if (m_xNextHandler.is())
     102             :     {
     103           0 :         m_xNextHandler->endElement( aName );
     104             :     }
     105           0 : }
     106             : 
     107           0 : void SAL_CALL ImplXMLSignatureListener::characters( const OUString& aChars )
     108             :     throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException, std::exception)
     109             : {
     110           0 :     if (m_xNextHandler.is())
     111             :     {
     112           0 :         m_xNextHandler->characters( aChars );
     113             :     }
     114           0 : }
     115             : 
     116           0 : void SAL_CALL ImplXMLSignatureListener::ignorableWhitespace( const OUString& aWhitespaces )
     117             :     throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException, std::exception)
     118             : {
     119           0 :     if (m_xNextHandler.is())
     120             :     {
     121           0 :         m_xNextHandler->ignorableWhitespace( aWhitespaces );
     122             :     }
     123           0 : }
     124             : 
     125           0 : void SAL_CALL ImplXMLSignatureListener::processingInstruction( const OUString& aTarget, const OUString& aData )
     126             :     throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException, std::exception)
     127             : {
     128           0 :     if (m_xNextHandler.is())
     129             :     {
     130           0 :         m_xNextHandler->processingInstruction( aTarget, aData );
     131             :     }
     132           0 : }
     133             : 
     134           0 : void SAL_CALL ImplXMLSignatureListener::setDocumentLocator( const com::sun::star::uno::Reference< com::sun::star::xml::sax::XLocator >& xLocator )
     135             :     throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException, std::exception)
     136             : {
     137           0 :     if (m_xNextHandler.is())
     138             :     {
     139           0 :         m_xNextHandler->setDocumentLocator( xLocator );
     140             :     }
     141           0 : }
     142             : 
     143             : // XUriBinding
     144             : 
     145           0 : UriBindingHelper::UriBindingHelper()
     146             : {
     147           0 : }
     148             : 
     149           0 : UriBindingHelper::UriBindingHelper( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rxStorage )
     150             : {
     151           0 :     mxStorage = rxStorage;
     152           0 : }
     153             : 
     154           0 : void SAL_CALL UriBindingHelper::setUriBinding( const OUString& /*uri*/, const uno::Reference< io::XInputStream >&)
     155             :     throw (uno::Exception, uno::RuntimeException, std::exception)
     156             : {
     157           0 : }
     158             : 
     159           0 : uno::Reference< io::XInputStream > SAL_CALL UriBindingHelper::getUriBinding( const OUString& uri )
     160             :     throw (uno::Exception, uno::RuntimeException, std::exception)
     161             : {
     162           0 :     uno::Reference< io::XInputStream > xInputStream;
     163           0 :     if ( mxStorage.is() )
     164             :     {
     165           0 :         xInputStream = OpenInputStream( mxStorage, uri );
     166             :     }
     167             :     else
     168             :     {
     169           0 :         SvFileStream* pStream = new SvFileStream( uri, STREAM_READ );
     170           0 :         pStream->Seek( STREAM_SEEK_TO_END );
     171           0 :         sal_uLong nBytes = pStream->Tell();
     172           0 :         pStream->Seek( STREAM_SEEK_TO_BEGIN );
     173           0 :         SvLockBytesRef xLockBytes = new SvLockBytes( pStream, true );
     174           0 :         xInputStream = new utl::OInputStreamHelper( xLockBytes, nBytes );
     175             :     }
     176           0 :     return xInputStream;
     177             : }
     178             : 
     179           0 : uno::Reference < io::XInputStream > UriBindingHelper::OpenInputStream( const uno::Reference < embed::XStorage >& rxStore, const OUString& rURI )
     180             : {
     181             :     OSL_ASSERT(!rURI.isEmpty());
     182           0 :     uno::Reference < io::XInputStream > xInStream;
     183             : 
     184           0 :     sal_Int32 nSepPos = rURI.indexOf( '/' );
     185           0 :     if ( nSepPos == -1 )
     186             :     {
     187             :         // Cloning because of I can't keep all storage references open
     188             :         // MBA with think about a better API...
     189             :         const OUString sName = ::rtl::Uri::decode(
     190           0 :             rURI, rtl_UriDecodeStrict, rtl_UriCharClassRelSegment);
     191           0 :         if (sName.isEmpty() && !rURI.isEmpty())
     192           0 :             throw uno::Exception("Could not decode URI for stream element.", 0);
     193             : 
     194           0 :         uno::Reference< io::XStream > xStream;
     195           0 :         xStream = rxStore->cloneStreamElement( sName );
     196           0 :         if ( !xStream.is() )
     197           0 :             throw uno::RuntimeException();
     198           0 :         xInStream = xStream->getInputStream();
     199             :     }
     200             :     else
     201             :     {
     202             :         const OUString aStoreName = ::rtl::Uri::decode(
     203           0 :             rURI.copy( 0, nSepPos ), rtl_UriDecodeStrict, rtl_UriCharClassRelSegment);
     204           0 :         if (aStoreName.isEmpty() && !rURI.isEmpty())
     205           0 :             throw uno::Exception("Could not decode URI for stream element.", 0);
     206             : 
     207           0 :         OUString aElement = rURI.copy( nSepPos+1 );
     208           0 :         uno::Reference < embed::XStorage > xSubStore = rxStore->openStorageElement( aStoreName, embed::ElementModes::READ );
     209           0 :         xInStream = OpenInputStream( xSubStore, aElement );
     210             :     }
     211           0 :     return xInStream;
     212             : }
     213             : 
     214             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10