LibreOffice Module desktop (master) 1
dp_configuration.cxx
Go to the documentation of this file.
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//TODO: Large parts of this file were copied from dp_component.cxx; those parts
21// should be consolidated.
22
23#include <config_extensions.h>
24
25#include <dp_backend.h>
26#if HAVE_FEATURE_EXTENSIONS
27#include <dp_persmap.h>
28#endif
29#include <dp_misc.h>
30#include <dp_ucb.h>
31#include <rtl/string.hxx>
32#include <rtl/strbuf.hxx>
33#include <rtl/ustrbuf.hxx>
36#include <ucbhelper/content.hxx>
39#include <comphelper/lok.hxx>
41#include <svl/inettype.hxx>
42#include <o3tl/string_view.hxx>
43#include <com/sun/star/configuration/Update.hpp>
44#include <com/sun/star/lang/IllegalArgumentException.hpp>
45#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
46#include <deque>
47#include <memory>
48#include <string_view>
49#include <utility>
50
52
53using namespace ::dp_misc;
54using namespace ::com::sun::star;
55using namespace ::com::sun::star::uno;
56using namespace ::com::sun::star::ucb;
57
59namespace {
60
62{
63 class PackageImpl : public ::dp_registry::backend::Package
64 {
65 BackendImpl * getMyBackend() const ;
66
67 const bool m_isSchema;
68
69 // Package
70 virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
71 ::osl::ResettableMutexGuard & guard,
72 ::rtl::Reference<AbortChannel> const & abortChannel,
73 Reference<XCommandEnvironment> const & xCmdEnv ) override;
74 virtual void processPackage_(
75 ::osl::ResettableMutexGuard & guard,
76 bool registerPackage,
77 bool startup,
78 ::rtl::Reference<AbortChannel> const & abortChannel,
79 Reference<XCommandEnvironment> const & xCmdEnv ) override;
80
81 public:
82 PackageImpl(
84 OUString const & url, OUString const & name,
85 Reference<deployment::XPackageTypeInfo> const & xPackageType,
86 bool isSchema, bool bRemoved, OUString const & identifier)
87 : Package( myBackend, url, name, name /* display-name */,
88 xPackageType, bRemoved, identifier),
89 m_isSchema( isSchema )
90 {}
91 };
92 friend class PackageImpl;
93
94 std::deque<OUString> m_xcs_files;
95 std::deque<OUString> m_xcu_files;
96 std::deque<OUString> & getFiles( bool xcs ) {
97 return xcs ? m_xcs_files : m_xcu_files;
98 }
99
102 std::unique_ptr<ConfigurationBackendDb> m_backendDb;
103
104 // PackageRegistryBackend
105 virtual Reference<deployment::XPackage> bindPackage_(
106 OUString const & url, OUString const & mediaType, bool bRemoved,
107 OUString const & identifier,
108 Reference<XCommandEnvironment> const & xCmdEnv ) override;
109
110#if HAVE_FEATURE_EXTENSIONS
111 // for backwards compatibility - nil if no (compatible) back-compat db present
112 std::unique_ptr<PersistentMap> m_registeredPackages;
113#endif
114
115 virtual void SAL_CALL disposing() override;
116
117 const Reference<deployment::XPackageTypeInfo> m_xConfDataTypeInfo;
118 const Reference<deployment::XPackageTypeInfo> m_xConfSchemaTypeInfo;
119 Sequence< Reference<deployment::XPackageTypeInfo> > m_typeInfos;
120
121 void configmgrini_verify_init(
122 Reference<XCommandEnvironment> const & xCmdEnv );
123 void configmgrini_flush( Reference<XCommandEnvironment> const & xCmdEnv );
124
125 /* The parameter isURL is false in the case of adding the conf:ini-entry
126 value from the backend db. This entry already contains the path as it
127 is used in the configmgr.ini.
128 */
129 void addToConfigmgrIni( bool isSchema, bool isURL, OUString const & url,
130 Reference<XCommandEnvironment> const & xCmdEnv );
131#if HAVE_FEATURE_EXTENSIONS
132 bool removeFromConfigmgrIni( bool isSchema, OUString const & url,
133 Reference<XCommandEnvironment> const & xCmdEnv );
134#endif
135 void addDataToDb(OUString const & url, ConfigurationBackendDb::Data const & data);
136 ::std::optional<ConfigurationBackendDb::Data> readDataFromDb(std::u16string_view url);
137 void revokeEntryFromDb(std::u16string_view url);
138 bool hasActiveEntry(std::u16string_view url);
139 bool activateEntry(std::u16string_view url);
140
141public:
142 BackendImpl( Sequence<Any> const & args,
143 Reference<XComponentContext> const & xComponentContext );
144
145 // XServiceInfo
146 virtual OUString SAL_CALL getImplementationName() override;
147 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
148 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
149
150 // XPackageRegistry
151 virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL
152 getSupportedPackageTypes() override;
153 virtual void SAL_CALL packageRemoved(OUString const & url, OUString const & mediaType) override;
154
156};
157
158
159void BackendImpl::disposing()
160{
161 try {
162 configmgrini_flush( Reference<XCommandEnvironment>() );
163
165 }
166 catch (const RuntimeException &) {
167 throw;
168 }
169 catch (const Exception &) {
170 Any exc( ::cppu::getCaughtException() );
171 throw lang::WrappedTargetRuntimeException(
172 "caught unexpected exception while disposing...",
173 static_cast<OWeakObject *>(this), exc );
174 }
175}
176
177
178BackendImpl::BackendImpl(
179 Sequence<Any> const & args,
180 Reference<XComponentContext> const & xComponentContext )
181 : PackageRegistryBackend( args, xComponentContext ),
182 m_configmgrini_inited( false ),
184 m_xConfDataTypeInfo( new Package::TypeInfo(
185 "application/vnd.sun.star.configuration-data",
186 "*.xcu",
187 DpResId(RID_STR_CONF_DATA)
188 ) ),
189 m_xConfSchemaTypeInfo( new Package::TypeInfo(
190 "application/vnd.sun.star.configuration-schema",
191 "*.xcs",
192 DpResId(RID_STR_CONF_SCHEMA)
193 ) ),
195{
196 const Reference<XCommandEnvironment> xCmdEnv;
197
198 if (transientMode())
199 {
200 // TODO
201 }
202 else
203 {
204 OUString dbFile = makeURL(getCachePath(), "backenddb.xml");
205 m_backendDb.reset(
206 new ConfigurationBackendDb(getComponentContext(), dbFile));
207 //clean up data folders which are no longer used.
208 //This must not be done in the same process where the help files
209 //are still registers. Only after revoking and restarting OOo the folders
210 //can be removed. This works now, because the extension manager is a singleton
211 //and the backends are only create once per process.
212 std::vector<OUString> folders = m_backendDb->getAllDataUrls();
213 deleteUnusedFolders(folders);
214
215 configmgrini_verify_init( xCmdEnv );
216
217#if HAVE_FEATURE_EXTENSIONS
218 std::unique_ptr<PersistentMap> pMap;
219 OUString aCompatURL( makeURL( getCachePath(), "registered_packages.pmap" ) );
220
221 // Don't create it if it doesn't exist already
222 if ( ::utl::UCBContentHelper::Exists( expandUnoRcUrl( aCompatURL ) ) )
223 {
224 try
225 {
226 pMap.reset( new PersistentMap( aCompatURL ) );
227 }
228 catch (const Exception &e)
229 {
230 OUString aStr = "Exception loading legacy package database: '" +
231 e.Message +
232 "' - ignoring file, please remove it.\n";
233 dp_misc::writeConsole( aStr );
234 }
235 }
236 m_registeredPackages = std::move(pMap);
237#endif
238 }
239}
240
241// XServiceInfo
242OUString BackendImpl::getImplementationName()
243{
244 return "com.sun.star.comp.deployment.configuration.PackageRegistryBackend";
245}
246
247sal_Bool BackendImpl::supportsService( const OUString& ServiceName )
248{
249 return cppu::supportsService(this, ServiceName);
250}
251
252css::uno::Sequence< OUString > BackendImpl::getSupportedServiceNames()
253{
254 return { BACKEND_SERVICE_NAME };
255}
256
257void BackendImpl::addDataToDb(
258 OUString const & url, ConfigurationBackendDb::Data const & data)
259{
260 if (m_backendDb)
261 m_backendDb->addEntry(url, data);
262}
263
264::std::optional<ConfigurationBackendDb::Data> BackendImpl::readDataFromDb(
265 std::u16string_view url)
266{
267 ::std::optional<ConfigurationBackendDb::Data> data;
268 if (m_backendDb)
269 data = m_backendDb->getEntry(url);
270 return data;
271}
272
273void BackendImpl::revokeEntryFromDb(std::u16string_view url)
274{
275 if (m_backendDb)
276 m_backendDb->revokeEntry(url);
277}
278
279bool BackendImpl::hasActiveEntry(std::u16string_view url)
280{
281 if (m_backendDb)
282 return m_backendDb->hasActiveEntry(url);
283 return false;
284}
285
286bool BackendImpl::activateEntry(std::u16string_view url)
287{
288 if (m_backendDb)
289 return m_backendDb->activateEntry(url);
290 return false;
291}
292
293
294// XPackageRegistry
295
296Sequence< Reference<deployment::XPackageTypeInfo> >
297BackendImpl::getSupportedPackageTypes()
298{
299 return m_typeInfos;
300}
301void BackendImpl::packageRemoved(OUString const & url, OUString const & /*mediaType*/)
302{
303 if (m_backendDb)
304 m_backendDb->removeEntry(url);
305}
306
307// PackageRegistryBackend
308
309Reference<deployment::XPackage> BackendImpl::bindPackage_(
310 OUString const & url, OUString const & mediaType_,
311 bool bRemoved, OUString const & identifier,
312 Reference<XCommandEnvironment> const & xCmdEnv )
313{
314 OUString mediaType( mediaType_ );
315 if (mediaType.isEmpty())
316 {
317 // detect media-type:
318 ::ucbhelper::Content ucbContent;
319 if (create_ucb_content( &ucbContent, url, xCmdEnv ))
320 {
321 const OUString title( StrTitle::getTitle( ucbContent ) );
322 if (title.endsWithIgnoreAsciiCase( ".xcu" )) {
323 mediaType = "application/vnd.sun.star.configuration-data";
324 }
325 if (title.endsWithIgnoreAsciiCase( ".xcs" )) {
326 mediaType = "application/vnd.sun.star.configuration-schema";
327 }
328 }
329 if (mediaType.isEmpty())
330 throw lang::IllegalArgumentException(
331 StrCannotDetectMediaType() + url,
332 static_cast<OWeakObject *>(this), static_cast<sal_Int16>(-1) );
333 }
334
335 OUString type, subType;
337 if (INetContentTypes::parse( mediaType, type, subType, &params ))
338 {
339 if (type.equalsIgnoreAsciiCase("application"))
340 {
341 OUString name;
342 if (!bRemoved)
343 {
344 ::ucbhelper::Content ucbContent( url, xCmdEnv, m_xComponentContext );
345 name = StrTitle::getTitle( ucbContent );
346 }
347
348 if (subType.equalsIgnoreAsciiCase( "vnd.sun.star.configuration-data"))
349 {
350 return new PackageImpl(
351 this, url, name, m_xConfDataTypeInfo, false /* data file */,
352 bRemoved, identifier);
353 }
354 else if (subType.equalsIgnoreAsciiCase( "vnd.sun.star.configuration-schema")) {
355 return new PackageImpl(
356 this, url, name, m_xConfSchemaTypeInfo, true /* schema file */,
357 bRemoved, identifier);
358 }
359 }
360 }
361 throw lang::IllegalArgumentException(
362 StrUnsupportedMediaType() + mediaType,
363 static_cast<OWeakObject *>(this),
364 static_cast<sal_Int16>(-1) );
365}
366
367
368void BackendImpl::configmgrini_verify_init(
369 Reference<XCommandEnvironment> const & xCmdEnv )
370{
371 if (transientMode())
372 return;
373 const ::osl::MutexGuard guard( m_aMutex );
375 return;
376
377 // common rc:
378 ::ucbhelper::Content ucb_content;
380 &ucb_content,
381 makeURL( getCachePath(), "configmgr.ini" ),
382 xCmdEnv, false /* no throw */ ))
383 {
384 OUString line;
385 if (readLine( &line, u"SCHEMA=", ucb_content,
386 RTL_TEXTENCODING_UTF8 ))
387 {
388 sal_Int32 index = RTL_CONSTASCII_LENGTH("SCHEMA=");
389 do {
390 OUString token( o3tl::trim(o3tl::getToken(line, 0, ' ', index )) );
391 if (!token.isEmpty()) {
392 //The file may not exist anymore if a shared or bundled
393 //extension was removed, but it can still be in the configmgrini.
394 //After running XExtensionManager::synchronize, the configmgrini is
395 //cleaned up
396 m_xcs_files.push_back( token );
397 }
398 }
399 while (index >= 0);
400 }
401 if (readLine( &line, u"DATA=", ucb_content,
402 RTL_TEXTENCODING_UTF8 )) {
403 sal_Int32 index = RTL_CONSTASCII_LENGTH("DATA=");
404 do {
405 std::u16string_view token( o3tl::trim(o3tl::getToken(line, 0, ' ', index )) );
406 if (!token.empty())
407 {
408 if (token[ 0 ] == '?')
409 token = token.substr( 1 );
410 //The file may not exist anymore if a shared or bundled
411 //extension was removed, but it can still be in the configmgrini.
412 //After running XExtensionManager::synchronize, the configmgrini is
413 //cleaned up
414 m_xcu_files.push_back( OUString(token) );
415 }
416 }
417 while (index >= 0);
418 }
419 }
422}
423
424
425void BackendImpl::configmgrini_flush(
426 Reference<XCommandEnvironment> const & xCmdEnv )
427{
428 if (transientMode())
429 return;
431 return;
432
433 OStringBuffer buf;
434 if (! m_xcs_files.empty())
435 {
436 auto iPos( m_xcs_files.cbegin() );
437 auto const iEnd( m_xcs_files.cend() );
438 buf.append( "SCHEMA=" );
439 while (iPos != iEnd) {
440 // encoded ASCII file-urls:
441 const OString item(
442 OUStringToOString( *iPos, RTL_TEXTENCODING_ASCII_US ) );
443 buf.append( item );
444 ++iPos;
445 if (iPos != iEnd)
446 buf.append( ' ' );
447 }
448 buf.append(LF);
449 }
450 if (! m_xcu_files.empty())
451 {
452 auto iPos( m_xcu_files.cbegin() );
453 auto const iEnd( m_xcu_files.cend() );
454 buf.append( "DATA=" );
455 while (iPos != iEnd) {
456 // encoded ASCII file-urls:
457 const OString item(
458 OUStringToOString( *iPos, RTL_TEXTENCODING_ASCII_US ) );
459 buf.append( item );
460 ++iPos;
461 if (iPos != iEnd)
462 buf.append( ' ' );
463 }
464 buf.append(LF);
465 }
466
467 // write configmgr.ini:
468 const Reference<io::XInputStream> xData(
469 ::xmlscript::createInputStream(
470 reinterpret_cast<sal_Int8 const *>(buf.getStr()),
471 buf.getLength() ) );
472 ::ucbhelper::Content ucb_content(
473 makeURL( getCachePath(), "configmgr.ini" ), xCmdEnv, m_xComponentContext );
474 ucb_content.writeStream( xData, true /* replace existing */ );
475
477}
478
479
480void BackendImpl::addToConfigmgrIni( bool isSchema, bool isURL, OUString const & url_,
481 Reference<XCommandEnvironment> const & xCmdEnv )
482{
483 const OUString rcterm( isURL ? dp_misc::makeRcTerm(url_) : url_ );
484 const ::osl::MutexGuard guard( m_aMutex );
485 configmgrini_verify_init( xCmdEnv );
486 std::deque<OUString> & rSet = getFiles(isSchema);
487 if (std::find( rSet.begin(), rSet.end(), rcterm ) == rSet.end()) {
488 rSet.push_front( rcterm ); // prepend to list, thus overriding
489 // write immediately:
491 configmgrini_flush( xCmdEnv );
492 }
493}
494
495#if HAVE_FEATURE_EXTENSIONS
496bool BackendImpl::removeFromConfigmgrIni(
497 bool isSchema, OUString const & url_,
498 Reference<XCommandEnvironment> const & xCmdEnv )
499{
500 const OUString rcterm( dp_misc::makeRcTerm(url_) );
501 const ::osl::MutexGuard guard( m_aMutex );
502 configmgrini_verify_init( xCmdEnv );
503 std::deque<OUString> & rSet = getFiles(isSchema);
504 auto i(std::find(rSet.begin(), rSet.end(), rcterm));
505 if (i == rSet.end() && !isSchema)
506 {
507 //in case the xcu contained %origin% then the configmr.ini contains the
508 //url to the file in the user installation (e.g. $BUNDLED_EXTENSIONS_USER)
509 //However, m_url (getURL()) contains the URL for the file in the actual
510 //extension installation.
511 ::std::optional<ConfigurationBackendDb::Data> data = readDataFromDb(url_);
512 if (data)
513 i = std::find(rSet.begin(), rSet.end(), data->iniEntry);
514 }
515 if (i == rSet.end()) {
516 return false;
517 }
518 rSet.erase(i);
519 // write immediately:
521 configmgrini_flush( xCmdEnv );
522 return true;
523}
524#endif
525
526// Package
527
528
529BackendImpl * BackendImpl::PackageImpl::getMyBackend() const
530{
531 BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get());
532 if (nullptr == pBackend)
533 {
534 //May throw a DisposedException
535 check();
536 //We should never get here...
537 throw RuntimeException(
538 "Failed to get the BackendImpl",
539 static_cast<OWeakObject*>(const_cast<PackageImpl *>(this)));
540 }
541 return pBackend;
542}
543
544beans::Optional< beans::Ambiguous<sal_Bool> >
545BackendImpl::PackageImpl::isRegistered_(
546 ::osl::ResettableMutexGuard &,
548 Reference<XCommandEnvironment> const & )
549{
550 BackendImpl * that = getMyBackend();
551
552 bool bReg = false;
553 if (that->hasActiveEntry(getURL()))
554 bReg = true;
555
556#if HAVE_FEATURE_EXTENSIONS
557 const OUString url(getURL());
558 if (!bReg && that->m_registeredPackages)
559 {
560 // fallback for user extension registered in berkeley DB
561 bReg = that->m_registeredPackages->has(
562 OUStringToOString( url, RTL_TEXTENCODING_UTF8 ));
563 }
564#endif
565 return beans::Optional< beans::Ambiguous<sal_Bool> >(
566 true, beans::Ambiguous<sal_Bool>( bReg, false ) );
567}
568
569
570OUString replaceOrigin(
571 OUString const & url, std::u16string_view destFolder, Reference< XCommandEnvironment > const & xCmdEnv, Reference< XComponentContext > const & xContext, bool & out_replaced)
572{
573 // looking for %origin%:
574 ::ucbhelper::Content ucb_content( url, xCmdEnv, xContext );
575 std::vector<sal_Int8> bytes( readFile( ucb_content ) );
576 std::vector<sal_Int8> filtered( bytes.size() * 2 );
577 bool use_filtered = false;
578 OString origin;
579 char const * pBytes = reinterpret_cast<char const *>(
580 bytes.data());
581 std::size_t nBytes = bytes.size();
582 size_t write_pos = 0;
583 while (nBytes > 0)
584 {
585 sal_Int32 index = rtl_str_indexOfChar_WithLength( pBytes, nBytes, '%' );
586 if (index < 0) {
587 if (! use_filtered) // opt
588 break;
589 index = nBytes;
590 }
591
592 if ((write_pos + index) > filtered.size())
593 filtered.resize( (filtered.size() + index) * 2 );
594 memcpy( filtered.data() + write_pos, pBytes, index );
595 write_pos += index;
596 pBytes += index;
597 nBytes -= index;
598 if (nBytes == 0)
599 break;
600
601 // consume %:
602 ++pBytes;
603 --nBytes;
604 char const * pAdd = "%";
605 sal_Int32 nAdd = 1;
606 if (nBytes > 1 && pBytes[ 0 ] == '%')
607 {
608 // %% => %
609 ++pBytes;
610 --nBytes;
611 use_filtered = true;
612 }
613 else if (rtl_str_shortenedCompare_WithLength(
614 pBytes, nBytes,
615 "origin%",
616 RTL_CONSTASCII_LENGTH("origin%"),
617 RTL_CONSTASCII_LENGTH("origin%")) == 0)
618 {
619 if (origin.isEmpty()) {
620 // encode only once
621 origin = OUStringToOString(
622 comphelper::string::encodeForXml( url.subView( 0, url.lastIndexOf( '/' ) ) ),
623 // xxx todo: encode always for UTF-8? => lookup doc-header?
624 RTL_TEXTENCODING_UTF8 );
625 }
626 pAdd = origin.getStr();
627 nAdd = origin.getLength();
628 pBytes += RTL_CONSTASCII_LENGTH("origin%");
629 nBytes -= RTL_CONSTASCII_LENGTH("origin%");
630 use_filtered = true;
631 }
632 if ((write_pos + nAdd) > filtered.size())
633 filtered.resize( (filtered.size() + nAdd) * 2 );
634 memcpy( filtered.data() + write_pos, pAdd, nAdd );
635 write_pos += nAdd;
636 }
637 if (!use_filtered)
638 return url;
639 if (write_pos < filtered.size())
640 filtered.resize( write_pos );
641 OUString newUrl(url);
642 if (!destFolder.empty())
643 {
644 //get the file name of the xcu and add it to the url of the temporary folder
645 sal_Int32 i = url.lastIndexOf('/');
646 newUrl = OUString::Concat(destFolder) + url.subView(i);
647 }
648
649 ucbhelper::Content(newUrl, xCmdEnv, xContext).writeStream(
650 xmlscript::createInputStream(std::move(filtered)), true);
651 out_replaced = true;
652 return newUrl;
653}
654
655
656void BackendImpl::PackageImpl::processPackage_(
657 ::osl::ResettableMutexGuard &,
658 bool doRegisterPackage,
659 bool startup,
661 Reference<XCommandEnvironment> const & xCmdEnv )
662{
663 BackendImpl * that = getMyBackend();
664 OUString url( getURL() );
665
666 if (doRegisterPackage)
667 {
668 if (getMyBackend()->activateEntry(getURL()))
669 {
670 ::std::optional<ConfigurationBackendDb::Data> data = that->readDataFromDb(url);
671 OSL_ASSERT(data);
672 that->addToConfigmgrIni( m_isSchema, false, data->iniEntry, xCmdEnv );
673 }
674 else
675 {
676 ConfigurationBackendDb::Data data;
677 if (!m_isSchema)
678 {
679 const OUString sModFolder = that->createFolder(xCmdEnv);
680 bool out_replaced = false;
681 url = replaceOrigin(url, sModFolder, xCmdEnv, that->getComponentContext(), out_replaced);
682 if (out_replaced)
683 data.dataUrl = sModFolder;
684 else
685 deleteTempFolder(sModFolder);
686 }
687 //No need for live-deployment for bundled extension, because OOo
688 //restarts after installation
689 if ((that->m_eContext != Context::Bundled && !startup)
691 {
692 if (m_isSchema)
693 {
694 css::configuration::Update::get(
695 that->m_xComponentContext)->insertExtensionXcsFile(
696 that->m_eContext == Context::Shared, expandUnoRcUrl(url));
697 }
698 else
699 {
700 css::configuration::Update::get(
701 that->m_xComponentContext)->insertExtensionXcuFile(
702 that->m_eContext == Context::Shared, expandUnoRcUrl(url));
703 }
704 }
705 that->addToConfigmgrIni( m_isSchema, true, url, xCmdEnv );
706 data.iniEntry = dp_misc::makeRcTerm(url);
707 that->addDataToDb(getURL(), data);
708 }
709 }
710 else // revoke
711 {
712#if HAVE_FEATURE_EXTENSIONS
713 if (!that->removeFromConfigmgrIni(m_isSchema, url, xCmdEnv) &&
714 that->m_registeredPackages) {
715 // Obsolete package database handling - should be removed for LibreOffice 4.0
716 t_string2string_map entries(
717 that->m_registeredPackages->getEntries());
718 for (auto const& entry : entries)
719 {
720 //If the xcu file was installed before the configmgr was changed
721 //to use the configmgr.ini, one needed to rebuild to whole directory
722 //structure containing the xcu, xcs files from all extensions. Now,
723 //we just add all other xcu/xcs files to the configmgr.ini instead of
724 //rebuilding the directory structure.
725 OUString url2(
726 OStringToOUString(entry.first, RTL_TEXTENCODING_UTF8));
727 if (url2 != url) {
728 bool schema = entry.second.equalsIgnoreAsciiCase(
729 "vnd.sun.star.configuration-schema");
730 OUString url_replaced(url2);
731 ConfigurationBackendDb::Data data;
732 if (!schema)
733 {
734 const OUString sModFolder = that->createFolder(xCmdEnv);
735 bool out_replaced = false;
736 url_replaced = replaceOrigin(
737 url2, sModFolder, xCmdEnv, that->getComponentContext(), out_replaced);
738 if (out_replaced)
739 data.dataUrl = sModFolder;
740 else
741 deleteTempFolder(sModFolder);
742 }
743 that->addToConfigmgrIni(schema, true, url_replaced, xCmdEnv);
744 data.iniEntry = dp_misc::makeRcTerm(url_replaced);
745 that->addDataToDb(url2, data);
746 }
747 that->m_registeredPackages->erase(entry.first);
748 }
749 try
750 {
752 makeURL( that->getCachePath(), "registry" ),
753 xCmdEnv, that->getComponentContext() ).executeCommand(
754 "delete", Any( true /* delete physically */ ) );
755 }
756 catch(const Exception&)
757 {
758 OSL_ASSERT(false);
759 }
760 }
761#endif
762 ::std::optional<ConfigurationBackendDb::Data> data = that->readDataFromDb(url);
763 //If an xcu file was life deployed then always a data entry is written.
764 //If the xcu file was already in the configmr.ini then there is also
765 //a data entry
766 if (!m_isSchema && data)
767 {
768 css::configuration::Update::get(
769 that->m_xComponentContext)->removeExtensionXcuFile(expandUnoRcTerm(data->iniEntry));
770 }
771 that->revokeEntryFromDb(url);
772 }
773}
774
775} // anon namespace
776
777} // namespace dp_registry
778
779extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
781 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
782{
783 return cppu::acquire(new dp_registry::backend::configuration::BackendImpl(args, context));
784}
785
786/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool parse(OUString const &rMediaType, OUString &rType, OUString &rSubType, INetContentTypeParameterList *pParameters=nullptr)
virtual void SAL_CALL disposing() override
Definition: dp_backend.cxx:116
css::uno::Any executeCommand(const OUString &rCommandName, const css::uno::Any &rCommandArgument)
void writeStream(const css::uno::Reference< css::io::XInputStream > &rStream, bool bReplaceExisting)
bool m_configmgrini_inited
Sequence< Reference< deployment::XPackageTypeInfo > > m_typeInfos
const Reference< deployment::XPackageTypeInfo > m_xConfSchemaTypeInfo
std::deque< OUString > m_xcu_files
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_deployment_configuration_PackageRegistryBackend_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
const bool m_isSchema
std::unique_ptr< ConfigurationBackendDb > m_backendDb
bool m_configmgrini_modified
const Reference< deployment::XPackageTypeInfo > m_xConfDataTypeInfo
std::deque< OUString > m_xcs_files
Reference< XComponentContext > const m_xComponentContext
OUString DpResId(TranslateId aId)
Definition: dp_misc.cxx:555
const char * name
std::unordered_map< OString, INetContentTypeParameter > INetContentTypeParameterList
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:2642
aStr
OUString encodeForXml(std::u16string_view rStr)
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
OUString makeURL(std::u16string_view baseURL, OUString const &relPath_)
appends a relative path to a url.
Definition: dp_misc.cxx:253
OUString makeRcTerm(OUString const &url)
Definition: dp_misc.cxx:301
OUString expandUnoRcUrl(OUString const &url)
Definition: dp_misc.cxx:315
std::unordered_map< OString, OString > t_string2string_map
Definition: dp_persmap.h:28
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool create_ucb_content(::ucbhelper::Content *ucb_content, OUString const &url, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv, bool throw_exc=true)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool readLine(OUString *res, std::u16string_view startingWith, ::ucbhelper::Content &ucb_content, rtl_TextEncoding textenc)
Definition: dp_ucb.cxx:200
OUString expandUnoRcTerm(OUString const &term_)
Definition: dp_misc.cxx:294
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC std::vector< sal_Int8 > readFile(::ucbhelper::Content &ucb_content)
Definition: dp_ucb.cxx:187
void writeConsole(std::u16string_view sText)
writes the argument string to the console.
Definition: dp_misc.cxx:463
const char LF
Definition: dp_misc.h:35
constexpr OUStringLiteral BACKEND_SERVICE_NAME
Definition: dp_backend.h:41
int i
line
index
def check(model)
std::basic_string_view< charT, traits > trim(std::basic_string_view< charT, traits > str)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
args
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
std::vector< sal_uInt8 > bytes
Reference< io::XInputStream > createInputStream(std::vector< sal_Int8 > &&rInData)
static SfxItemSet & rSet
::boost::spirit::classic::rule< ScannerT > identifier
unsigned char sal_Bool
signed char sal_Int8
ResultType type