Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include <stdlib.h>
22 : : #include <osl/file.h>
23 : : #include <vector>
24 : : #include <osl/mutex.hxx>
25 : : #include <osl/diagnose.h>
26 : : #include <osl/module.h>
27 : : #include <rtl/ustring.hxx>
28 : : #include <uno/environment.h>
29 : : #include <uno/mapping.hxx>
30 : : #include <cppuhelper/queryinterface.hxx>
31 : : #include <cppuhelper/weak.hxx>
32 : : #include <cppuhelper/factory.hxx>
33 : : #include <cppuhelper/shlib.hxx>
34 : : #include <cppuhelper/implbase3.hxx>
35 : : #include <cppuhelper/implementationentry.hxx>
36 : : #include <cppuhelper/bootstrap.hxx>
37 : :
38 : : #include <com/sun/star/loader/XImplementationLoader.hpp>
39 : : #include <com/sun/star/lang/IllegalArgumentException.hpp>
40 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 : : #include <com/sun/star/lang/XServiceInfo.hpp>
42 : : #include <com/sun/star/lang/XInitialization.hpp>
43 : : #include <com/sun/star/registry/XRegistryKey.hpp>
44 : :
45 : : #define SERVICENAME "com.sun.star.loader.SharedLibrary"
46 : : #define IMPLNAME "com.sun.star.comp.stoc.DLLComponentLoader"
47 : :
48 : : #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
49 : :
50 : :
51 : : using namespace com::sun::star;
52 : : using namespace com::sun::star::uno;
53 : : using namespace com::sun::star::loader;
54 : : using namespace com::sun::star::lang;
55 : : using namespace com::sun::star::registry;
56 : : using namespace cppu;
57 : : using namespace osl;
58 : : using ::rtl::OUString;
59 : : extern rtl_StandardModuleCount g_moduleCount;
60 : :
61 : : namespace stoc_bootstrap
62 : : {
63 : 756 : Sequence< OUString > loader_getSupportedServiceNames()
64 : : {
65 : 756 : Sequence< OUString > seqNames(1);
66 [ + - ][ + - ]: 756 : seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME));
67 : 756 : return seqNames;
68 : : }
69 : :
70 : 10036 : OUString loader_getImplementationName()
71 : : {
72 : 10036 : return OUString(RTL_CONSTASCII_USTRINGPARAM(IMPLNAME));
73 : : }
74 : : }
75 : :
76 : : namespace stoc_loader
77 : : {
78 : : //*************************************************************************
79 : : // DllComponentLoader
80 : : //*************************************************************************
81 : : class DllComponentLoader
82 : : : public WeakImplHelper3< XImplementationLoader,
83 : : XInitialization,
84 : : XServiceInfo >
85 : : {
86 : : public:
87 : : DllComponentLoader( const Reference<XComponentContext> & xCtx );
88 : : ~DllComponentLoader();
89 : :
90 : : // XServiceInfo
91 : : virtual OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException);
92 : : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
93 : : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
94 : :
95 : : // XInitialization
96 : : virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
97 : :
98 : : // XImplementationLoader
99 : : virtual Reference<XInterface> SAL_CALL activate( const OUString& implementationName, const OUString& implementationLoaderUrl, const OUString& locationUrl, const Reference<XRegistryKey>& xKey ) throw(CannotActivateFactoryException, RuntimeException);
100 : : virtual sal_Bool SAL_CALL writeRegistryInfo( const Reference<XRegistryKey>& xKey, const OUString& implementationLoaderUrl, const OUString& locationUrl ) throw(CannotRegisterImplementationException, RuntimeException);
101 : :
102 : : private:
103 : : OUString expand_url( OUString const & url )
104 : : SAL_THROW( (RuntimeException) );
105 : :
106 : : Reference<XMultiServiceFactory> m_xSMgr;
107 : : };
108 : :
109 : : //*************************************************************************
110 : 414 : DllComponentLoader::DllComponentLoader( const Reference<XComponentContext> & xCtx )
111 : : {
112 [ + - ]: 414 : g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
113 [ + - ][ + - ]: 414 : m_xSMgr.set( xCtx->getServiceManager(), UNO_QUERY );
[ + - ]
114 : 414 : }
115 : :
116 : : //*************************************************************************
117 : 414 : DllComponentLoader::~DllComponentLoader()
118 : : {
119 [ + - ]: 414 : g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
120 [ - + ]: 828 : }
121 : :
122 : : //*************************************************************************
123 : 0 : OUString SAL_CALL DllComponentLoader::getImplementationName( )
124 : : throw(::com::sun::star::uno::RuntimeException)
125 : : {
126 : 0 : return stoc_bootstrap::loader_getImplementationName();
127 : : }
128 : :
129 : : //*************************************************************************
130 : 0 : sal_Bool SAL_CALL DllComponentLoader::supportsService( const OUString& ServiceName )
131 : : throw(::com::sun::star::uno::RuntimeException)
132 : : {
133 [ # # ]: 0 : Sequence< OUString > aSNL = getSupportedServiceNames();
134 [ # # ]: 0 : const OUString * pArray = aSNL.getArray();
135 [ # # ]: 0 : for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
136 [ # # ]: 0 : if( pArray[i] == ServiceName )
137 : 0 : return sal_True;
138 [ # # ]: 0 : return sal_False;
139 : : }
140 : :
141 : : //*************************************************************************
142 : 0 : Sequence<OUString> SAL_CALL DllComponentLoader::getSupportedServiceNames( )
143 : : throw(::com::sun::star::uno::RuntimeException)
144 : : {
145 : 0 : return stoc_bootstrap::loader_getSupportedServiceNames();
146 : : }
147 : :
148 : : //*************************************************************************
149 : 0 : void DllComponentLoader::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& )
150 : : throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
151 : : {
152 : : OSL_FAIL( "dllcomponentloader::initialize should not be called !" );
153 : : // if( aArgs.getLength() != 1 )
154 : : // {
155 : : // throw IllegalArgumentException();
156 : : // }
157 : :
158 : : // Reference< XMultiServiceFactory > rServiceManager;
159 : :
160 : : // if( aArgs.getConstArray()[0].getValueType().getTypeClass() == TypeClass_INTERFACE )
161 : : // {
162 : : // aArgs.getConstArray()[0] >>= rServiceManager;
163 : : // }
164 : :
165 : : // if( !rServiceManager.is() )
166 : : // {
167 : : // throw IllegalArgumentException();
168 : : // }
169 : :
170 : : // m_xSMgr = rServiceManager;
171 : 0 : }
172 : :
173 : : //==================================================================================================
174 : 414 : OUString DllComponentLoader::expand_url( OUString const & url )
175 : : SAL_THROW( (RuntimeException) )
176 : : {
177 : : try
178 : : {
179 [ + - ]: 414 : return cppu::bootstrap_expandUri( url );
180 : : }
181 [ # # ]: 0 : catch ( const IllegalArgumentException & e )
182 : : {
183 [ # # ]: 0 : throw RuntimeException( e.Message, e.Context );
184 : : }
185 : : }
186 : :
187 : : //*************************************************************************
188 : 414 : Reference<XInterface> SAL_CALL DllComponentLoader::activate(
189 : : const OUString & rImplName, const OUString &, const OUString & rLibName,
190 : : const Reference< XRegistryKey > & xKey )
191 : :
192 : : throw(CannotActivateFactoryException, RuntimeException)
193 : : {
194 : 414 : rtl::OUString aPrefix;
195 [ + - ]: 414 : if( xKey.is() )
196 : : {
197 [ + - ]: 414 : Reference<XRegistryKey > xActivatorKey = xKey->openKey(
198 [ + - ][ + - ]: 414 : rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/ACTIVATOR") ) );
199 [ + - ][ + - ]: 414 : if (xActivatorKey.is() && xActivatorKey->getValueType() == RegistryValueType_ASCII )
[ + - ][ + - ]
[ + - ]
200 : : {
201 [ + - ]: 414 : Reference<XRegistryKey > xPrefixKey = xKey->openKey(
202 [ + - ][ + - ]: 414 : rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/PREFIX") ) );
203 [ + - ][ + - ]: 414 : if( xPrefixKey.is() && xPrefixKey->getValueType() == RegistryValueType_ASCII )
[ + - ][ + - ]
[ + - ]
204 : : {
205 [ + - ][ + - ]: 414 : aPrefix = xPrefixKey->getAsciiValue();
206 [ + + ]: 414 : if( !aPrefix.isEmpty() )
207 [ + - ]: 394 : aPrefix = aPrefix + OUSTR("_");
208 : 414 : }
209 : 414 : }
210 : : }
211 : :
212 : : return loadSharedLibComponentFactory(
213 [ + - ][ + - ]: 414 : expand_url( rLibName ), OUString(), rImplName, m_xSMgr, xKey, aPrefix );
214 : : }
215 : :
216 : :
217 : : //*************************************************************************
218 : 0 : sal_Bool SAL_CALL DllComponentLoader::writeRegistryInfo(
219 : : const Reference< XRegistryKey > & xKey, const OUString &, const OUString & rLibName )
220 : :
221 : : throw(CannotRegisterImplementationException, RuntimeException)
222 : : {
223 : : #ifdef DISABLE_DYNLOADING
224 : : (void) xKey;
225 : : (void) rLibName;
226 : : OSL_FAIL( "DllComponentLoader::writeRegistryInfo() should not be called I think?" );
227 : : return sal_False;
228 : : #else
229 : : writeSharedLibComponentInfo(
230 [ # # ][ # # ]: 0 : expand_url( rLibName ), OUString(), m_xSMgr, xKey );
231 : 0 : return sal_True;
232 : : #endif
233 : : }
234 : : }
235 : :
236 : : namespace stoc_bootstrap
237 : : {
238 : : //*************************************************************************
239 : 414 : Reference<XInterface> SAL_CALL DllComponentLoader_CreateInstance( const Reference<XComponentContext> & xCtx ) throw(Exception)
240 : : {
241 : 414 : Reference<XInterface> xRet;
242 : :
243 [ + - ][ + - ]: 414 : XImplementationLoader *pXLoader = (XImplementationLoader *)new stoc_loader::DllComponentLoader(xCtx);
244 : :
245 [ + - ]: 414 : if (pXLoader)
246 : : {
247 [ + - ][ + - ]: 414 : xRet = Reference<XInterface>::query(pXLoader);
248 : : }
249 : :
250 : 414 : return xRet;
251 : : }
252 : :
253 : : }
254 : :
255 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|