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

Generated by: LCOV version 1.11