bump product version to 4.1.6.2
[LibreOffice.git] / xmlsecurity / source / xmlsec / nss / xmlsecuritycontext_nssimpl.cxx
blobcd3c863d3e7fa9059e2465f646cacb3f1e404664
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
21 #include <rtl/uuid.h>
22 #include "securityenvironment_nssimpl.hxx"
24 #include "xmlsecuritycontext_nssimpl.hxx"
25 #include "xmlstreamio.hxx"
27 #include "xmlsecurity/xmlsec-wrapper.h"
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 ;
34 using ::com::sun::star::xml::crypto::XSecurityEnvironment ;
35 using ::com::sun::star::xml::crypto::XXMLSecurityContext ;
37 XMLSecurityContext_NssImpl :: XMLSecurityContext_NssImpl( const Reference< XMultiServiceFactory >& aFactory )
38 ://i39448 : m_pKeysMngr( NULL ) ,
39 m_xServiceManager( aFactory ) ,
40 m_nDefaultEnvIndex(-1)
41 //m_xSecurityEnvironment( NULL )
43 //Init xmlsec library
44 if( xmlSecInit() < 0 ) {
45 throw RuntimeException() ;
48 //Init xmlsec crypto engine library
49 if( xmlSecCryptoInit() < 0 ) {
50 xmlSecShutdown() ;
51 throw RuntimeException() ;
54 //Enable external stream handlers
55 if( xmlEnableStreamInputCallbacks() < 0 ) {
56 xmlSecCryptoShutdown() ;
57 xmlSecShutdown() ;
58 throw RuntimeException() ;
62 XMLSecurityContext_NssImpl :: ~XMLSecurityContext_NssImpl() {
63 //i39448
65 xmlDisableStreamInputCallbacks() ;
66 xmlSecCryptoShutdown() ;
67 xmlSecShutdown() ;
70 //i39448 : new methods
71 sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::addSecurityEnvironment(
72 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment >& aSecurityEnvironment)
73 throw (::com::sun::star::security::SecurityInfrastructureException, ::com::sun::star::uno::RuntimeException)
75 if( !aSecurityEnvironment.is() )
77 throw RuntimeException() ;
80 m_vSecurityEnvironments.push_back( aSecurityEnvironment );
82 return m_vSecurityEnvironments.size() - 1 ;
86 sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::getSecurityEnvironmentNumber( )
87 throw (::com::sun::star::uno::RuntimeException)
89 return m_vSecurityEnvironments.size();
92 ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > SAL_CALL
93 XMLSecurityContext_NssImpl::getSecurityEnvironmentByIndex( sal_Int32 index )
94 throw (::com::sun::star::uno::RuntimeException)
96 ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > xSecurityEnvironment;
98 if (index >= 0 && index < ( sal_Int32 )m_vSecurityEnvironments.size())
100 xSecurityEnvironment = m_vSecurityEnvironments[index];
102 else
103 throw RuntimeException() ;
105 return xSecurityEnvironment;
108 ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > SAL_CALL
109 XMLSecurityContext_NssImpl::getSecurityEnvironment( )
110 throw (::com::sun::star::uno::RuntimeException)
112 if (m_nDefaultEnvIndex >= 0 && m_nDefaultEnvIndex < ( sal_Int32 )m_vSecurityEnvironments.size())
113 return getSecurityEnvironmentByIndex(m_nDefaultEnvIndex);
114 else
115 throw RuntimeException() ;
118 sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::getDefaultSecurityEnvironmentIndex( )
119 throw (::com::sun::star::uno::RuntimeException)
121 return m_nDefaultEnvIndex ;
124 void SAL_CALL XMLSecurityContext_NssImpl::setDefaultSecurityEnvironmentIndex( sal_Int32 nDefaultEnvIndex )
125 throw (::com::sun::star::uno::RuntimeException)
127 m_nDefaultEnvIndex = nDefaultEnvIndex;
130 //i39448 : old methods deleted
133 /* XInitialization */
134 void SAL_CALL XMLSecurityContext_NssImpl :: initialize( const Sequence< Any >& /*aArguments*/ ) throw( Exception, RuntimeException ) {
135 // TBD
138 /* XServiceInfo */
139 OUString SAL_CALL XMLSecurityContext_NssImpl :: getImplementationName() throw( RuntimeException ) {
140 return impl_getImplementationName() ;
143 /* XServiceInfo */
144 sal_Bool SAL_CALL XMLSecurityContext_NssImpl :: supportsService( const OUString& serviceName) throw( RuntimeException ) {
145 Sequence< OUString > seqServiceNames = getSupportedServiceNames() ;
146 const OUString* pArray = seqServiceNames.getConstArray() ;
147 for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) {
148 if( *( pArray + i ) == serviceName )
149 return sal_True ;
151 return sal_False ;
154 /* XServiceInfo */
155 Sequence< OUString > SAL_CALL XMLSecurityContext_NssImpl :: getSupportedServiceNames() throw( RuntimeException ) {
156 return impl_getSupportedServiceNames() ;
159 //Helper for XServiceInfo
160 Sequence< OUString > XMLSecurityContext_NssImpl :: impl_getSupportedServiceNames() {
161 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
162 Sequence< OUString > seqServiceNames( 1 ) ;
163 seqServiceNames.getArray()[0] = OUString("com.sun.star.xml.crypto.XMLSecurityContext") ;
164 return seqServiceNames ;
167 OUString XMLSecurityContext_NssImpl :: impl_getImplementationName() throw( RuntimeException ) {
168 return OUString("com.sun.star.xml.security.bridge.xmlsec.XMLSecurityContext_NssImpl") ;
171 //Helper for registry
172 Reference< XInterface > SAL_CALL XMLSecurityContext_NssImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
173 return Reference< XInterface >( *new XMLSecurityContext_NssImpl( aServiceManager ) ) ;
176 Reference< XSingleServiceFactory > XMLSecurityContext_NssImpl :: impl_createFactory( const Reference< XMultiServiceFactory >& aServiceManager ) {
177 //Reference< XSingleServiceFactory > xFactory ;
178 //xFactory = ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName , impl_createInstance , impl_getSupportedServiceNames ) ;
179 //return xFactory ;
180 return ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName() , impl_createInstance , impl_getSupportedServiceNames() ) ;
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */