update dev300-m58
[ooovba.git] / xmlsecurity / source / xmlsec / nss / xsec_nss.cxx
blob9ae4cc681cbffb2100be08438a31473f503fa9de
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xsec_nss.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlsecurity.hxx"
34 #include <sal/config.h>
35 #include <stdio.h>
37 #include <osl/mutex.hxx>
38 #include <osl/thread.h>
39 #include <cppuhelper/factory.hxx>
40 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
42 #include "seinitializer_nssimpl.hxx"
43 #include "xmlsignature_nssimpl.hxx"
44 #include "xmlencryption_nssimpl.hxx"
45 #include "xmlsecuritycontext_nssimpl.hxx"
46 #include "securityenvironment_nssimpl.hxx"
48 using namespace ::rtl;
49 using namespace ::cppu;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::lang;
52 using namespace ::com::sun::star::registry;
54 extern "C"
57 sal_Bool SAL_CALL nss_component_writeInfo( void* /*pServiceManager*/ , void* pRegistryKey )
59 sal_Bool result = sal_False;
60 sal_Int32 i ;
61 OUString sKeyName ;
62 Reference< XRegistryKey > xNewKey ;
63 Sequence< OUString > seqServices ;
64 Reference< XRegistryKey > xKey( reinterpret_cast< XRegistryKey* >( pRegistryKey ) ) ;
66 if( xKey.is() ) {
67 // try {
68 // XMLSignature_NssImpl
69 sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
70 sKeyName += XMLSignature_NssImpl::impl_getImplementationName() ;
71 sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
73 xNewKey = xKey->createKey( sKeyName ) ;
74 if( xNewKey.is() ) {
75 seqServices = XMLSignature_NssImpl::impl_getSupportedServiceNames() ;
76 for( i = seqServices.getLength() ; i -- ; )
77 xNewKey->createKey( seqServices.getConstArray()[i] ) ;
80 // XMLEncryption_NssImpl
81 sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
82 sKeyName += XMLEncryption_NssImpl::impl_getImplementationName() ;
83 sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
85 xNewKey = xKey->createKey( sKeyName ) ;
86 if( xNewKey.is() ) {
87 seqServices = XMLEncryption_NssImpl::impl_getSupportedServiceNames() ;
88 for( i = seqServices.getLength() ; i -- ; )
89 xNewKey->createKey( seqServices.getConstArray()[i] ) ;
92 // XMLSecurityContext_NssImpl
93 sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
94 sKeyName += XMLSecurityContext_NssImpl::impl_getImplementationName() ;
95 sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
97 xNewKey = xKey->createKey( sKeyName ) ;
98 if( xNewKey.is() ) {
99 seqServices = XMLSecurityContext_NssImpl::impl_getSupportedServiceNames() ;
100 for( i = seqServices.getLength() ; i -- ; )
101 xNewKey->createKey( seqServices.getConstArray()[i] ) ;
104 // SecurityEnvironment_NssImpl
105 sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
106 sKeyName += SecurityEnvironment_NssImpl::impl_getImplementationName() ;
107 sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
109 xNewKey = xKey->createKey( sKeyName ) ;
110 if( xNewKey.is() ) {
111 seqServices = SecurityEnvironment_NssImpl::impl_getSupportedServiceNames() ;
112 for( i = seqServices.getLength() ; i -- ; )
113 xNewKey->createKey( seqServices.getConstArray()[i] ) ;
116 // SEInitializer_NssImpl
117 sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
118 sKeyName += SEInitializer_NssImpl_getImplementationName() ;
119 sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
121 xNewKey = xKey->createKey( sKeyName ) ;
122 if( xNewKey.is() ) {
123 seqServices = SEInitializer_NssImpl_getSupportedServiceNames() ;
124 for( i = seqServices.getLength() ; i -- ; )
125 xNewKey->createKey( seqServices.getConstArray()[i] ) ;
128 return sal_True;
129 //} catch( InvalidRegistryException & ) {
130 // //we should not ignore exceptions
131 // return sal_False ;
134 return result;
137 void* SAL_CALL nss_component_getFactory( const sal_Char* pImplName , void* pServiceManager , void* /*pRegistryKey*/ )
139 void* pRet = 0;
140 Reference< XSingleServiceFactory > xFactory ;
142 if( pImplName != NULL && pServiceManager != NULL ) {
143 if( XMLSignature_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) {
144 xFactory = XMLSignature_NssImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
145 } else if( XMLSecurityContext_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) {
146 xFactory = XMLSecurityContext_NssImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
147 } else if( SecurityEnvironment_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) {
148 xFactory = SecurityEnvironment_NssImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
149 } else if( XMLEncryption_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) {
150 xFactory = XMLEncryption_NssImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
151 } else if( SEInitializer_NssImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) {
152 xFactory = Reference< XSingleServiceFactory >( createSingleFactory(
153 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
154 OUString::createFromAscii( pImplName ),
155 SEInitializer_NssImpl_createInstance, SEInitializer_NssImpl_getSupportedServiceNames() ) );
159 if( xFactory.is() ) {
160 xFactory->acquire() ;
161 pRet = xFactory.get() ;
164 return pRet ;