Avoid potential negative array index access to cached text.
[LibreOffice.git] / configmgr / source / update.cxx
blob5851a6af05a354c971e387a8c4f1e61f25776eb1
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 <sal/config.h>
22 #include <cassert>
23 #include <set>
25 #include <com/sun/star/configuration/XUpdate.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/uno/Sequence.hxx>
29 #include <com/sun/star/uno/XInterface.hpp>
30 #include <cppuhelper/implbase.hxx>
31 #include <cppuhelper/supportsservice.hxx>
32 #include <cppuhelper/weak.hxx>
33 #include <osl/mutex.hxx>
34 #include <rtl/ref.hxx>
35 #include <rtl/ustring.hxx>
36 #include <sal/types.h>
38 #include "broadcaster.hxx"
39 #include "components.hxx"
40 #include "lock.hxx"
41 #include "modifications.hxx"
42 #include "rootaccess.hxx"
44 namespace configmgr::update {
46 namespace {
48 std::set< OUString > seqToSet(
49 css::uno::Sequence< OUString > const & sequence)
51 return std::set< OUString >( sequence.begin(), sequence.end() );
54 class Service:
55 public cppu::WeakImplHelper< css::configuration::XUpdate, css::lang::XServiceInfo >
57 public:
58 explicit Service(const css::uno::Reference< css::uno::XComponentContext >& context):
59 context_(context)
61 assert(context.is());
62 lock_ = lock();
65 private:
66 Service(const Service&) = delete;
67 Service& operator=(const Service&) = delete;
69 virtual ~Service() override {}
71 virtual void SAL_CALL insertExtensionXcsFile(
72 sal_Bool shared, OUString const & fileUri) override;
74 virtual void SAL_CALL insertExtensionXcuFile(
75 sal_Bool shared, OUString const & fileUri) override;
77 virtual void SAL_CALL removeExtensionXcuFile(OUString const & fileUri) override;
79 virtual void SAL_CALL insertModificationXcuFile(
80 OUString const & fileUri,
81 css::uno::Sequence< OUString > const & includedPaths,
82 css::uno::Sequence< OUString > const & excludedPaths) override;
84 OUString SAL_CALL getImplementationName() override {
85 return "com.sun.star.comp.configuration.Update";
88 sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override {
89 return cppu::supportsService(this, ServiceName);
92 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override {
93 return {"com.sun.star.configuration.Update_Service"};
96 std::shared_ptr<osl::Mutex> lock_;
97 css::uno::Reference< css::uno::XComponentContext > context_;
100 void Service::insertExtensionXcsFile(
101 sal_Bool shared, OUString const & fileUri)
103 osl::MutexGuard g(*lock_);
104 Components::getSingleton(context_).insertExtensionXcsFile(shared, fileUri);
107 void Service::insertExtensionXcuFile(
108 sal_Bool shared, OUString const & fileUri)
110 Broadcaster bc;
112 osl::MutexGuard g(*lock_);
113 Components & components = Components::getSingleton(context_);
114 Modifications mods;
115 components.insertExtensionXcuFile(shared, fileUri, &mods);
116 components.initGlobalBroadcaster(
117 mods, rtl::Reference< RootAccess >(), &bc);
119 bc.send();
122 void Service::removeExtensionXcuFile(OUString const & fileUri)
124 Broadcaster bc;
126 osl::MutexGuard g(*lock_);
127 Components & components = Components::getSingleton(context_);
128 Modifications mods;
129 components.removeExtensionXcuFile(fileUri, &mods);
130 components.initGlobalBroadcaster(
131 mods, rtl::Reference< RootAccess >(), &bc);
133 bc.send();
136 void Service::insertModificationXcuFile(
137 OUString const & fileUri,
138 css::uno::Sequence< OUString > const & includedPaths,
139 css::uno::Sequence< OUString > const & excludedPaths)
141 Broadcaster bc;
143 osl::MutexGuard g(*lock_);
144 Components & components = Components::getSingleton(context_);
145 Modifications mods;
146 components.insertModificationXcuFile(
147 fileUri, seqToSet(includedPaths), seqToSet(excludedPaths), &mods);
148 components.initGlobalBroadcaster(
149 mods, rtl::Reference< RootAccess >(), &bc);
151 bc.send();
157 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
158 com_sun_star_comp_configuration_Update_get_implementation(
159 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
161 return cppu::acquire(new configmgr::update::Service(context));
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */