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 {
toString(const Sequence<sal_Int8> & rSerialNumber)52 virtual OUString SAL_CALL toString( const Sequence< sal_Int8 >& rSerialNumber )
53 {
54 return bigIntegerToNumericString(rSerialNumber);
55 }
toSequence(const OUString & rSerialNumber)56 virtual Sequence< sal_Int8 > SAL_CALL toSequence( const OUString& rSerialNumber )
57 {
58 return numericStringToBigInteger(rSerialNumber);
59 }
60 };
61
SerialNumberAdapterImpl_getImplementationName()62 OUString SerialNumberAdapterImpl_getImplementationName()
63 {
64 return OUString(RTL_CONSTASCII_USTRINGPARAM(
65 "com.sun.star.security.SerialNumberAdapter"));
66 }
67
SerialNumberAdapterImpl_getSupportedServiceNames()68 Sequence< OUString > SerialNumberAdapterImpl_getSupportedServiceNames()
69 {
70 Sequence < OUString > aRet(1);
71 OUString* pArray = aRet.getArray();
72 pArray[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(
73 "com.sun.star.security.SerialNumberAdapter" ) );
74 return aRet;
75 }
76
SerialNumberAdapterImpl_createInstance(const Reference<XComponentContext> &)77 Reference< XInterface > SerialNumberAdapterImpl_createInstance(
78 const Reference< XComponentContext > &)
79 {
80 return Reference< XInterface >( *new SerialNumberAdapterImpl() );
81 }
82
83 }
84
85 extern "C"
86 {
87
88 extern void* nss_component_getFactory( const sal_Char*, void*, void* );
89
90 #if defined( XMLSEC_CRYPTO_MSCRYPTO )
91 extern void* mscrypt_component_getFactory( const sal_Char*, void*, void* );
92 #endif
93
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)94 void SAL_CALL component_getImplementationEnvironment(
95 const sal_Char ** ppEnvTypeName, uno_Environment **)
96 {
97 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
98 }
99
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void * pRegistryKey)100 void* SAL_CALL component_getFactory( const sal_Char* pImplName , void* pServiceManager , void* pRegistryKey )
101 {
102 void* pRet = 0;
103 Reference< XInterface > xFactory ;
104
105 if( pImplName != NULL && pServiceManager != NULL ) {
106 if( XMLElementWrapper_XmlSecImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) )
107 {
108 xFactory = Reference< XSingleServiceFactory >( createSingleFactory(
109 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
110 OUString::createFromAscii( pImplName ),
111 XMLElementWrapper_XmlSecImpl_createInstance, XMLElementWrapper_XmlSecImpl_getSupportedServiceNames() ) );
112 }
113 else if( XMLDocumentWrapper_XmlSecImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) )
114 {
115 xFactory = Reference< XSingleServiceFactory >( createSingleFactory(
116 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
117 OUString::createFromAscii( pImplName ),
118 XMLDocumentWrapper_XmlSecImpl_createInstance, XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames() ) );
119 }
120 else if( SerialNumberAdapterImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) )
121 {
122 xFactory = ::cppu::createSingleComponentFactory(
123 SerialNumberAdapterImpl_createInstance,
124 OUString::createFromAscii( pImplName ),
125 SerialNumberAdapterImpl_getSupportedServiceNames() );
126 }
127 }
128
129 if( xFactory.is() ) {
130 xFactory->acquire() ;
131 pRet = xFactory.get() ;
132 } else {
133 pRet = nss_component_getFactory( pImplName, pServiceManager, pRegistryKey ) ;
134 if( pRet != NULL )
135 return pRet ;
136
137 #if defined( XMLSEC_CRYPTO_MSCRYPTO )
138 pRet = mscrypt_component_getFactory( pImplName, pServiceManager, pRegistryKey ) ;
139 if( pRet != NULL )
140 return pRet ;
141 #endif
142 }
143
144 return pRet ;
145 }
146
147 }
148