Avoid potential negative array index access to cached text.
[LibreOffice.git] / remotebridges / source / unourl_resolver / unourl_resolver.cxx
blob6dc273ab365ef01da65ad4cca2d48b43ffbd8a25
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <rtl/malformeduriexception.hxx>
22 #include <com/sun/star/lang/XComponent.hpp>
23 #include <com/sun/star/lang/XServiceInfo.hpp>
24 #include <com/sun/star/bridge/BridgeFactory.hpp>
25 #include <com/sun/star/bridge/XBridgeFactory.hpp>
26 #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
27 #include <com/sun/star/connection/XConnector.hpp>
28 #include <cppuhelper/implbase.hxx>
29 #include <cppuhelper/supportsservice.hxx>
30 #include <cppuhelper/unourl.hxx>
32 using namespace cppu;
33 using namespace com::sun::star::uno;
34 using namespace com::sun::star::lang;
35 using namespace com::sun::star::connection;
36 using namespace com::sun::star::bridge;
38 namespace unourl_resolver
41 namespace {
43 class ResolverImpl : public WeakImplHelper< XServiceInfo, XUnoUrlResolver >
45 Reference< XMultiComponentFactory > _xSMgr;
46 Reference< XComponentContext > _xCtx;
48 public:
49 explicit ResolverImpl( const Reference< XComponentContext > & xSMgr );
51 // XServiceInfo
52 virtual OUString SAL_CALL getImplementationName() override;
53 virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) override;
54 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
56 // XUnoUrlResolver
57 virtual Reference< XInterface > SAL_CALL resolve( const OUString & rUnoUrl ) override;
62 ResolverImpl::ResolverImpl( const Reference< XComponentContext > & xCtx )
63 : _xSMgr( xCtx->getServiceManager() )
64 , _xCtx( xCtx )
67 // XServiceInfo
68 OUString ResolverImpl::getImplementationName()
70 return "com.sun.star.comp.bridge.UnoUrlResolver";
73 sal_Bool ResolverImpl::supportsService( const OUString & rServiceName )
75 return cppu::supportsService(this, rServiceName);
78 Sequence< OUString > ResolverImpl::getSupportedServiceNames()
80 return { "com.sun.star.bridge.UnoUrlResolver" };
83 // XUnoUrlResolver
84 Reference< XInterface > ResolverImpl::resolve( const OUString & rUnoUrl )
86 OUString aProtocolDescr;
87 OUString aConnectDescr;
88 OUString aInstanceName;
89 try
91 cppu::UnoUrl aUrl(rUnoUrl);
92 aProtocolDescr = aUrl.getProtocol().getDescriptor();
93 aConnectDescr = aUrl.getConnection().getDescriptor();
94 aInstanceName = aUrl.getObjectName();
96 catch (const rtl::MalformedUriException & rEx)
98 throw ConnectionSetupException(rEx.getMessage(), nullptr);
101 Reference< XConnector > xConnector(
102 _xSMgr->createInstanceWithContext( "com.sun.star.connection.Connector", _xCtx ),
103 UNO_QUERY_THROW );
104 Reference< XConnection > xConnection( xConnector->connect( aConnectDescr ) );
106 // As soon as singletons are ready, switch to singleton !
107 Reference< XBridgeFactory2 > xBridgeFactory( BridgeFactory::create(_xCtx) );
109 // bridge
110 Reference< XBridge > xBridge( xBridgeFactory->createBridge(
111 OUString(), aProtocolDescr,
112 xConnection, Reference< XInstanceProvider >() ) );
114 Reference< XInterface > xRet( xBridge->getInstance( aInstanceName ) );
116 return xRet;
120 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
121 remotebridges_ResolverImpl_get_implementation(
122 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
124 return cppu::acquire(new ResolverImpl(context));
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */