LCOV - code coverage report
Current view: top level - xmlsecurity/source/xmlsec/nss - xmlsecuritycontext_nssimpl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 26 61 42.6 %
Date: 2015-06-13 12:38:46 Functions: 9 16 56.2 %
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 <sal/config.h>
      21             : #include <rtl/uuid.h>
      22             : #include "securityenvironment_nssimpl.hxx"
      23             : 
      24             : #include "xmlsecuritycontext_nssimpl.hxx"
      25             : #include "xmlstreamio.hxx"
      26             : 
      27             : #include "xmlsecurity/xmlsec-wrapper.h"
      28             : 
      29             : using namespace ::com::sun::star::uno ;
      30             : using namespace ::com::sun::star::lang ;
      31             : using ::com::sun::star::lang::XMultiServiceFactory ;
      32             : using ::com::sun::star::lang::XSingleServiceFactory ;
      33             : 
      34             : using ::com::sun::star::xml::crypto::XSecurityEnvironment ;
      35             : using ::com::sun::star::xml::crypto::XXMLSecurityContext ;
      36             : 
      37           1 : XMLSecurityContext_NssImpl :: XMLSecurityContext_NssImpl()
      38           1 :     : m_nDefaultEnvIndex(-1)
      39             : {
      40             :     //Init xmlsec library
      41           1 :     if( xmlSecInit() < 0 ) {
      42           0 :         throw RuntimeException() ;
      43             :     }
      44             : 
      45             :     //Init xmlsec crypto engine library
      46           1 :     if( xmlSecCryptoInit() < 0 ) {
      47           0 :         xmlSecShutdown() ;
      48           0 :         throw RuntimeException() ;
      49             :     }
      50             : 
      51             :     //Enable external stream handlers
      52           1 :     if( xmlEnableStreamInputCallbacks() < 0 ) {
      53           0 :         xmlSecCryptoShutdown() ;
      54           0 :         xmlSecShutdown() ;
      55           0 :         throw RuntimeException() ;
      56             :     }
      57           1 : }
      58             : 
      59           3 : XMLSecurityContext_NssImpl :: ~XMLSecurityContext_NssImpl()
      60             : {
      61           1 :     xmlDisableStreamInputCallbacks() ;
      62           1 :     xmlSecCryptoShutdown() ;
      63           1 :     xmlSecShutdown() ;
      64           2 : }
      65             : 
      66           0 : sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::addSecurityEnvironment(
      67             :     const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment >& aSecurityEnvironment)
      68             :     throw (::com::sun::star::security::SecurityInfrastructureException, ::com::sun::star::uno::RuntimeException, std::exception)
      69             : {
      70           0 :     if( !aSecurityEnvironment.is() )
      71             :     {
      72           0 :         throw RuntimeException() ;
      73             :     }
      74             : 
      75           0 :     m_vSecurityEnvironments.push_back( aSecurityEnvironment );
      76             : 
      77           0 :     return m_vSecurityEnvironments.size() - 1 ;
      78             : }
      79             : 
      80             : 
      81           0 : sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::getSecurityEnvironmentNumber(  )
      82             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
      83             : {
      84           0 :     return m_vSecurityEnvironments.size();
      85             : }
      86             : 
      87             : ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > SAL_CALL
      88           0 :     XMLSecurityContext_NssImpl::getSecurityEnvironmentByIndex( sal_Int32 index )
      89             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
      90             : {
      91           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > xSecurityEnvironment;
      92             : 
      93           0 :     if (index >= 0 && index < ( sal_Int32 )m_vSecurityEnvironments.size())
      94             :     {
      95           0 :         xSecurityEnvironment = m_vSecurityEnvironments[index];
      96             :     }
      97             :     else
      98           0 :         throw RuntimeException() ;
      99             : 
     100           0 :     return xSecurityEnvironment;
     101             : }
     102             : 
     103             : ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > SAL_CALL
     104           0 :     XMLSecurityContext_NssImpl::getSecurityEnvironment(  )
     105             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     106             : {
     107           0 :     if (m_nDefaultEnvIndex >= 0 && m_nDefaultEnvIndex < ( sal_Int32 )m_vSecurityEnvironments.size())
     108           0 :         return getSecurityEnvironmentByIndex(m_nDefaultEnvIndex);
     109             :     else
     110           0 :         throw RuntimeException() ;
     111             : }
     112             : 
     113           0 : sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::getDefaultSecurityEnvironmentIndex(  )
     114             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     115             : {
     116           0 :     return m_nDefaultEnvIndex ;
     117             : }
     118             : 
     119           0 : void SAL_CALL XMLSecurityContext_NssImpl::setDefaultSecurityEnvironmentIndex( sal_Int32 nDefaultEnvIndex )
     120             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     121             : {
     122           0 :     m_nDefaultEnvIndex = nDefaultEnvIndex;
     123           0 : }
     124             : 
     125             : /* XServiceInfo */
     126           1 : OUString SAL_CALL XMLSecurityContext_NssImpl :: getImplementationName() throw( RuntimeException, std::exception ) {
     127           1 :     return impl_getImplementationName() ;
     128             : }
     129             : 
     130             : /* XServiceInfo */
     131           0 : sal_Bool SAL_CALL XMLSecurityContext_NssImpl :: supportsService( const OUString& serviceName) throw( RuntimeException, std::exception ) {
     132           0 :     Sequence< OUString > seqServiceNames = getSupportedServiceNames() ;
     133           0 :     const OUString* pArray = seqServiceNames.getConstArray() ;
     134           0 :     for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) {
     135           0 :         if( *( pArray + i ) == serviceName )
     136           0 :             return sal_True ;
     137             :     }
     138           0 :     return sal_False ;
     139             : }
     140             : 
     141             : /* XServiceInfo */
     142           1 : Sequence< OUString > SAL_CALL XMLSecurityContext_NssImpl :: getSupportedServiceNames() throw( RuntimeException, std::exception ) {
     143           1 :     return impl_getSupportedServiceNames() ;
     144             : }
     145             : 
     146             : //Helper for XServiceInfo
     147           2 : Sequence< OUString > XMLSecurityContext_NssImpl :: impl_getSupportedServiceNames() {
     148           2 :     ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
     149           2 :     Sequence< OUString > seqServiceNames( 1 ) ;
     150           2 :     seqServiceNames[0] = "com.sun.star.xml.crypto.XMLSecurityContext";
     151           2 :     return seqServiceNames ;
     152             : }
     153             : 
     154           5 : OUString XMLSecurityContext_NssImpl :: impl_getImplementationName() throw( RuntimeException ) {
     155           5 :     return OUString("com.sun.star.xml.security.bridge.xmlsec.XMLSecurityContext_NssImpl") ;
     156             : }
     157             : 
     158             : //Helper for registry
     159           1 : Reference< XInterface > SAL_CALL XMLSecurityContext_NssImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& ) throw( RuntimeException ) {
     160           1 :     return Reference< XInterface >( *new XMLSecurityContext_NssImpl ) ;
     161             : }
     162             : 
     163           1 : Reference< XSingleServiceFactory > XMLSecurityContext_NssImpl :: impl_createFactory( const Reference< XMultiServiceFactory >& aServiceManager ) {
     164             :     //Reference< XSingleServiceFactory > xFactory ;
     165             :     //xFactory = ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName , impl_createInstance , impl_getSupportedServiceNames ) ;
     166             :     //return xFactory ;
     167           1 :     return ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName() , impl_createInstance , impl_getSupportedServiceNames() ) ;
     168             : }
     169             : 
     170             : 
     171             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11