1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_xmlsecurity.hxx" 26 27 #include <sal/config.h> 28 #include <stdio.h> 29 30 #include <osl/mutex.hxx> 31 #include <osl/thread.h> 32 #include <cppuhelper/factory.hxx> 33 #include <cppuhelper/implbase1.hxx> 34 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 35 #include <com/sun/star/security/XSerialNumberAdapter.hpp> 36 37 #include "xmlelementwrapper_xmlsecimpl.hxx" 38 #include "xmldocumentwrapper_xmlsecimpl.hxx" 39 #include "xmlsecurity/biginteger.hxx" 40 41 using namespace ::rtl; 42 using namespace ::cppu; 43 using namespace ::com::sun::star::uno; 44 using namespace ::com::sun::star::lang; 45 using namespace ::com::sun::star::registry; 46 47 namespace 48 { 49 class SerialNumberAdapterImpl : public WeakImplHelper1< 50 ::com::sun::star::security::XSerialNumberAdapter > 51 { 52 virtual OUString SAL_CALL toString( const Sequence< sal_Int8 >& rSerialNumber ) 53 throw (RuntimeException) 54 { 55 return bigIntegerToNumericString(rSerialNumber); 56 } 57 virtual Sequence< sal_Int8 > SAL_CALL toSequence( const OUString& rSerialNumber ) 58 throw (RuntimeException) 59 { 60 return numericStringToBigInteger(rSerialNumber); 61 } 62 }; 63 64 OUString SerialNumberAdapterImpl_getImplementationName() 65 throw (RuntimeException) 66 { 67 return OUString(RTL_CONSTASCII_USTRINGPARAM( 68 "com.sun.star.security.SerialNumberAdapter")); 69 } 70 71 Sequence< OUString > SerialNumberAdapterImpl_getSupportedServiceNames() 72 throw (RuntimeException) 73 { 74 Sequence < OUString > aRet(1); 75 OUString* pArray = aRet.getArray(); 76 pArray[0] = OUString(RTL_CONSTASCII_USTRINGPARAM( 77 "com.sun.star.security.SerialNumberAdapter" ) ); 78 return aRet; 79 } 80 81 Reference< XInterface > SerialNumberAdapterImpl_createInstance( 82 const Reference< XComponentContext > &) throw( Exception ) 83 { 84 return Reference< XInterface >( *new SerialNumberAdapterImpl() ); 85 } 86 87 } 88 89 extern "C" 90 { 91 92 extern void* nss_component_getFactory( const sal_Char*, void*, void* ); 93 94 #if defined( XMLSEC_CRYPTO_MSCRYPTO ) 95 extern void* mscrypt_component_getFactory( const sal_Char*, void*, void* ); 96 #endif 97 98 void SAL_CALL component_getImplementationEnvironment( 99 const sal_Char ** ppEnvTypeName, uno_Environment **) 100 { 101 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 102 } 103 104 void* SAL_CALL component_getFactory( const sal_Char* pImplName , void* pServiceManager , void* pRegistryKey ) 105 { 106 void* pRet = 0; 107 Reference< XInterface > xFactory ; 108 109 if( pImplName != NULL && pServiceManager != NULL ) { 110 if( XMLElementWrapper_XmlSecImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) 111 { 112 xFactory = Reference< XSingleServiceFactory >( createSingleFactory( 113 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), 114 OUString::createFromAscii( pImplName ), 115 XMLElementWrapper_XmlSecImpl_createInstance, XMLElementWrapper_XmlSecImpl_getSupportedServiceNames() ) ); 116 } 117 else if( XMLDocumentWrapper_XmlSecImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) 118 { 119 xFactory = Reference< XSingleServiceFactory >( createSingleFactory( 120 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), 121 OUString::createFromAscii( pImplName ), 122 XMLDocumentWrapper_XmlSecImpl_createInstance, XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames() ) ); 123 } 124 else if( SerialNumberAdapterImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) 125 { 126 xFactory = ::cppu::createSingleComponentFactory( 127 SerialNumberAdapterImpl_createInstance, 128 OUString::createFromAscii( pImplName ), 129 SerialNumberAdapterImpl_getSupportedServiceNames() ); 130 } 131 } 132 133 if( xFactory.is() ) { 134 xFactory->acquire() ; 135 pRet = xFactory.get() ; 136 } else { 137 pRet = nss_component_getFactory( pImplName, pServiceManager, pRegistryKey ) ; 138 if( pRet != NULL ) 139 return pRet ; 140 141 #if defined( XMLSEC_CRYPTO_MSCRYPTO ) 142 pRet = mscrypt_component_getFactory( pImplName, pServiceManager, pRegistryKey ) ; 143 if( pRet != NULL ) 144 return pRet ; 145 #endif 146 } 147 148 return pRet ; 149 } 150 151 } 152 153