1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmlsecurity.hxx"
30 
31 #include <sal/config.h>
32 #include <stdio.h>
33 
34 #include <osl/mutex.hxx>
35 #include <osl/thread.h>
36 #include <cppuhelper/factory.hxx>
37 #include <cppuhelper/implbase1.hxx>
38 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
39 #include <com/sun/star/security/XSerialNumberAdapter.hpp>
40 
41 #include "xmlelementwrapper_xmlsecimpl.hxx"
42 #include "xmldocumentwrapper_xmlsecimpl.hxx"
43 #include "xmlsecurity/biginteger.hxx"
44 
45 using namespace ::rtl;
46 using namespace ::cppu;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::lang;
49 using namespace ::com::sun::star::registry;
50 
51 namespace
52 {
53 class SerialNumberAdapterImpl : public WeakImplHelper1<
54         ::com::sun::star::security::XSerialNumberAdapter >
55 {
56     virtual OUString SAL_CALL toString( const Sequence< sal_Int8 >& rSerialNumber )
57         throw (RuntimeException)
58     {
59         return bigIntegerToNumericString(rSerialNumber);
60     }
61     virtual Sequence< sal_Int8 > SAL_CALL toSequence( const OUString& rSerialNumber )
62         throw (RuntimeException)
63     {
64         return numericStringToBigInteger(rSerialNumber);
65     }
66 };
67 
68 OUString SerialNumberAdapterImpl_getImplementationName()
69     throw (RuntimeException)
70 {
71     return OUString(RTL_CONSTASCII_USTRINGPARAM(
72         "com.sun.star.security.SerialNumberAdapter"));
73 }
74 
75 Sequence< OUString > SerialNumberAdapterImpl_getSupportedServiceNames()
76     throw (RuntimeException)
77 {
78     Sequence < OUString > aRet(1);
79     OUString* pArray = aRet.getArray();
80     pArray[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(
81         "com.sun.star.security.SerialNumberAdapter" ) );
82     return aRet;
83 }
84 
85 Reference< XInterface > SerialNumberAdapterImpl_createInstance(
86     const Reference< XComponentContext > &) throw( Exception )
87 {
88     return Reference< XInterface >( *new SerialNumberAdapterImpl() );
89 }
90 
91 }
92 
93 extern "C"
94 {
95 
96 extern void* nss_component_getFactory( const sal_Char*, void*, void* );
97 
98 #if defined( XMLSEC_CRYPTO_MSCRYPTO )
99 extern void* mscrypt_component_getFactory( const sal_Char*, void*, void* );
100 #endif
101 
102 void SAL_CALL component_getImplementationEnvironment(
103 	const sal_Char ** ppEnvTypeName, uno_Environment **)
104 {
105 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
106 }
107 
108 void* SAL_CALL component_getFactory( const sal_Char* pImplName , void* pServiceManager , void* pRegistryKey )
109 {
110 	void* pRet = 0;
111 	Reference< XInterface > xFactory ;
112 
113 	if( pImplName != NULL && pServiceManager != NULL ) {
114 		if( XMLElementWrapper_XmlSecImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) )
115 		{
116 			xFactory = Reference< XSingleServiceFactory >( createSingleFactory(
117 				reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
118 				OUString::createFromAscii( pImplName ),
119 				XMLElementWrapper_XmlSecImpl_createInstance, XMLElementWrapper_XmlSecImpl_getSupportedServiceNames() ) );
120 		}
121 		else if( XMLDocumentWrapper_XmlSecImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) )
122 		{
123 			xFactory = Reference< XSingleServiceFactory >( createSingleFactory(
124 				reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
125 				OUString::createFromAscii( pImplName ),
126 				XMLDocumentWrapper_XmlSecImpl_createInstance, XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames() ) );
127 		}
128 		else if( SerialNumberAdapterImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) )
129 		{
130 			xFactory = ::cppu::createSingleComponentFactory(
131               SerialNumberAdapterImpl_createInstance,
132               OUString::createFromAscii( pImplName ),
133               SerialNumberAdapterImpl_getSupportedServiceNames() );
134 		}
135 	}
136 
137 	if( xFactory.is() ) {
138 		xFactory->acquire() ;
139 		pRet = xFactory.get() ;
140 	} else {
141 		pRet = nss_component_getFactory( pImplName, pServiceManager, pRegistryKey ) ;
142 		if( pRet != NULL )
143 			return pRet ;
144 
145 #if defined( XMLSEC_CRYPTO_MSCRYPTO )
146 		pRet = mscrypt_component_getFactory( pImplName, pServiceManager, pRegistryKey ) ;
147 		if( pRet != NULL )
148 			return pRet ;
149 #endif
150 	}
151 
152 	return pRet ;
153 }
154 
155 }
156 
157