LCOV - code coverage report
Current view: top level - libreoffice/xmlsecurity/source/xmlsec/nss - xmlsecuritycontext_nssimpl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 63 0.0 %
Date: 2012-12-27 Functions: 0 17 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 <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 <sal/types.h>
      28             : //For reasons that escape me, this is what xmlsec does when size_t is not 4
      29             : #if SAL_TYPES_SIZEOFPOINTER != 4
      30             : #    define XMLSEC_NO_SIZE_T
      31             : #endif
      32             : #include "xmlsec/xmlsec.h"
      33             : #include "xmlsec/keysmngr.h"
      34             : #include "xmlsec/crypto.h"
      35             : 
      36             : using namespace ::com::sun::star::uno ;
      37             : using namespace ::com::sun::star::lang ;
      38             : using ::com::sun::star::lang::XMultiServiceFactory ;
      39             : using ::com::sun::star::lang::XSingleServiceFactory ;
      40             : using ::rtl::OUString ;
      41             : 
      42             : using ::com::sun::star::xml::crypto::XSecurityEnvironment ;
      43             : using ::com::sun::star::xml::crypto::XXMLSecurityContext ;
      44             : 
      45           0 : XMLSecurityContext_NssImpl :: XMLSecurityContext_NssImpl( const Reference< XMultiServiceFactory >& aFactory )
      46             :     ://i39448 : m_pKeysMngr( NULL ) ,
      47             :     m_xServiceManager( aFactory ) ,
      48           0 :     m_nDefaultEnvIndex(-1)
      49             :     //m_xSecurityEnvironment( NULL )
      50             : {
      51             :     //Init xmlsec library
      52           0 :     if( xmlSecInit() < 0 ) {
      53           0 :         throw RuntimeException() ;
      54             :     }
      55             : 
      56             :     //Init xmlsec crypto engine library
      57           0 :     if( xmlSecCryptoInit() < 0 ) {
      58           0 :         xmlSecShutdown() ;
      59           0 :         throw RuntimeException() ;
      60             :     }
      61             : 
      62             :     //Enable external stream handlers
      63           0 :     if( xmlEnableStreamInputCallbacks() < 0 ) {
      64           0 :         xmlSecCryptoShutdown() ;
      65           0 :         xmlSecShutdown() ;
      66           0 :         throw RuntimeException() ;
      67             :     }
      68           0 : }
      69             : 
      70           0 : XMLSecurityContext_NssImpl :: ~XMLSecurityContext_NssImpl() {
      71             :     //i39448
      72             : 
      73           0 :     xmlDisableStreamInputCallbacks() ;
      74           0 :     xmlSecCryptoShutdown() ;
      75           0 :     xmlSecShutdown() ;
      76           0 : }
      77             : 
      78             : //i39448 : new methods
      79           0 : sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::addSecurityEnvironment(
      80             :     const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment >& aSecurityEnvironment)
      81             :     throw (::com::sun::star::security::SecurityInfrastructureException, ::com::sun::star::uno::RuntimeException)
      82             : {
      83           0 :     if( !aSecurityEnvironment.is() )
      84             :     {
      85           0 :         throw RuntimeException() ;
      86             :     }
      87             : 
      88           0 :     m_vSecurityEnvironments.push_back( aSecurityEnvironment );
      89             : 
      90           0 :     return m_vSecurityEnvironments.size() - 1 ;
      91             : }
      92             : 
      93             : 
      94           0 : sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::getSecurityEnvironmentNumber(  )
      95             :     throw (::com::sun::star::uno::RuntimeException)
      96             : {
      97           0 :     return m_vSecurityEnvironments.size();
      98             : }
      99             : 
     100             : ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > SAL_CALL
     101           0 :     XMLSecurityContext_NssImpl::getSecurityEnvironmentByIndex( sal_Int32 index )
     102             :     throw (::com::sun::star::uno::RuntimeException)
     103             : {
     104           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > xSecurityEnvironment;
     105             : 
     106           0 :     if (index >= 0 && index < ( sal_Int32 )m_vSecurityEnvironments.size())
     107             :     {
     108           0 :         xSecurityEnvironment = m_vSecurityEnvironments[index];
     109             :     }
     110             :     else
     111           0 :         throw RuntimeException() ;
     112             : 
     113           0 :     return xSecurityEnvironment;
     114             : }
     115             : 
     116             : ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > SAL_CALL
     117           0 :     XMLSecurityContext_NssImpl::getSecurityEnvironment(  )
     118             :     throw (::com::sun::star::uno::RuntimeException)
     119             : {
     120           0 :     if (m_nDefaultEnvIndex >= 0 && m_nDefaultEnvIndex < ( sal_Int32 )m_vSecurityEnvironments.size())
     121           0 :         return getSecurityEnvironmentByIndex(m_nDefaultEnvIndex);
     122             :     else
     123           0 :         throw RuntimeException() ;
     124             : }
     125             : 
     126           0 : sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::getDefaultSecurityEnvironmentIndex(  )
     127             :     throw (::com::sun::star::uno::RuntimeException)
     128             : {
     129           0 :     return m_nDefaultEnvIndex ;
     130             : }
     131             : 
     132           0 : void SAL_CALL XMLSecurityContext_NssImpl::setDefaultSecurityEnvironmentIndex( sal_Int32 nDefaultEnvIndex )
     133             :     throw (::com::sun::star::uno::RuntimeException)
     134             : {
     135           0 :     m_nDefaultEnvIndex = nDefaultEnvIndex;
     136           0 : }
     137             : 
     138             : //i39448 : old methods deleted
     139             : 
     140             : 
     141             : /* XInitialization */
     142           0 : void SAL_CALL XMLSecurityContext_NssImpl :: initialize( const Sequence< Any >& /*aArguments*/ ) throw( Exception, RuntimeException ) {
     143             :     // TBD
     144           0 : } ;
     145             : 
     146             : /* XServiceInfo */
     147           0 : OUString SAL_CALL XMLSecurityContext_NssImpl :: getImplementationName() throw( RuntimeException ) {
     148           0 :     return impl_getImplementationName() ;
     149             : }
     150             : 
     151             : /* XServiceInfo */
     152           0 : sal_Bool SAL_CALL XMLSecurityContext_NssImpl :: supportsService( const OUString& serviceName) throw( RuntimeException ) {
     153           0 :     Sequence< OUString > seqServiceNames = getSupportedServiceNames() ;
     154           0 :     const OUString* pArray = seqServiceNames.getConstArray() ;
     155           0 :     for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) {
     156           0 :         if( *( pArray + i ) == serviceName )
     157           0 :             return sal_True ;
     158             :     }
     159           0 :     return sal_False ;
     160             : }
     161             : 
     162             : /* XServiceInfo */
     163           0 : Sequence< OUString > SAL_CALL XMLSecurityContext_NssImpl :: getSupportedServiceNames() throw( RuntimeException ) {
     164           0 :     return impl_getSupportedServiceNames() ;
     165             : }
     166             : 
     167             : //Helper for XServiceInfo
     168           0 : Sequence< OUString > XMLSecurityContext_NssImpl :: impl_getSupportedServiceNames() {
     169           0 :     ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
     170           0 :     Sequence< OUString > seqServiceNames( 1 ) ;
     171           0 :     seqServiceNames.getArray()[0] = OUString("com.sun.star.xml.crypto.XMLSecurityContext") ;
     172           0 :     return seqServiceNames ;
     173             : }
     174             : 
     175           0 : OUString XMLSecurityContext_NssImpl :: impl_getImplementationName() throw( RuntimeException ) {
     176           0 :     return OUString("com.sun.star.xml.security.bridge.xmlsec.XMLSecurityContext_NssImpl") ;
     177             : }
     178             : 
     179             : //Helper for registry
     180           0 : Reference< XInterface > SAL_CALL XMLSecurityContext_NssImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
     181           0 :     return Reference< XInterface >( *new XMLSecurityContext_NssImpl( aServiceManager ) ) ;
     182             : }
     183             : 
     184           0 : Reference< XSingleServiceFactory > XMLSecurityContext_NssImpl :: impl_createFactory( const Reference< XMultiServiceFactory >& aServiceManager ) {
     185             :     //Reference< XSingleServiceFactory > xFactory ;
     186             :     //xFactory = ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName , impl_createInstance , impl_getSupportedServiceNames ) ;
     187             :     //return xFactory ;
     188           0 :     return ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName() , impl_createInstance , impl_getSupportedServiceNames() ) ;
     189             : }
     190             : 
     191             : 
     192             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10