27#include <rtl/string.hxx>
28#include <rtl/strbuf.hxx>
29#include <rtl/ustrbuf.hxx>
41#include <com/sun/star/beans/NamedValue.hpp>
42#include <com/sun/star/deployment/DeploymentException.hpp>
43#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
44#include <com/sun/star/container/XNameContainer.hpp>
45#include <com/sun/star/container/XSet.hpp>
46#include <com/sun/star/registry/XSimpleRegistry.hpp>
47#include <com/sun/star/registry/XImplementationRegistration.hpp>
48#include <com/sun/star/loader/XImplementationLoader.hpp>
49#include <com/sun/star/io/XInputStream.hpp>
50#include <com/sun/star/ucb/NameClash.hpp>
51#include <com/sun/star/util/theMacroExpander.hpp>
56#include <unordered_map>
71std::vector<OUString> getCmdBootstrapVariables()
73 std::vector<OUString> ret;
74 sal_uInt32
count = osl_getCommandArgCount();
75 for (sal_uInt32 i = 0;
i <
count;
i++)
78 osl_getCommandArg(i, &arg.pData);
79 if (arg.startsWith(
"-env:"))
85bool jarManifestHeaderPresent(
86 OUString
const & url, std::u16string_view name,
87 Reference<XCommandEnvironment>
const & xCmdEnv )
89 OUString buf =
"vnd.sun.star.zip://"
91 url, rtl_UriCharClassRegName, rtl_UriEncodeIgnoreEscapes,
92 RTL_TEXTENCODING_UTF8 )
93 +
"/META-INF/MANIFEST.MF";
98 &manifestContent, buf, xCmdEnv,
100 &&
readLine( &line, name, manifestContent, RTL_TEXTENCODING_ASCII_US );
108 BackendImpl * getMyBackend()
const;
112 enum class Reg { Uninit,
Void, Registered, NotRegistered, MaybeRegistered };
115 void getComponentInfo(
116 ComponentBackendDb::Data * data,
117 std::vector< css::uno::Reference< css::uno::XInterface > > *
119 Reference<XComponentContext>
const &
xContext );
121 void componentLiveInsertion(
122 ComponentBackendDb::Data
const & data,
123 std::vector< css::uno::Reference< css::uno::XInterface > >
const &
126 void componentLiveRemoval(ComponentBackendDb::Data
const & data);
129 virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
130 ::osl::ResettableMutexGuard & guard,
132 Reference<XCommandEnvironment>
const & xCmdEnv )
override;
133 virtual void processPackage_(
134 ::osl::ResettableMutexGuard & guard,
135 bool registerPackage,
138 Reference<XCommandEnvironment>
const & xCmdEnv )
override;
140 Reference<registry::XSimpleRegistry> getRDB()
const;
143 ComponentPackageImpl(
145 OUString
const & url, OUString
const & name,
146 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
147 OUString loader,
bool bRemoved,
148 OUString
const & identifier);
150 friend class ComponentPackageImpl;
154 BackendImpl * getMyBackend()
const;
157 virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
158 ::osl::ResettableMutexGuard & guard,
160 Reference<XCommandEnvironment>
const & xCmdEnv )
override;
161 virtual void processPackage_(
162 ::osl::ResettableMutexGuard & guard,
163 bool registerPackage,
166 Reference<XCommandEnvironment>
const & xCmdEnv )
override;
168 ComponentsPackageImpl(
170 OUString
const & url, OUString
const & name,
171 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
172 bool bRemoved, OUString
const & identifier);
174 friend class ComponentsPackageImpl;
178 BackendImpl * getMyBackend()
const;
183 virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
184 ::osl::ResettableMutexGuard & guard,
186 Reference<XCommandEnvironment>
const & xCmdEnv )
override;
187 virtual void processPackage_(
188 ::osl::ResettableMutexGuard & guard,
189 bool registerPackage,
192 Reference<XCommandEnvironment>
const & xCmdEnv )
override;
195 TypelibraryPackageImpl(
197 OUString
const & url, OUString
const & name,
198 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
199 bool jarFile,
bool bRemoved,
200 OUString
const & identifier);
202 friend class TypelibraryPackageImpl;
211 OtherPlatformPackageImpl(
213 OUString
const & url, OUString
const & name,
214 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
215 bool bRemoved, OUString
const & identifier, OUString platform);
218 BackendImpl * getMyBackend()
const;
220 Reference<registry::XSimpleRegistry> impl_openRDB()
const;
221 Reference<XInterface> impl_createInstance(OUString
const& rService)
const;
224 virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
225 ::osl::ResettableMutexGuard & guard,
227 Reference<XCommandEnvironment>
const & xCmdEnv )
override;
228 virtual void processPackage_(
229 ::osl::ResettableMutexGuard & guard,
230 bool registerPackage,
233 Reference<XCommandEnvironment>
const & xCmdEnv )
override;
238 friend class OtherPlatformPackageImpl;
244 enum RcItem { RCITEM_JAR_TYPELIB, RCITEM_RDB_TYPELIB, RCITEM_COMPONENTS };
246 std::deque<OUString> & getRcItemList( RcItem kind ) {
249 case RCITEM_JAR_TYPELIB:
251 case RCITEM_RDB_TYPELIB:
262 typedef std::unordered_map< OUString, Reference<XInterface> > t_string2object;
266 virtual Reference<deployment::XPackage> bindPackage_(
267 OUString
const & url, OUString
const & mediaType,
268 bool bRemoved, OUString
const & identifier,
269 Reference<XCommandEnvironment>
const & xCmdEnv )
override;
271 virtual void SAL_CALL disposing()
override;
290 void addDataToDb(OUString
const & url, ComponentBackendDb::Data
const & data);
291 ComponentBackendDb::Data readDataFromDb(std::u16string_view url);
292 void revokeEntryFromDb(std::u16string_view url);
297 void unorc_verify_init( Reference<XCommandEnvironment>
const & xCmdEnv );
298 void unorc_flush( Reference<XCommandEnvironment>
const & xCmdEnv );
300 Reference<XInterface> getObject( OUString
const &
id );
301 Reference<XInterface> insertObject(
302 OUString
const &
id, Reference<XInterface>
const & xObject );
303 void releaseObject( OUString
const &
id );
305 void addToUnoRc( RcItem kind, OUString
const & url,
306 Reference<XCommandEnvironment>
const & xCmdEnv );
307 void removeFromUnoRc( RcItem kind, OUString
const & url,
308 Reference<XCommandEnvironment>
const & xCmdEnv );
309 bool hasInUnoRc( RcItem kind, OUString
const & url );
311 css::uno::Reference< css::uno::XComponentContext > getRootContext()
const;
314 BackendImpl( Sequence<Any>
const & args,
315 Reference<XComponentContext>
const & xComponentContext );
323 virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL
324 getSupportedPackageTypes()
override;
326 virtual void SAL_CALL packageRemoved(OUString
const & url, OUString
const & mediaType)
override;
331 void initServiceRdbFiles();
335BackendImpl::ComponentPackageImpl::ComponentPackageImpl(
337 OUString
const & url, OUString
const & name,
338 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
339 OUString loader,
bool bRemoved,
340 OUString
const & identifier)
347Reference<registry::XSimpleRegistry>
348BackendImpl::ComponentPackageImpl::getRDB()
const
350 BackendImpl * that = getMyBackend();
358 const ::osl::MutexGuard guard( m_aMutex );
359 if (!that->bSwitchedRdbFiles)
361 that->bSwitchedRdbFiles =
true;
362 that->initServiceRdbFiles();
365 if (
m_loader ==
"com.sun.star.loader.SharedLibrary" )
366 return that->m_xNativeRDB;
368 return that->m_xCommonRDB;
371BackendImpl * BackendImpl::ComponentPackageImpl::getMyBackend()
const
373 BackendImpl * pBackend =
static_cast<BackendImpl *
>(m_myBackend.get());
374 if (
nullptr == pBackend)
380 "Failed to get the BackendImpl",
381 static_cast<OWeakObject*
>(
const_cast<ComponentPackageImpl *
>(
this)));
387void BackendImpl::disposing()
399 unorc_flush( Reference<XCommandEnvironment>() );
401 PackageRegistryBackend::disposing();
406 catch (
const Exception &) {
407 Any exc( ::cppu::getCaughtException() );
408 throw lang::WrappedTargetRuntimeException(
409 "caught unexpected exception while disposing...",
410 static_cast<OWeakObject *
>(
this), exc );
415void BackendImpl::initServiceRdbFiles()
417 const Reference<XCommandEnvironment> xCmdEnv;
429 if (oldRDB.
get().is())
431 cacheDir.transferContent(
446 if (oldRDB.
get().is())
448 cacheDir.transferContent(
455 unorc_flush( Reference<XCommandEnvironment>() );
462 ->createInstanceWithContext(
463 "com.sun.star.registry.SimpleRegistry",
472 ->createInstanceWithContext(
473 "com.sun.star.registry.SimpleRegistry",
481BackendImpl::BackendImpl(
482 Sequence<Any>
const & args,
483 Reference<XComponentContext>
const & xComponentContext )
484 : PackageRegistryBackend(
args, xComponentContext ),
489 "application/vnd.sun.star.uno-component;type=native;platform=" +
495 "application/vnd.sun.star.uno-component;type=Java",
497 DpResId(RID_STR_JAVA_COMPONENT)
500 "application/vnd.sun.star.uno-component;type=Python",
503 RID_STR_PYTHON_COMPONENT)
506 "application/vnd.sun.star.uno-components",
511 "application/vnd.sun.star.uno-typelibrary;type=RDB",
516 "application/vnd.sun.star.uno-typelibrary;type=Java",
523 const Reference<XCommandEnvironment> xCmdEnv;
530 xComponentContext->getServiceManager()->createInstanceWithContext(
531 "com.sun.star.registry.SimpleRegistry",
532 xComponentContext ), UNO_QUERY_THROW );
536 xComponentContext->getServiceManager()->createInstanceWithContext(
537 "com.sun.star.registry.SimpleRegistry",
538 xComponentContext ), UNO_QUERY_THROW );
544 unorc_verify_init( xCmdEnv );
545 OUString dbFile =
makeURL(getCachePath(),
"backenddb.xml");
552OUString BackendImpl::getImplementationName()
554 return "com.sun.star.comp.deployment.component.PackageRegistryBackend";
557sal_Bool BackendImpl::supportsService(
const OUString& ServiceName )
562css::uno::Sequence< OUString > BackendImpl::getSupportedServiceNames()
567void BackendImpl::addDataToDb(
568 OUString
const & url, ComponentBackendDb::Data
const & data)
574ComponentBackendDb::Data BackendImpl::readDataFromDb(std::u16string_view url)
576 ComponentBackendDb::Data data;
582void BackendImpl::revokeEntryFromDb(std::u16string_view url)
590Sequence< Reference<deployment::XPackageTypeInfo> >
591BackendImpl::getSupportedPackageTypes()
596void BackendImpl::packageRemoved(OUString
const & url, OUString
const & )
604Reference<deployment::XPackage> BackendImpl::bindPackage_(
605 OUString
const & url, OUString
const & mediaType_,
606 bool bRemoved, OUString
const & identifier,
607 Reference<XCommandEnvironment>
const & xCmdEnv )
609 OUString mediaType(mediaType_);
610 if ( mediaType.isEmpty() || mediaType ==
"application/vnd.sun.star.uno-component" || mediaType ==
"application/vnd.sun.star.uno-typelibrary" )
615 const OUString title( StrTitle::getTitle( ucbContent ) );
616 if (title.endsWithIgnoreAsciiCase(SAL_DLLEXTENSION))
618 mediaType =
"application/vnd.sun.star.uno-component;type=native;platform=" +
621 else if (title.endsWithIgnoreAsciiCase(
".jar"))
623 if (jarManifestHeaderPresent(
624 url, u
"RegistrationClassName", xCmdEnv ))
625 mediaType =
"application/vnd.sun.star.uno-component;type=Java";
626 if (mediaType.isEmpty())
627 mediaType =
"application/vnd.sun.star.uno-typelibrary;type=Java";
629 else if (title.endsWithIgnoreAsciiCase(
".py"))
630 mediaType =
"application/vnd.sun.star.uno-component;type=Python";
631 else if (title.endsWithIgnoreAsciiCase(
".rdb"))
632 mediaType =
"application/vnd.sun.star.uno-typelibrary;type=RDB";
634 if (mediaType.isEmpty())
635 throw lang::IllegalArgumentException(
636 StrCannotDetectMediaType() + url,
637 static_cast<OWeakObject *
>(
this),
static_cast<sal_Int16
>(-1) );
640 OUString
type, subType;
644 if (
type.equalsIgnoreAsciiCase(
"application"))
650 name = StrTitle::getTitle( ucbContent );
653 if (subType.equalsIgnoreAsciiCase(
"vnd.sun.star.uno-component"))
657 auto const iter = params.find(OString(
"platform"));
658 bool bPlatformFits(iter == params.end());
662 aPlatform = iter->second.m_sValue;
667 if (bPlatformFits || bRemoved) {
668 auto const iterType = params.find(OString(
"type"));
669 if (iterType != params.end())
671 OUString
const &
value = iterType->second.m_sValue;
672 if (
value.equalsIgnoreAsciiCase(
"native")) {
674 return new BackendImpl::ComponentPackageImpl(
676 "com.sun.star.loader.SharedLibrary",
677 bRemoved, identifier);
679 return new BackendImpl::OtherPlatformPackageImpl(
681 bRemoved, identifier, aPlatform);
683 if (
value.equalsIgnoreAsciiCase(
"Java")) {
684 return new BackendImpl::ComponentPackageImpl(
686 "com.sun.star.loader.Java2",
687 bRemoved, identifier);
689 if (
value.equalsIgnoreAsciiCase(
"Python")) {
690 return new BackendImpl::ComponentPackageImpl(
692 "com.sun.star.loader.Python",
693 bRemoved, identifier);
698 else if (subType.equalsIgnoreAsciiCase(
"vnd.sun.star.uno-components"))
700 auto const iter = params.find(OString(
"platform"));
701 if (iter == params.end() ||
platform_fits(iter->second.m_sValue)) {
702 return new BackendImpl::ComponentsPackageImpl(
707 else if (subType.equalsIgnoreAsciiCase(
"vnd.sun.star.uno-typelibrary"))
709 auto const iter = params.find(OString(
"type"));
710 if (iter != params.end()) {
711 OUString
const &
value = iter->second.m_sValue;
712 if (
value.equalsIgnoreAsciiCase(
"RDB"))
714 return new BackendImpl::TypelibraryPackageImpl(
716 false , bRemoved, identifier);
718 if (
value.equalsIgnoreAsciiCase(
"Java")) {
719 return new BackendImpl::TypelibraryPackageImpl(
721 true , bRemoved, identifier);
727 throw lang::IllegalArgumentException(
728 StrUnsupportedMediaType() + mediaType,
729 static_cast<OWeakObject *
>(
this),
730 static_cast<sal_Int16
>(-1) );
734void BackendImpl::unorc_verify_init(
735 Reference<XCommandEnvironment>
const & xCmdEnv )
739 const ::osl::MutexGuard guard( m_aMutex );
747 makeURL( getCachePath(),
"unorc" ),
751 if (
readLine( &line, u
"UNO_JAVA_CLASSPATH=", ucb_content,
752 RTL_TEXTENCODING_UTF8 ))
754 sal_Int32
index =
sizeof (
"UNO_JAVA_CLASSPATH=") - 1;
757 if (!token.isEmpty())
773 if (
readLine( &line, u
"UNO_TYPES=", ucb_content,
774 RTL_TEXTENCODING_UTF8 )) {
775 sal_Int32
index =
sizeof (
"UNO_TYPES=") - 1;
778 if (!token.isEmpty())
780 if (token[ 0 ] ==
'?')
781 token = token.copy( 1 );
796 if (
readLine( &line, u
"UNO_SERVICES=", ucb_content,
797 RTL_TEXTENCODING_UTF8 ))
808 for (sal_Int32 i = RTL_CONSTASCII_LENGTH(
"UNO_SERVICES=");
811 OUString token(
line.getToken(0,
' ', i));
812 if (!token.isEmpty())
814 if (state == 1 && token.match(
"?$ORIGIN/"))
817 RTL_CONSTASCII_LENGTH(
"?$ORIGIN/"));
820 else if ( state <= 2 && token ==
"${$ORIGIN/${_OS}_${_ARCH}rc:UNO_SERVICES}" )
828 token = token.copy(1);
842 if (
readLine( &line, u
"UNO_SERVICES=", ucb_content,
843 RTL_TEXTENCODING_UTF8 )) {
845 sizeof (
"UNO_SERVICES=?$ORIGIN/") - 1 );
854void BackendImpl::unorc_flush( Reference<XCommandEnvironment>
const & xCmdEnv )
863 OStringBuffer buf(
"ORIGIN=" + osOrigin + OStringChar(
LF));
869 buf.append(
"UNO_JAVA_CLASSPATH=" );
870 while (iPos != iEnd) {
885 buf.append(
"UNO_TYPES=" );
886 while (iPos != iEnd) {
905 if (!sCommonRDB.isEmpty() || !sNativeRDB.isEmpty() ||
908 buf.append(
"UNO_SERVICES=" );
910 if (!sCommonRDB.isEmpty())
912 buf.append(
"?$ORIGIN/"
916 if (!sNativeRDB.isEmpty())
922 buf.append(
"${$ORIGIN/${_OS}_${_ARCH}rc:UNO_SERVICES}" );
930 "UNO_SERVICES=?$ORIGIN/" +
934 const Reference<io::XInputStream> xData(
935 ::xmlscript::createInputStream(
936 reinterpret_cast<sal_Int8 const *
>(buf2.getStr()),
937 buf2.getLength() ) );
956 const Reference<io::XInputStream> xData(
957 ::xmlscript::createInputStream(
958 reinterpret_cast<sal_Int8 const *
>(buf.getStr()),
968void BackendImpl::addToUnoRc( RcItem kind, OUString
const & url_,
969 Reference<XCommandEnvironment>
const & xCmdEnv )
972 const ::osl::MutexGuard guard( m_aMutex );
973 unorc_verify_init( xCmdEnv );
974 std::deque<OUString> &
rSet = getRcItemList(kind);
975 if (std::find(
rSet.begin(),
rSet.end(), rcterm ) ==
rSet.end()) {
976 rSet.push_front( rcterm );
979 unorc_flush( xCmdEnv );
984void BackendImpl::removeFromUnoRc(
985 RcItem kind, OUString
const & url_,
986 Reference<XCommandEnvironment>
const & xCmdEnv )
989 const ::osl::MutexGuard guard( m_aMutex );
990 unorc_verify_init( xCmdEnv );
991 std::deque<OUString> & aRcItemList = getRcItemList(kind);
992 aRcItemList.erase(std::remove(aRcItemList.begin(), aRcItemList.end(), rcterm), aRcItemList.end());
995 unorc_flush( xCmdEnv );
999bool BackendImpl::hasInUnoRc(
1000 RcItem kind, OUString
const & url_ )
1003 const ::osl::MutexGuard guard( m_aMutex );
1004 std::deque<OUString>
const &
rSet = getRcItemList(kind);
1005 return std::find(
rSet.begin(),
rSet.end(), rcterm ) !=
rSet.end();
1008css::uno::Reference< css::uno::XComponentContext > BackendImpl::getRootContext()
1011 css::uno::Reference< css::uno::XComponentContext > rootContext(
1013 css::uno::UNO_QUERY);
1018void BackendImpl::releaseObject( OUString
const &
id )
1020 const ::osl::MutexGuard guard( m_aMutex );
1025Reference<XInterface> BackendImpl::getObject( OUString
const &
id )
1027 const ::osl::MutexGuard guard( m_aMutex );
1028 const t_string2object::const_iterator iFind(
m_backendObjects.find(
id ) );
1030 return Reference<XInterface>();
1032 return iFind->second;
1036Reference<XInterface> BackendImpl::insertObject(
1037 OUString
const &
id, Reference<XInterface>
const & xObject )
1039 const ::osl::MutexGuard guard( m_aMutex );
1040 const std::pair<t_string2object::iterator, bool> insertion(
1042 return insertion.first->second;
1046Reference<XComponentContext> raise_uno_process(
1047 Reference<XComponentContext>
const &
xContext,
1054 const OUString connectStr =
"uno:pipe,name=" +
generateRandomPipeId() +
";urp;uno.ComponentContext";
1060 std::vector<OUString>
args{
1061#if OSL_DEBUG_LEVEL == 0
1068 "-env:INIFILENAME=" };
1071 std::vector<OUString> bootvars = getCmdBootstrapVariables();
1072 args.insert(
args.end(), bootvars.begin(), bootvars.end());
1074 oslProcess hProcess;
1080 OUStringBuffer sMsg =
"error starting process: " + url;
1081 for(
const auto& arg : args)
1082 sMsg.append(
" " + arg);
1083 throw uno::RuntimeException(sMsg.makeStringAndClear());
1086 return Reference<XComponentContext>(
1092 if ( osl_terminateProcess( hProcess ) != osl_Process_E_None )
1094 OSL_ASSERT(
false );
1100void extractComponentData(
1101 css::uno::Reference< css::uno::XComponentContext >
const & context,
1102 css::uno::Reference< css::registry::XRegistryKey >
const & registry,
1103 ComponentBackendDb::Data * data,
1104 std::vector< css::uno::Reference< css::uno::XInterface > > * factories,
1105 css::uno::Reference< css::loader::XImplementationLoader >
const &
1107 OUString
const & componentUrl)
1110 context.is() && registry.is() && data !=
nullptr && componentLoader.is());
1111 OUString registryName(registry->getKeyName());
1112 sal_Int32
prefix = registryName.getLength();
1113 if (!registryName.endsWith(
"/")) {
1114 prefix += RTL_CONSTASCII_LENGTH(
"/");
1116 const css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
1117 keys(registry->openKeys());
1118 css::uno::Reference< css::lang::XMultiComponentFactory > smgr(
1119 context->getServiceManager(), css::uno::UNO_SET_THROW);
1120 for (css::uno::Reference< css::registry::XRegistryKey >
const & key : keys) {
1121 OUString
name(key->getKeyName().copy(prefix));
1122 data->implementationNames.push_back(name);
1123 css::uno::Reference< css::registry::XRegistryKey > singletons(
1124 key->openKey(
"UNO/SINGLETONS"));
1125 if (singletons.is()) {
1126 sal_Int32 prefix2 = key->getKeyName().getLength() +
1127 RTL_CONSTASCII_LENGTH(
"/UNO/SINGLETONS/");
1128 const css::uno::Sequence<
1129 css::uno::Reference< css::registry::XRegistryKey > >
1130 singletonKeys(singletons->openKeys());
1131 for (css::uno::Reference< css::registry::XRegistryKey >
const & singletonKey : singletonKeys) {
1132 data->singletons.emplace_back(
1133 singletonKey->getKeyName().copy(prefix2), name);
1136 if (factories !=
nullptr) {
1137 factories->push_back(
1138 componentLoader->activate(
1139 name, OUString(), componentUrl, key));
1144void BackendImpl::ComponentPackageImpl::getComponentInfo(
1145 ComponentBackendDb::Data * data,
1146 std::vector< css::uno::Reference< css::uno::XInterface > > * factories,
1147 Reference<XComponentContext>
const &
xContext )
1149 const Reference<loader::XImplementationLoader> xLoader(
1150 xContext->getServiceManager()->createInstanceWithContext(
1154 throw css::deployment::DeploymentException(
1155 "cannot instantiate loader " +
m_loader,
1156 static_cast< OWeakObject *
>(
this),
Any());
1165 OUString url(getURL());
1166 const Reference<registry::XSimpleRegistry> xMemReg(
1167 xContext->getServiceManager()->createInstanceWithContext(
1168 "com.sun.star.registry.SimpleRegistry",
xContext ),
1170 xMemReg->open( OUString() ,
false,
true );
1171 xLoader->writeRegistryInfo( xMemReg->getRootKey(), OUString(), url );
1172 extractComponentData(
1173 xContext, xMemReg->getRootKey(), data, factories, xLoader, url);
1176void BackendImpl::ComponentPackageImpl::componentLiveInsertion(
1177 ComponentBackendDb::Data
const & data,
1178 std::vector< css::uno::Reference< css::uno::XInterface > >
const &
1181 css::uno::Reference< css::uno::XComponentContext > rootContext(
1182 getMyBackend()->getRootContext());
1183 css::uno::Reference< css::container::XSet >
set(
1184 rootContext->getServiceManager(), css::uno::UNO_QUERY_THROW);
1185 std::vector< css::uno::Reference< css::uno::XInterface > >::const_iterator
1186 factory(factories.begin());
1187 for (
auto const& implementationName : data.implementationNames)
1190 set->insert(css::uno::Any(*factory++));
1191 }
catch (
const container::ElementExistException &) {
1192 SAL_WARN(
"desktop.deployment",
"implementation already registered " << implementationName);
1195 if (data.singletons.empty())
return;
1197 css::uno::Reference< css::container::XNameContainer > cont(
1198 rootContext, css::uno::UNO_QUERY_THROW);
1199 for (
auto const& singleton : data.singletons)
1201 OUString
name(
"/singletons/" + singleton.first);
1204 cont->removeByName( name +
"/arguments");
1205 }
catch (
const container::NoSuchElementException &) {}
1207 cont->insertByName( name +
"/service", css::uno::Any(singleton.second));
1208 }
catch (
const container::ElementExistException &) {
1209 cont->replaceByName( name +
"/service", css::uno::Any(singleton.second));
1212 cont->insertByName(name, css::uno::Any());
1213 }
catch (
const container::ElementExistException &) {
1214 SAL_WARN(
"desktop.deployment",
"singleton already registered " << singleton.first);
1215 cont->replaceByName(name, css::uno::Any());
1220void BackendImpl::ComponentPackageImpl::componentLiveRemoval(
1221 ComponentBackendDb::Data
const & data)
1223 css::uno::Reference< css::uno::XComponentContext > rootContext(
1224 getMyBackend()->getRootContext());
1225 css::uno::Reference< css::container::XSet >
set(
1226 rootContext->getServiceManager(), css::uno::UNO_QUERY_THROW);
1227 for (
auto const& implementationName : data.implementationNames)
1230 set->remove(css::uno::Any(implementationName));
1231 }
catch (
const css::container::NoSuchElementException &) {
1235 if (data.singletons.empty())
1238 css::uno::Reference< css::container::XNameContainer > cont(
1239 rootContext, css::uno::UNO_QUERY_THROW);
1240 for (
auto const& singleton : data.singletons)
1242 OUString
name(
"/singletons/" + singleton.first);
1245 cont->removeByName(name);
1246 }
catch (
const container::NoSuchElementException &) {}
1248 cont->removeByName( name +
"/service" );
1249 }
catch (
const container::NoSuchElementException &) {}
1251 cont->removeByName( name +
"/arguments" );
1252 }
catch (
const container::NoSuchElementException &) {}
1261beans::Optional< beans::Ambiguous<sal_Bool> >
1262BackendImpl::ComponentPackageImpl::isRegistered_(
1263 ::osl::ResettableMutexGuard &,
1265 Reference<XCommandEnvironment>
const & )
1270 const Reference<registry::XSimpleRegistry> xRDB( getRDB() );
1273 bool bAmbiguousComponentName =
false;
1275 const Reference<registry::XRegistryKey> xRootKey(
1276 xRDB->getRootKey() );
1277 const Reference<registry::XRegistryKey> xImplKey(
1278 xRootKey->openKey(
"IMPLEMENTATIONS" ) );
1279 Sequence<OUString> implNames;
1280 if (xImplKey.is() && xImplKey->isValid())
1281 implNames = xImplKey->getKeyNames();
1282 OUString
const * pImplNames = implNames.getConstArray();
1283 sal_Int32
pos = implNames.getLength();
1286 checkAborted( abortChannel );
1288 pImplNames[ pos ] +
"/UNO/LOCATION" );
1289 const Reference<registry::XRegistryKey> xKey(
1290 xRootKey->openKey(key) );
1291 if (xKey.is() && xKey->isValid())
1293 const OUString location( xKey->getAsciiValue() );
1294 if (location.equalsIgnoreAsciiCase( getURL() ))
1301 OUString thisUrl(getURL());
1302 std::u16string_view thisFileName(thisUrl.subView(thisUrl.lastIndexOf(
'/')));
1304 std::u16string_view locationFileName(location.subView(location.lastIndexOf(
'/')));
1306 bAmbiguousComponentName =
true;
1312 else if (bAmbiguousComponentName)
1332 return beans::Optional< beans::Ambiguous<sal_Bool> >(
1334 beans::Ambiguous<sal_Bool>(
1339void BackendImpl::ComponentPackageImpl::processPackage_(
1340 ::osl::ResettableMutexGuard &,
1341 bool doRegisterPackage,
1344 Reference<XCommandEnvironment>
const & xCmdEnv )
1346 BackendImpl * that = getMyBackend();
1347 OUString url(getURL());
1348 if (doRegisterPackage) {
1349 ComponentBackendDb::Data data;
1350 css::uno::Reference< css::uno::XComponentContext > context;
1352 context = that->getComponentContext();
1354 context.set(that->getObject(url), css::uno::UNO_QUERY);
1355 if (!context.is()) {
1360 that->getComponentContext(), abortChannel)),
1361 css::uno::UNO_QUERY_THROW);
1364 css::uno::Reference< css::registry::XImplementationRegistration> impreg(
1365 context->getServiceManager()->createInstanceWithContext(
1366 "com.sun.star.registry.ImplementationRegistration",
1368 css::uno::UNO_QUERY_THROW);
1369 css::uno::Reference< css::registry::XSimpleRegistry > rdb(getRDB());
1370 impreg->registerImplementation(
m_loader, url, rdb);
1373 if (
m_loader ==
"com.sun.star.loader.Java2" && !jarManifestHeaderPresent(url, u
"UNO-Type-Path", xCmdEnv))
1375 that->addToUnoRc(RCITEM_JAR_TYPELIB, url, xCmdEnv);
1376 data.javaTypeLibrary =
true;
1378 std::vector< css::uno::Reference< css::uno::XInterface > > factories;
1379 getComponentInfo(&data, startup ?
nullptr : &factories, context);
1382 componentLiveInsertion(data, factories);
1383 }
catch (css::uno::Exception &) {
1386 impreg->revokeImplementation(url, rdb);
1387 }
catch (css::uno::RuntimeException &) {
1394 that->addDataToDb(url, data);
1397 ComponentBackendDb::Data data(that->readDataFromDb(url));
1398 css::uno::Reference< css::uno::XComponentContext > context(
1399 that->getObject(url), css::uno::UNO_QUERY);
1400 bool remoteContext = context.is();
1401 if (!remoteContext) {
1402 context = that->getComponentContext();
1405 componentLiveRemoval(data);
1407 css::uno::Reference< css::registry::XImplementationRegistration >(
1408 context->getServiceManager()->createInstanceWithContext(
1409 "com.sun.star.registry.ImplementationRegistration",
1411 css::uno::UNO_QUERY_THROW)->revokeImplementation(url, getRDB());
1412 if (data.javaTypeLibrary) {
1413 that->removeFromUnoRc(RCITEM_JAR_TYPELIB, url, xCmdEnv);
1415 if (remoteContext) {
1416 that->releaseObject(url);
1419 getMyBackend()->revokeEntryFromDb(url);
1423BackendImpl::TypelibraryPackageImpl::TypelibraryPackageImpl(
1425 OUString
const & url, OUString
const & name,
1426 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
1427 bool jarFile,
bool bRemoved, OUString
const & identifier)
1435BackendImpl * BackendImpl::TypelibraryPackageImpl::getMyBackend()
const
1437 BackendImpl * pBackend =
static_cast<BackendImpl *
>(m_myBackend.get());
1438 if (
nullptr == pBackend)
1444 static_cast<OWeakObject*
>(
const_cast<TypelibraryPackageImpl *
>(
this)));
1449beans::Optional< beans::Ambiguous<sal_Bool> >
1450BackendImpl::TypelibraryPackageImpl::isRegistered_(
1451 ::osl::ResettableMutexGuard &,
1453 Reference<XCommandEnvironment>
const & )
1455 BackendImpl * that = getMyBackend();
1456 return beans::Optional< beans::Ambiguous<sal_Bool> >(
1458 beans::Ambiguous<sal_Bool>(
1460 m_jarFile ? RCITEM_JAR_TYPELIB : RCITEM_RDB_TYPELIB, getURL() ),
1465void BackendImpl::TypelibraryPackageImpl::processPackage_(
1466 ::osl::ResettableMutexGuard &,
1467 bool doRegisterPackage,
1470 Reference<XCommandEnvironment>
const & xCmdEnv )
1472 BackendImpl * that = getMyBackend();
1473 const OUString url( getURL() );
1475 if (doRegisterPackage)
1489 css::uno::Reference< css::container::XSet >(
1490 that->getComponentContext()->getValueByName(
1492 "/com.sun.star.reflection.theTypeDescriptionManager"),
1493 css::uno::UNO_QUERY_THROW)->insert(
1497 that->addToUnoRc(
m_jarFile ? RCITEM_JAR_TYPELIB : RCITEM_RDB_TYPELIB,
1502 that->removeFromUnoRc(
1503 m_jarFile ? RCITEM_JAR_TYPELIB : RCITEM_RDB_TYPELIB, url, xCmdEnv );
1507 css::uno::Reference< css::container::XSet >(
1508 that->getComponentContext()->getValueByName(
1510 "/com.sun.star.reflection.theTypeDescriptionManager"),
1511 css::uno::UNO_QUERY_THROW)->remove(
1517BackendImpl::OtherPlatformPackageImpl::OtherPlatformPackageImpl(
1519 OUString
const & url, OUString
const & name,
1520 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
1521 bool bRemoved, OUString
const & identifier, OUString platform)
1525 OSL_PRECOND(bRemoved,
"this class can only be used for removing packages!");
1529BackendImpl::OtherPlatformPackageImpl::getMyBackend()
const
1531 BackendImpl * pBackend =
static_cast<BackendImpl *
>(m_myBackend.get());
1532 if (
nullptr == pBackend)
1538 static_cast<OWeakObject*
>(
const_cast<OtherPlatformPackageImpl*
>(
this)));
1543Reference<registry::XSimpleRegistry>
1544BackendImpl::OtherPlatformPackageImpl::impl_openRDB()
const
1547 OUString
const aRDBPath(
makeURL(getMyBackend()->getCachePath(), aRDB));
1549 Reference<registry::XSimpleRegistry> xRegistry;
1554 impl_createInstance(
"com.sun.star.registry.SimpleRegistry"),
1560 catch (registry::InvalidRegistryException
const&)
1563 xRegistry.set(
nullptr);
1566 SAL_WARN_IF( !xRegistry.is(),
"desktop.deployment",
"could not create registry for the package's platform");
1570Reference<XInterface>
1571BackendImpl::OtherPlatformPackageImpl::impl_createInstance(OUString
const& rService)
1576 Reference<XInterface> xService;
1578 xService.set(
xContext->getServiceManager()->createInstanceWithContext(rService,
xContext));
1582beans::Optional<beans::Ambiguous<sal_Bool> >
1583BackendImpl::OtherPlatformPackageImpl::isRegistered_(
1584 ::osl::ResettableMutexGuard& ,
1586 Reference<XCommandEnvironment>
const& )
1588 return beans::Optional<beans::Ambiguous<sal_Bool> >(
true,
1589 beans::Ambiguous<sal_Bool>(
true,
false));
1593BackendImpl::OtherPlatformPackageImpl::processPackage_(
1594 ::osl::ResettableMutexGuard& ,
1595 bool bRegisterPackage,
1598 Reference<XCommandEnvironment>
const& )
1600 OSL_PRECOND(!bRegisterPackage,
"this class can only be used for removing packages!");
1602 OUString
const aURL(getURL());
1604 Reference<registry::XSimpleRegistry>
const xServicesRDB(impl_openRDB());
1605 Reference<registry::XImplementationRegistration>
const xImplReg(
1606 impl_createInstance(
"com.sun.star.registry.ImplementationRegistration"),
1609 if (xImplReg.is() && xServicesRDB.is())
1610 xImplReg->revokeImplementation(
aURL, xServicesRDB);
1611 if (xServicesRDB.is())
1612 xServicesRDB->close();
1614 getMyBackend()->revokeEntryFromDb(
aURL);
1617BackendImpl * BackendImpl::ComponentsPackageImpl::getMyBackend()
const
1619 BackendImpl * pBackend =
static_cast<BackendImpl *
>(m_myBackend.get());
1620 if (
nullptr == pBackend)
1626 static_cast<OWeakObject*
>(
const_cast<ComponentsPackageImpl *
>(
this)));
1631beans::Optional< beans::Ambiguous<sal_Bool> >
1632BackendImpl::ComponentsPackageImpl::isRegistered_(
1633 ::osl::ResettableMutexGuard &,
1635 Reference<XCommandEnvironment>
const & )
1637 return beans::Optional< beans::Ambiguous<sal_Bool> >(
1639 beans::Ambiguous<sal_Bool>(
1640 getMyBackend()->hasInUnoRc(RCITEM_COMPONENTS, getURL()),
false));
1643void BackendImpl::ComponentsPackageImpl::processPackage_(
1644 ::osl::ResettableMutexGuard &,
1645 bool doRegisterPackage,
1648 Reference<XCommandEnvironment>
const & xCmdEnv )
1650 BackendImpl * that = getMyBackend();
1651 OUString url(getURL());
1652 if (doRegisterPackage) {
1654 css::uno::Reference< css::uno::XComponentContext > context(
1655 that->getObject(url), css::uno::UNO_QUERY);
1656 if (!context.is()) {
1661 that->getComponentContext(), abortChannel)),
1662 css::uno::UNO_QUERY_THROW);
1666 css::uno::Sequence< css::beans::NamedValue >
args
1669 {
"component-context", css::uno::Any(context) }
1671 css::uno::Reference< css::container::XSet > smgr(
1672 that->getRootContext()->getServiceManager(),
1673 css::uno::UNO_QUERY_THROW);
1674 smgr->insert(css::uno::Any(args));
1676 that->addToUnoRc(RCITEM_COMPONENTS, url, xCmdEnv);
1678 that->removeFromUnoRc(RCITEM_COMPONENTS, url, xCmdEnv);
1682 css::uno::Sequence< css::beans::NamedValue >
args { {
"uri", css::uno::Any(
expandUnoRcUrl(url)) } };
1683 css::uno::Reference< css::container::XSet > smgr(
1684 that->getRootContext()->getServiceManager(),
1685 css::uno::UNO_QUERY_THROW);
1686 smgr->remove(css::uno::Any(args));
1688 that->releaseObject(url);
1689 that->revokeEntryFromDb(url);
1693BackendImpl::ComponentsPackageImpl::ComponentsPackageImpl(
1695 OUString
const & url, OUString
const & name,
1696 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
1697 bool bRemoved, OUString
const & identifier)
1707extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
1709 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const& args)
1711 return cppu::acquire(
new dp_registry::backend::component::BackendImpl(
args, context));
static bool parse(OUString const &rMediaType, OUString &rType, OUString &rSubType, INetContentTypeParameterList *pParameters=nullptr)
virtual void SAL_CALL disposing() override
css::uno::Reference< css::ucb::XContent > get() const
void writeStream(const css::uno::Reference< css::io::XInputStream > &rStream, bool bReplaceExisting)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define TOOLS_INFO_EXCEPTION(area, stream)
OUString const m_aPlatform
std::deque< OUString > m_rdb_typelibs
const Reference< deployment::XPackageTypeInfo > m_xPythonComponentTypeInfo
OUString m_nativeRDB_orig
const Reference< deployment::XPackageTypeInfo > m_xRDBTypelibTypeInfo
Reference< registry::XSimpleRegistry > m_xCommonRDB
const Reference< deployment::XPackageTypeInfo > m_xComponentsTypeInfo
Sequence< Reference< deployment::XPackageTypeInfo > > m_typeInfos
std::deque< OUString > m_jar_typelibs
t_string2object m_backendObjects
std::deque< OUString > m_components
Reference< registry::XSimpleRegistry > m_xNativeRDB
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_deployment_component_PackageRegistryBackend_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
const Reference< deployment::XPackageTypeInfo > m_xJavaTypelibTypeInfo
std::unique_ptr< ComponentBackendDb > m_backendDb
const Reference< deployment::XPackageTypeInfo > m_xJavaComponentTypeInfo
const Reference< deployment::XPackageTypeInfo > m_xDynComponentTypeInfo
OUString m_commonRDB_orig
Reference< XComponentContext > const m_xComponentContext
OUString DpResId(TranslateId aId)
std::unordered_map< OString, INetContentTypeParameter > INetContentTypeParameterList
static uno::Reference< css::uno::XComponentContext > xContext
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
void set(css::uno::UnoInterfaceReference const &value)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
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 expandMacros(OUString const &text)
OUString makeURL(std::u16string_view baseURL, OUString const &relPath_)
appends a relative path to a url.
OUString makeRcTerm(OUString const &url)
OUString expandUnoRcUrl(OUString const &url)
Reference< XInterface > resolveUnoURL(OUString const &connectString, Reference< XComponentContext > const &xLocalContext, AbortChannel const *abortChannel)
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)
OUString generateRandomPipeId()
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool readLine(OUString *res, std::u16string_view startingWith, ::ucbhelper::Content &ucb_content, rtl_TextEncoding textenc)
OUString expandUnoRcTerm(OUString const &term_)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool platform_fits(std::u16string_view platform_string)
oslProcess raiseProcess(OUString const &appURL, Sequence< OUString > const &args)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString const & getPlatformString()
constexpr OUStringLiteral BACKEND_SERVICE_NAME
std::basic_string_view< charT, traits > trim(std::basic_string_view< charT, traits > str)
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
::boost::spirit::classic::rule< ScannerT > identifier