merged tag ooo/OOO330_m14
[LibreOffice.git] / xmlsecurity / source / framework / xsec_framework.cxx
blob57eb78028df3fbd0ec050ccdef4bf10db0018cac
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmlsecurity.hxx"
31 #include <stdio.h>
33 #include <osl/mutex.hxx>
34 #include <osl/thread.h>
35 #include <cppuhelper/factory.hxx>
36 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
38 #include <decryptorimpl.hxx>
39 #include <encryptorimpl.hxx>
40 #include <signaturecreatorimpl.hxx>
41 #include <signatureverifierimpl.hxx>
42 #include <saxeventkeeperimpl.hxx>
43 #include <xmlencryptiontemplateimpl.hxx>
44 #include <xmlsignaturetemplateimpl.hxx>
46 using namespace ::rtl;
47 using namespace ::cppu;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::lang;
50 using namespace ::com::sun::star::registry;
52 extern "C"
54 //==================================================================================================
55 void SAL_CALL component_getImplementationEnvironment(
56 const sal_Char ** ppEnvTypeName, uno_Environment **)
58 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
61 //==================================================================================================
62 sal_Bool SAL_CALL component_writeInfo(
63 void * /*pServiceManager*/, void * pRegistryKey )
65 if (pRegistryKey)
67 try
69 //Decryptor
70 sal_Int32 nPos = 0;
71 Reference< XRegistryKey > xNewKey(
72 reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( DecryptorImpl_getImplementationName() ) );
73 xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
75 const Sequence< OUString > & rSNL = DecryptorImpl_getSupportedServiceNames();
76 const OUString * pArray = rSNL.getConstArray();
77 for ( nPos = rSNL.getLength(); nPos--; )
78 xNewKey->createKey( pArray[nPos] );
80 //Encryptor
81 xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( EncryptorImpl_getImplementationName() );
82 xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
83 const Sequence< OUString > & rSNL2 = EncryptorImpl_getSupportedServiceNames();
84 pArray = rSNL2.getConstArray();
85 for ( nPos = rSNL2.getLength(); nPos--; )
86 xNewKey->createKey( pArray[nPos] );
88 //SignatureCreator
89 xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( SignatureCreatorImpl_getImplementationName() );
90 xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
91 const Sequence< OUString > & rSNL3 = SignatureCreatorImpl_getSupportedServiceNames();
92 pArray = rSNL3.getConstArray();
93 for ( nPos = rSNL3.getLength(); nPos--; )
94 xNewKey->createKey( pArray[nPos] );
96 //SignatureVerifier
97 xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( SignatureVerifierImpl_getImplementationName() );
98 xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
99 const Sequence< OUString > & rSNL4 = SignatureVerifierImpl_getSupportedServiceNames();
100 pArray = rSNL4.getConstArray();
101 for ( nPos = rSNL4.getLength(); nPos--; )
102 xNewKey->createKey( pArray[nPos] );
104 //SAXEventKeeper
105 xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( SAXEventKeeperImpl_getImplementationName() );
106 xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
107 const Sequence< OUString > & rSNL5 = SAXEventKeeperImpl_getSupportedServiceNames();
108 pArray = rSNL5.getConstArray();
109 for ( nPos = rSNL5.getLength(); nPos--; )
110 xNewKey->createKey( pArray[nPos] );
112 //XMLSignatureTemplateImpl
113 xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( XMLSignatureTemplateImpl::impl_getImplementationName() );
114 xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
115 const Sequence< OUString > & rSNL6 = XMLSignatureTemplateImpl::impl_getSupportedServiceNames();
116 pArray = rSNL6.getConstArray();
117 for ( nPos = rSNL6.getLength(); nPos--; )
118 xNewKey->createKey( pArray[nPos] );
120 // XMLEncryptionTemplateImpl
121 xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( XMLEncryptionTemplateImpl::impl_getImplementationName() );
122 xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
123 const Sequence< OUString > & rSNL7 = XMLEncryptionTemplateImpl::impl_getSupportedServiceNames();
124 pArray = rSNL7.getConstArray();
125 for ( nPos = rSNL7.getLength(); nPos--; )
126 xNewKey->createKey( pArray[nPos] );
128 return sal_True;
130 catch (InvalidRegistryException &)
132 OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
135 return sal_False;
138 //==================================================================================================
139 void * SAL_CALL component_getFactory(
140 const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ )
142 void * pRet = 0;
144 //Decryptor
145 OUString implName = OUString::createFromAscii( pImplName );
146 if ( pServiceManager && implName.equals(DecryptorImpl_getImplementationName()) )
148 Reference< XSingleServiceFactory > xFactory( createSingleFactory(
149 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
150 OUString::createFromAscii( pImplName ),
151 DecryptorImpl_createInstance, DecryptorImpl_getSupportedServiceNames() ) );
153 if (xFactory.is())
155 xFactory->acquire();
156 pRet = xFactory.get();
160 //Encryptor
161 if ( pServiceManager && implName.equals(EncryptorImpl_getImplementationName()) )
163 Reference< XSingleServiceFactory > xFactory( createSingleFactory(
164 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
165 OUString::createFromAscii( pImplName ),
166 EncryptorImpl_createInstance, EncryptorImpl_getSupportedServiceNames() ) );
168 if (xFactory.is())
170 xFactory->acquire();
171 pRet = xFactory.get();
175 //SignatureCreator
176 if ( pServiceManager && implName.equals(SignatureCreatorImpl_getImplementationName()) )
178 Reference< XSingleServiceFactory > xFactory( createSingleFactory(
179 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
180 OUString::createFromAscii( pImplName ),
181 SignatureCreatorImpl_createInstance, SignatureCreatorImpl_getSupportedServiceNames() ) );
183 if (xFactory.is())
185 xFactory->acquire();
186 pRet = xFactory.get();
190 //SignatureVerifier
191 if ( pServiceManager && implName.equals(SignatureVerifierImpl_getImplementationName()) )
193 Reference< XSingleServiceFactory > xFactory( createSingleFactory(
194 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
195 OUString::createFromAscii( pImplName ),
196 SignatureVerifierImpl_createInstance, SignatureVerifierImpl_getSupportedServiceNames() ) );
198 if (xFactory.is())
200 xFactory->acquire();
201 pRet = xFactory.get();
205 //SAXEventKeeper
206 if ( pServiceManager && implName.equals(SAXEventKeeperImpl_getImplementationName()) )
208 Reference< XSingleServiceFactory > xFactory( createSingleFactory(
209 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
210 OUString::createFromAscii( pImplName ),
211 SAXEventKeeperImpl_createInstance, SAXEventKeeperImpl_getSupportedServiceNames() ) );
213 if (xFactory.is())
215 xFactory->acquire();
216 pRet = xFactory.get();
220 //XMLSignatureTemplate
221 if ( pServiceManager && implName.equals( XMLSignatureTemplateImpl::impl_getImplementationName()) )
223 Reference< XSingleServiceFactory > xFactory = XMLSignatureTemplateImpl::impl_createFactory(
224 reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
226 if (xFactory.is())
228 xFactory->acquire();
229 pRet = xFactory.get();
233 //XMLEncryptionTemplate
234 if ( pServiceManager && implName.equals( XMLEncryptionTemplateImpl::impl_getImplementationName()) )
236 Reference< XSingleServiceFactory > xFactory = XMLEncryptionTemplateImpl::impl_createFactory(
237 reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
239 if (xFactory.is())
241 xFactory->acquire();
242 pRet = xFactory.get();
246 return pRet;