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