21 #include <strings.hrc>
26 #include <rtl/string.hxx>
27 #include <rtl/strbuf.hxx>
28 #include <rtl/ustrbuf.hxx>
29 #include <rtl/uri.hxx>
38 #include <com/sun/star/beans/NamedValue.hpp>
39 #include <com/sun/star/deployment/DeploymentException.hpp>
40 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
41 #include <com/sun/star/container/XNameContainer.hpp>
42 #include <com/sun/star/container/XSet.hpp>
43 #include <com/sun/star/registry/XSimpleRegistry.hpp>
44 #include <com/sun/star/registry/XImplementationRegistration.hpp>
45 #include <com/sun/star/loader/XImplementationLoader.hpp>
46 #include <com/sun/star/io/XInputStream.hpp>
47 #include <com/sun/star/ucb/NameClash.hpp>
48 #include <com/sun/star/util/theMacroExpander.hpp>
52 #include <string_view>
53 #include <unordered_map>
68 std::vector<OUString> getCmdBootstrapVariables()
70 std::vector<OUString> ret;
71 sal_uInt32
count = osl_getCommandArgCount();
72 for (sal_uInt32 i = 0;
i < count;
i++)
75 osl_getCommandArg(i, &arg.pData);
76 if (arg.startsWith(
"-env:"))
82 bool jarManifestHeaderPresent(
83 OUString
const & url, OUString
const & name,
87 buf.append(
"vnd.sun.star.zip://" );
90 url, rtl_UriCharClassRegName, rtl_UriEncodeIgnoreEscapes,
91 RTL_TEXTENCODING_UTF8 ) );
92 buf.append(
"/META-INF/MANIFEST.MF" );
97 &manifestContent, buf.makeStringAndClear(), xCmdEnv,
99 &&
readLine( &line, name, manifestContent, RTL_TEXTENCODING_ASCII_US );
107 BackendImpl * getMyBackend()
const;
111 enum class Reg { Uninit,
Void, Registered, NotRegistered, MaybeRegistered };
114 void getComponentInfo(
115 ComponentBackendDb::Data * data,
116 std::vector< css::uno::Reference< css::uno::XInterface > > *
120 void componentLiveInsertion(
121 ComponentBackendDb::Data
const & data,
122 std::vector< css::uno::Reference< css::uno::XInterface > >
const &
125 void componentLiveRemoval(ComponentBackendDb::Data
const & data);
128 virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
129 ::osl::ResettableMutexGuard & guard,
132 virtual void processPackage_(
133 ::osl::ResettableMutexGuard & guard,
134 bool registerPackage,
139 Reference<registry::XSimpleRegistry> getRDB()
const;
142 ComponentPackageImpl(
144 OUString
const & url, OUString
const & name,
145 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
146 OUString
const & loader,
bool bRemoved,
147 OUString
const & identifier);
149 friend class ComponentPackageImpl;
153 BackendImpl * getMyBackend()
const;
156 virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
157 ::osl::ResettableMutexGuard & guard,
160 virtual void processPackage_(
161 ::osl::ResettableMutexGuard & guard,
162 bool registerPackage,
167 ComponentsPackageImpl(
169 OUString
const & url, OUString
const & name,
170 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
171 bool bRemoved, OUString
const & identifier);
173 friend class ComponentsPackageImpl;
177 BackendImpl * getMyBackend()
const;
182 virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
183 ::osl::ResettableMutexGuard & guard,
186 virtual void processPackage_(
187 ::osl::ResettableMutexGuard & guard,
188 bool registerPackage,
194 TypelibraryPackageImpl(
196 OUString
const & url, OUString
const & name,
197 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
198 bool jarFile,
bool bRemoved,
199 OUString
const & identifier);
201 friend class TypelibraryPackageImpl;
210 OtherPlatformPackageImpl(
212 OUString
const & url, OUString
const & name,
213 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
214 bool bRemoved, OUString
const & identifier, OUString
const& rPlatform);
217 BackendImpl * getMyBackend()
const;
219 Reference<registry::XSimpleRegistry> impl_openRDB()
const;
220 Reference<XInterface> impl_createInstance(OUString
const& rService)
const;
223 virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
224 ::osl::ResettableMutexGuard & guard,
227 virtual void processPackage_(
228 ::osl::ResettableMutexGuard & guard,
229 bool registerPackage,
237 friend class OtherPlatformPackageImpl;
243 enum RcItem { RCITEM_JAR_TYPELIB, RCITEM_RDB_TYPELIB, RCITEM_COMPONENTS };
245 std::deque<OUString> & getRcItemList( RcItem kind ) {
248 case RCITEM_JAR_TYPELIB:
250 case RCITEM_RDB_TYPELIB:
261 typedef std::unordered_map< OUString, Reference<XInterface> > t_string2object;
265 virtual Reference<deployment::XPackage> bindPackage_(
266 OUString
const & url, OUString
const & mediaType,
267 bool bRemoved, OUString
const & identifier,
270 virtual void SAL_CALL disposing()
override;
289 void addDataToDb(OUString
const & url, ComponentBackendDb::Data
const & data);
290 ComponentBackendDb::Data readDataFromDb(std::u16string_view url);
291 void revokeEntryFromDb(std::u16string_view url);
299 Reference<XInterface> getObject( OUString
const &
id );
300 Reference<XInterface> insertObject(
301 OUString
const &
id, Reference<XInterface>
const & xObject );
302 void releaseObject( OUString
const &
id );
304 void addToUnoRc( RcItem kind, OUString
const & url,
306 void removeFromUnoRc( RcItem kind, OUString
const & url,
308 bool hasInUnoRc( RcItem kind, OUString
const & url );
310 css::uno::Reference< css::uno::XComponentContext > getRootContext()
const;
313 BackendImpl( Sequence<Any>
const & args,
322 virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL
323 getSupportedPackageTypes()
override;
325 virtual void SAL_CALL packageRemoved(OUString
const & url, OUString
const & mediaType)
override;
330 void initServiceRdbFiles();
334 BackendImpl::ComponentPackageImpl::ComponentPackageImpl(
336 OUString
const & url, OUString
const & name,
337 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
338 OUString
const & loader,
bool bRemoved,
339 OUString
const & identifier)
340 :
Package( myBackend, url, name, name ,
341 xPackageType, bRemoved, identifier),
346 Reference<registry::XSimpleRegistry>
347 BackendImpl::ComponentPackageImpl::getRDB()
const
349 BackendImpl * that = getMyBackend();
357 const ::osl::MutexGuard guard(
getMutex() );
358 if (!that->bSwitchedRdbFiles)
360 that->bSwitchedRdbFiles =
true;
361 that->initServiceRdbFiles();
364 if (
m_loader ==
"com.sun.star.loader.SharedLibrary" )
365 return that->m_xNativeRDB;
367 return that->m_xCommonRDB;
370 BackendImpl * BackendImpl::ComponentPackageImpl::getMyBackend()
const
372 BackendImpl * pBackend =
static_cast<BackendImpl *
>(m_myBackend.get());
373 if (
nullptr == pBackend)
379 "Failed to get the BackendImpl",
380 static_cast<OWeakObject*>(const_cast<ComponentPackageImpl *>(
this)));
386 void BackendImpl::disposing()
400 PackageRegistryBackend::disposing();
405 catch (
const Exception &) {
407 throw lang::WrappedTargetRuntimeException(
408 "caught unexpected exception while disposing...",
409 static_cast<OWeakObject *>(
this), exc );
414 void BackendImpl::initServiceRdbFiles()
428 if (oldRDB.
get().is())
430 cacheDir.transferContent(
445 if (oldRDB.
get().is())
447 cacheDir.transferContent(
461 ->createInstanceWithContext(
462 "com.sun.star.registry.SimpleRegistry",
471 ->createInstanceWithContext(
472 "com.sun.star.registry.SimpleRegistry",
480 BackendImpl::BackendImpl(
481 Sequence<Any>
const & args,
483 : PackageRegistryBackend( args, xComponentContext ),
488 "application/vnd.sun.star.uno-component;type=native;platform=" +
494 "application/vnd.sun.star.uno-component;type=Java",
496 DpResId(RID_STR_JAVA_COMPONENT)
499 "application/vnd.sun.star.uno-component;type=Python",
502 RID_STR_PYTHON_COMPONENT)
505 "application/vnd.sun.star.uno-components",
510 "application/vnd.sun.star.uno-typelibrary;type=RDB",
515 "application/vnd.sun.star.uno-typelibrary;type=Java",
535 xComponentContext->getServiceManager()->createInstanceWithContext(
536 "com.sun.star.registry.SimpleRegistry",
537 xComponentContext ), UNO_QUERY_THROW );
541 xComponentContext->getServiceManager()->createInstanceWithContext(
542 "com.sun.star.registry.SimpleRegistry",
543 xComponentContext ), UNO_QUERY_THROW );
549 unorc_verify_init( xCmdEnv );
550 OUString dbFile =
makeURL(getCachePath(),
"backenddb.xml");
557 OUString BackendImpl::getImplementationName()
559 return "com.sun.star.comp.deployment.component.PackageRegistryBackend";
562 sal_Bool BackendImpl::supportsService(
const OUString& ServiceName )
567 css::uno::Sequence< OUString > BackendImpl::getSupportedServiceNames()
572 void BackendImpl::addDataToDb(
573 OUString
const & url, ComponentBackendDb::Data
const & data)
579 ComponentBackendDb::Data BackendImpl::readDataFromDb(std::u16string_view url)
581 ComponentBackendDb::Data data;
587 void BackendImpl::revokeEntryFromDb(std::u16string_view url)
595 Sequence< Reference<deployment::XPackageTypeInfo> >
596 BackendImpl::getSupportedPackageTypes()
601 void BackendImpl::packageRemoved(OUString
const & url, OUString
const & )
609 Reference<deployment::XPackage> BackendImpl::bindPackage_(
610 OUString
const & url, OUString
const & mediaType_,
611 bool bRemoved, OUString
const & identifier,
614 OUString mediaType(mediaType_);
615 if ( mediaType.isEmpty() || mediaType ==
"application/vnd.sun.star.uno-component" || mediaType ==
"application/vnd.sun.star.uno-typelibrary" )
620 const OUString title( StrTitle::getTitle( ucbContent ) );
621 if (title.endsWithIgnoreAsciiCase(SAL_DLLEXTENSION))
623 mediaType =
"application/vnd.sun.star.uno-component;type=native;platform=" +
626 else if (title.endsWithIgnoreAsciiCase(
".jar"))
628 if (jarManifestHeaderPresent(
629 url,
"RegistrationClassName", xCmdEnv ))
630 mediaType =
"application/vnd.sun.star.uno-component;type=Java";
631 if (mediaType.isEmpty())
632 mediaType =
"application/vnd.sun.star.uno-typelibrary;type=Java";
634 else if (title.endsWithIgnoreAsciiCase(
".py"))
635 mediaType =
"application/vnd.sun.star.uno-component;type=Python";
636 else if (title.endsWithIgnoreAsciiCase(
".rdb"))
637 mediaType =
"application/vnd.sun.star.uno-typelibrary;type=RDB";
639 if (mediaType.isEmpty())
640 throw lang::IllegalArgumentException(
641 StrCannotDetectMediaType() + url,
642 static_cast<OWeakObject *
>(
this), static_cast<sal_Int16>(-1) );
645 OUString
type, subType;
649 if (type.equalsIgnoreAsciiCase(
"application"))
655 name = StrTitle::getTitle( ucbContent );
658 if (subType.equalsIgnoreAsciiCase(
"vnd.sun.star.uno-component"))
662 auto const iter = params.find(OString(
"platform"));
663 bool bPlatformFits(iter == params.end());
667 aPlatform = iter->second.m_sValue;
672 if (bPlatformFits || bRemoved) {
673 auto const iterType = params.find(OString(
"type"));
674 if (iterType != params.end())
676 OUString
const &
value = iterType->second.m_sValue;
677 if (value.equalsIgnoreAsciiCase(
"native")) {
679 return new BackendImpl::ComponentPackageImpl(
681 "com.sun.star.loader.SharedLibrary",
682 bRemoved, identifier);
684 return new BackendImpl::OtherPlatformPackageImpl(
686 bRemoved, identifier, aPlatform);
688 if (value.equalsIgnoreAsciiCase(
"Java")) {
689 return new BackendImpl::ComponentPackageImpl(
691 "com.sun.star.loader.Java2",
692 bRemoved, identifier);
694 if (value.equalsIgnoreAsciiCase(
"Python")) {
695 return new BackendImpl::ComponentPackageImpl(
697 "com.sun.star.loader.Python",
698 bRemoved, identifier);
703 else if (subType.equalsIgnoreAsciiCase(
"vnd.sun.star.uno-components"))
705 auto const iter = params.find(OString(
"platform"));
706 if (iter == params.end() ||
platform_fits(iter->second.m_sValue)) {
707 return new BackendImpl::ComponentsPackageImpl(
712 else if (subType.equalsIgnoreAsciiCase(
"vnd.sun.star.uno-typelibrary"))
714 auto const iter = params.find(OString(
"type"));
715 if (iter != params.end()) {
716 OUString
const & value = iter->second.m_sValue;
717 if (value.equalsIgnoreAsciiCase(
"RDB"))
719 return new BackendImpl::TypelibraryPackageImpl(
721 false , bRemoved, identifier);
723 if (value.equalsIgnoreAsciiCase(
"Java")) {
724 return new BackendImpl::TypelibraryPackageImpl(
726 true , bRemoved, identifier);
732 throw lang::IllegalArgumentException(
733 StrUnsupportedMediaType() + mediaType,
734 static_cast<OWeakObject *>(
this),
735 static_cast<sal_Int16>(-1) );
739 void BackendImpl::unorc_verify_init(
744 const ::osl::MutexGuard guard(
getMutex() );
752 makeURL( getCachePath(),
"unorc" ),
756 if (
readLine( &line,
"UNO_JAVA_CLASSPATH=", ucb_content,
757 RTL_TEXTENCODING_UTF8 ))
759 sal_Int32
index =
sizeof (
"UNO_JAVA_CLASSPATH=") - 1;
761 OUString token( line.getToken( 0,
' ', index ).trim() );
762 if (!token.isEmpty())
772 m_jar_typelibs.push_back( token );
778 if (
readLine( &line,
"UNO_TYPES=", ucb_content,
779 RTL_TEXTENCODING_UTF8 )) {
780 sal_Int32 index =
sizeof (
"UNO_TYPES=") - 1;
782 OUString token( line.getToken( 0,
' ', index ).trim() );
783 if (!token.isEmpty())
785 if (token[ 0 ] ==
'?')
786 token = token.copy( 1 );
795 m_rdb_typelibs.push_back( token );
801 if (
readLine( &line,
"UNO_SERVICES=", ucb_content,
802 RTL_TEXTENCODING_UTF8 ))
813 for (sal_Int32 i = RTL_CONSTASCII_LENGTH(
"UNO_SERVICES=");
816 OUString token(line.getToken(0,
' ', i));
817 if (!token.isEmpty())
819 if (state == 1 && token.match(
"?$ORIGIN/"))
822 RTL_CONSTASCII_LENGTH(
"?$ORIGIN/"));
825 else if ( state <= 2 && token ==
"${$ORIGIN/${_OS}_${_ARCH}rc:UNO_SERVICES}" )
833 token = token.copy(1);
835 m_components.push_back(token);
847 if (
readLine( &line,
"UNO_SERVICES=", ucb_content,
848 RTL_TEXTENCODING_UTF8 )) {
850 sizeof (
"UNO_SERVICES=?$ORIGIN/") - 1 );
868 buf.append(
"ORIGIN=");
871 buf.append(osOrigin);
874 if (! m_jar_typelibs.empty())
876 auto iPos( m_jar_typelibs.cbegin() );
877 auto const iEnd( m_jar_typelibs.cend() );
878 buf.append(
"UNO_JAVA_CLASSPATH=" );
879 while (iPos != iEnd) {
890 if (! m_rdb_typelibs.empty())
892 auto iPos( m_rdb_typelibs.cbegin() );
893 auto const iEnd( m_rdb_typelibs.cend() );
894 buf.append(
"UNO_TYPES=" );
895 while (iPos != iEnd) {
914 if (!sCommonRDB.isEmpty() || !sNativeRDB.isEmpty() ||
915 !m_components.empty())
917 buf.append(
"UNO_SERVICES=" );
919 if (!sCommonRDB.isEmpty())
921 buf.append(
"?$ORIGIN/" );
923 sCommonRDB, RTL_TEXTENCODING_ASCII_US ) );
926 if (!sNativeRDB.isEmpty())
932 buf.append(
"${$ORIGIN/${_OS}_${_ARCH}rc:UNO_SERVICES}" );
940 "UNO_SERVICES=?$ORIGIN/" +
944 const Reference<io::XInputStream> xData(
946 reinterpret_cast<sal_Int8 const *>(buf2.getStr()),
947 buf2.getLength() ) );
953 for (
auto const& component : m_components)
967 const Reference<io::XInputStream> xData(
969 reinterpret_cast<sal_Int8 const *>(buf.getStr()),
979 void BackendImpl::addToUnoRc( RcItem kind, OUString
const & url_,
983 const ::osl::MutexGuard guard(
getMutex() );
984 unorc_verify_init( xCmdEnv );
985 std::deque<OUString> & rSet = getRcItemList(kind);
986 if (std::find( rSet.begin(), rSet.end(), rcterm ) == rSet.end()) {
987 rSet.push_front( rcterm );
990 unorc_flush( xCmdEnv );
995 void BackendImpl::removeFromUnoRc(
996 RcItem kind, OUString
const & url_,
1000 const ::osl::MutexGuard guard(
getMutex() );
1001 unorc_verify_init( xCmdEnv );
1002 std::deque<OUString> & aRcItemList = getRcItemList(kind);
1003 aRcItemList.erase(std::remove(aRcItemList.begin(), aRcItemList.end(), rcterm), aRcItemList.end());
1006 unorc_flush( xCmdEnv );
1010 bool BackendImpl::hasInUnoRc(
1011 RcItem kind, OUString
const & url_ )
1014 const ::osl::MutexGuard guard(
getMutex() );
1015 std::deque<OUString>
const & rSet = getRcItemList(kind);
1016 return std::find( rSet.begin(), rSet.end(), rcterm ) != rSet.end();
1019 css::uno::Reference< css::uno::XComponentContext > BackendImpl::getRootContext()
1022 css::uno::Reference< css::uno::XComponentContext > rootContext(
1024 css::uno::UNO_QUERY);
1029 void BackendImpl::releaseObject( OUString
const &
id )
1031 const ::osl::MutexGuard guard(
getMutex() );
1036 Reference<XInterface> BackendImpl::getObject( OUString
const &
id )
1038 const ::osl::MutexGuard guard(
getMutex() );
1039 const t_string2object::const_iterator iFind(
m_backendObjects.find(
id ) );
1041 return Reference<XInterface>();
1043 return iFind->second;
1047 Reference<XInterface> BackendImpl::insertObject(
1048 OUString
const &
id, Reference<XInterface>
const & xObject )
1050 const ::osl::MutexGuard guard(
getMutex() );
1051 const std::pair<t_string2object::iterator, bool> insertion(
1053 return insertion.first->second;
1061 OSL_ASSERT( xContext.is() );
1063 OUString url( util::theMacroExpander::get(xContext)->
expandMacros(
"$URE_BIN_DIR/uno" ) );
1065 const OUString connectStr =
"uno:pipe,name=" +
generateRandomPipeId() +
";urp;uno.ComponentContext";
1071 std::vector<OUString> args{
1072 #if OSL_DEBUG_LEVEL == 0
1079 "-env:INIFILENAME=" };
1082 std::vector<OUString> bootvars = getCmdBootstrapVariables();
1083 args.insert(args.end(), bootvars.begin(), bootvars.end());
1085 oslProcess hProcess;
1091 OUStringBuffer sMsg =
"error starting process: " + url;
1092 for(
const auto& arg : args)
1093 sMsg.append(
" ").append(arg);
1094 throw uno::RuntimeException(sMsg.makeStringAndClear());
1103 if ( osl_terminateProcess( hProcess ) != osl_Process_E_None )
1105 OSL_ASSERT(
false );
1111 void extractComponentData(
1112 css::uno::Reference< css::uno::XComponentContext >
const & context,
1113 css::uno::Reference< css::registry::XRegistryKey >
const & registry,
1114 ComponentBackendDb::Data * data,
1115 std::vector< css::uno::Reference< css::uno::XInterface > > * factories,
1116 css::uno::Reference< css::loader::XImplementationLoader >
const &
1118 OUString
const & componentUrl)
1121 context.is() && registry.is() && data !=
nullptr && componentLoader.is());
1122 OUString registryName(registry->getKeyName());
1123 sal_Int32
prefix = registryName.getLength();
1124 if (!registryName.endsWith(
"/")) {
1125 prefix += RTL_CONSTASCII_LENGTH(
"/");
1127 const css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
1128 keys(registry->openKeys());
1129 css::uno::Reference< css::lang::XMultiComponentFactory > smgr(
1130 context->getServiceManager(), css::uno::UNO_SET_THROW);
1131 for (css::uno::Reference< css::registry::XRegistryKey >
const & key : keys) {
1132 OUString name(key->getKeyName().copy(prefix));
1133 data->implementationNames.push_back(name);
1134 css::uno::Reference< css::registry::XRegistryKey > singletons(
1135 key->openKey(
"UNO/SINGLETONS"));
1136 if (singletons.is()) {
1137 sal_Int32 prefix2 = key->getKeyName().getLength() +
1138 RTL_CONSTASCII_LENGTH(
"/UNO/SINGLETONS/");
1139 const css::uno::Sequence<
1140 css::uno::Reference< css::registry::XRegistryKey > >
1141 singletonKeys(singletons->openKeys());
1142 for (css::uno::Reference< css::registry::XRegistryKey >
const & singletonKey : singletonKeys) {
1143 data->singletons.emplace_back(
1144 singletonKey->getKeyName().copy(prefix2), name);
1147 if (factories !=
nullptr) {
1148 factories->push_back(
1149 componentLoader->activate(
1150 name, OUString(), componentUrl, key));
1155 void BackendImpl::ComponentPackageImpl::getComponentInfo(
1156 ComponentBackendDb::Data * data,
1157 std::vector< css::uno::Reference< css::uno::XInterface > > * factories,
1160 const Reference<loader::XImplementationLoader> xLoader(
1161 xContext->getServiceManager()->createInstanceWithContext(
1165 throw css::deployment::DeploymentException(
1166 "cannot instantiate loader " +
m_loader,
1167 static_cast< OWeakObject * >(
this),
Any());
1176 OUString url(getURL());
1177 const Reference<registry::XSimpleRegistry> xMemReg(
1178 xContext->getServiceManager()->createInstanceWithContext(
1179 "com.sun.star.registry.SimpleRegistry", xContext ),
1181 xMemReg->open( OUString() ,
false,
true );
1182 xLoader->writeRegistryInfo( xMemReg->getRootKey(), OUString(), url );
1183 extractComponentData(
1184 xContext, xMemReg->getRootKey(), data, factories, xLoader, url);
1187 void BackendImpl::ComponentPackageImpl::componentLiveInsertion(
1188 ComponentBackendDb::Data
const & data,
1189 std::vector< css::uno::Reference< css::uno::XInterface > >
const &
1192 css::uno::Reference< css::uno::XComponentContext > rootContext(
1193 getMyBackend()->getRootContext());
1194 css::uno::Reference< css::container::XSet >
set(
1195 rootContext->getServiceManager(), css::uno::UNO_QUERY_THROW);
1196 std::vector< css::uno::Reference< css::uno::XInterface > >::const_iterator
1197 factory(factories.begin());
1198 for (
auto const& implementationName : data.implementationNames)
1201 set->insert(css::uno::Any(*factory++));
1202 }
catch (
const container::ElementExistException &) {
1203 SAL_WARN(
"desktop.deployment",
"implementation already registered " << implementationName);
1206 if (data.singletons.empty())
return;
1208 css::uno::Reference< css::container::XNameContainer > cont(
1209 rootContext, css::uno::UNO_QUERY_THROW);
1210 for (
auto const& singleton : data.singletons)
1212 OUString name(
"/singletons/" + singleton.first);
1215 cont->removeByName( name +
"/arguments");
1216 }
catch (
const container::NoSuchElementException &) {}
1218 cont->insertByName( name +
"/service", css::uno::Any(singleton.second));
1219 }
catch (
const container::ElementExistException &) {
1220 cont->replaceByName( name +
"/service", css::uno::Any(singleton.second));
1223 cont->insertByName(name, css::uno::Any());
1224 }
catch (
const container::ElementExistException &) {
1225 SAL_WARN(
"desktop.deployment",
"singleton already registered " << singleton.first);
1226 cont->replaceByName(name, css::uno::Any());
1231 void BackendImpl::ComponentPackageImpl::componentLiveRemoval(
1232 ComponentBackendDb::Data
const & data)
1234 css::uno::Reference< css::uno::XComponentContext > rootContext(
1235 getMyBackend()->getRootContext());
1236 css::uno::Reference< css::container::XSet >
set(
1237 rootContext->getServiceManager(), css::uno::UNO_QUERY_THROW);
1238 for (
auto const& implementationName : data.implementationNames)
1241 set->remove(css::uno::Any(implementationName));
1242 }
catch (
const css::container::NoSuchElementException &) {
1246 if (data.singletons.empty())
1249 css::uno::Reference< css::container::XNameContainer > cont(
1250 rootContext, css::uno::UNO_QUERY_THROW);
1251 for (
auto const& singleton : data.singletons)
1253 OUString name(
"/singletons/" + singleton.first);
1256 cont->removeByName(name);
1257 }
catch (
const container::NoSuchElementException &) {}
1259 cont->removeByName( name +
"/service" );
1260 }
catch (
const container::NoSuchElementException &) {}
1262 cont->removeByName( name +
"/arguments" );
1263 }
catch (
const container::NoSuchElementException &) {}
1272 beans::Optional< beans::Ambiguous<sal_Bool> >
1273 BackendImpl::ComponentPackageImpl::isRegistered_(
1274 ::osl::ResettableMutexGuard &,
1281 const Reference<registry::XSimpleRegistry> xRDB( getRDB() );
1284 bool bAmbiguousComponentName =
false;
1286 const Reference<registry::XRegistryKey> xRootKey(
1287 xRDB->getRootKey() );
1288 const Reference<registry::XRegistryKey> xImplKey(
1289 xRootKey->openKey(
"IMPLEMENTATIONS" ) );
1291 if (xImplKey.is() && xImplKey->isValid())
1292 implNames = xImplKey->getKeyNames();
1293 OUString
const * pImplNames = implNames.getConstArray();
1294 sal_Int32
pos = implNames.getLength();
1297 checkAborted( abortChannel );
1299 pImplNames[ pos ] +
"/UNO/LOCATION" );
1300 const Reference<registry::XRegistryKey> xKey(
1301 xRootKey->openKey(key) );
1302 if (xKey.is() && xKey->isValid())
1304 const OUString location( xKey->getAsciiValue() );
1305 if (location.equalsIgnoreAsciiCase( getURL() ))
1312 OUString thisUrl(getURL());
1313 OUString thisFileName(thisUrl.copy(thisUrl.lastIndexOf(
'/')));
1315 OUString locationFileName(location.copy(location.lastIndexOf(
'/')));
1316 if (locationFileName.equalsIgnoreAsciiCase(thisFileName))
1317 bAmbiguousComponentName =
true;
1323 else if (bAmbiguousComponentName)
1343 return beans::Optional< beans::Ambiguous<sal_Bool> >(
1345 beans::Ambiguous<sal_Bool>(
1350 void BackendImpl::ComponentPackageImpl::processPackage_(
1351 ::osl::ResettableMutexGuard &,
1352 bool doRegisterPackage,
1357 BackendImpl * that = getMyBackend();
1358 OUString url(getURL());
1359 if (doRegisterPackage) {
1360 ComponentBackendDb::Data data;
1361 css::uno::Reference< css::uno::XComponentContext > context;
1363 context = that->getComponentContext();
1365 context.set(that->getObject(url), css::uno::UNO_QUERY);
1366 if (!context.is()) {
1371 that->getComponentContext(), abortChannel)),
1372 css::uno::UNO_QUERY_THROW);
1375 css::uno::Reference< css::registry::XImplementationRegistration> impreg(
1376 context->getServiceManager()->createInstanceWithContext(
1377 "com.sun.star.registry.ImplementationRegistration",
1379 css::uno::UNO_QUERY_THROW);
1380 css::uno::Reference< css::registry::XSimpleRegistry > rdb(getRDB());
1381 impreg->registerImplementation(
m_loader, url, rdb);
1384 if (
m_loader ==
"com.sun.star.loader.Java2" && !jarManifestHeaderPresent(url,
"UNO-Type-Path", xCmdEnv))
1386 that->addToUnoRc(RCITEM_JAR_TYPELIB, url, xCmdEnv);
1387 data.javaTypeLibrary =
true;
1389 std::vector< css::uno::Reference< css::uno::XInterface > > factories;
1390 getComponentInfo(&data, startup ?
nullptr : &factories, context);
1393 componentLiveInsertion(data, factories);
1394 }
catch (css::uno::Exception &) {
1397 impreg->revokeImplementation(url, rdb);
1398 }
catch (css::uno::RuntimeException &) {
1405 that->addDataToDb(url, data);
1408 ComponentBackendDb::Data data(that->readDataFromDb(url));
1409 css::uno::Reference< css::uno::XComponentContext > context(
1410 that->getObject(url), css::uno::UNO_QUERY);
1411 bool remoteContext = context.is();
1412 if (!remoteContext) {
1413 context = that->getComponentContext();
1416 componentLiveRemoval(data);
1418 css::uno::Reference< css::registry::XImplementationRegistration >(
1419 context->getServiceManager()->createInstanceWithContext(
1420 "com.sun.star.registry.ImplementationRegistration",
1422 css::uno::UNO_QUERY_THROW)->revokeImplementation(url, getRDB());
1423 if (data.javaTypeLibrary) {
1424 that->removeFromUnoRc(RCITEM_JAR_TYPELIB, url, xCmdEnv);
1426 if (remoteContext) {
1427 that->releaseObject(url);
1430 getMyBackend()->revokeEntryFromDb(url);
1434 BackendImpl::TypelibraryPackageImpl::TypelibraryPackageImpl(
1436 OUString
const & url, OUString
const & name,
1437 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
1438 bool jarFile,
bool bRemoved, OUString
const & identifier)
1439 :
Package( myBackend, url, name, name ,
1440 xPackageType, bRemoved, identifier),
1446 BackendImpl * BackendImpl::TypelibraryPackageImpl::getMyBackend()
const
1448 BackendImpl * pBackend =
static_cast<BackendImpl *
>(m_myBackend.get());
1449 if (
nullptr == pBackend)
1455 static_cast<OWeakObject*>(const_cast<TypelibraryPackageImpl *>(
this)));
1460 beans::Optional< beans::Ambiguous<sal_Bool> >
1461 BackendImpl::TypelibraryPackageImpl::isRegistered_(
1462 ::osl::ResettableMutexGuard &,
1466 BackendImpl * that = getMyBackend();
1467 return beans::Optional< beans::Ambiguous<sal_Bool> >(
1469 beans::Ambiguous<sal_Bool>(
1471 m_jarFile ? RCITEM_JAR_TYPELIB : RCITEM_RDB_TYPELIB, getURL() ),
1476 void BackendImpl::TypelibraryPackageImpl::processPackage_(
1477 ::osl::ResettableMutexGuard &,
1478 bool doRegisterPackage,
1483 BackendImpl * that = getMyBackend();
1484 const OUString url( getURL() );
1486 if (doRegisterPackage)
1500 css::uno::Reference< css::container::XSet >(
1501 that->getComponentContext()->getValueByName(
1503 "/com.sun.star.reflection.theTypeDescriptionManager"),
1504 css::uno::UNO_QUERY_THROW)->insert(
1508 that->addToUnoRc(
m_jarFile ? RCITEM_JAR_TYPELIB : RCITEM_RDB_TYPELIB,
1513 that->removeFromUnoRc(
1514 m_jarFile ? RCITEM_JAR_TYPELIB : RCITEM_RDB_TYPELIB, url, xCmdEnv );
1518 css::uno::Reference< css::container::XSet >(
1519 that->getComponentContext()->getValueByName(
1521 "/com.sun.star.reflection.theTypeDescriptionManager"),
1522 css::uno::UNO_QUERY_THROW)->
remove(
1528 BackendImpl::OtherPlatformPackageImpl::OtherPlatformPackageImpl(
1530 OUString
const & url, OUString
const & name,
1531 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
1532 bool bRemoved, OUString
const & identifier, OUString
const& rPlatform)
1533 :
Package(myBackend, url, name, name, xPackageType, bRemoved, identifier)
1536 OSL_PRECOND(bRemoved,
"this class can only be used for removing packages!");
1540 BackendImpl::OtherPlatformPackageImpl::getMyBackend()
const
1542 BackendImpl * pBackend =
static_cast<BackendImpl *
>(m_myBackend.get());
1543 if (
nullptr == pBackend)
1549 static_cast<OWeakObject*>(const_cast<OtherPlatformPackageImpl*>(
this)));
1554 Reference<registry::XSimpleRegistry>
1555 BackendImpl::OtherPlatformPackageImpl::impl_openRDB()
const
1558 OUString
const aRDBPath(
makeURL(getMyBackend()->getCachePath(), aRDB));
1560 Reference<registry::XSimpleRegistry> xRegistry;
1565 impl_createInstance(
"com.sun.star.registry.SimpleRegistry"),
1571 catch (registry::InvalidRegistryException
const&)
1574 xRegistry.set(
nullptr);
1577 SAL_WARN_IF( !xRegistry.is(),
"desktop.deployment",
"could not create registry for the package's platform");
1581 Reference<XInterface>
1582 BackendImpl::OtherPlatformPackageImpl::impl_createInstance(OUString
const& rService)
1586 OSL_ASSERT(xContext.is());
1587 Reference<XInterface> xService;
1589 xService.set(xContext->getServiceManager()->createInstanceWithContext(rService, xContext));
1593 beans::Optional<beans::Ambiguous<sal_Bool> >
1594 BackendImpl::OtherPlatformPackageImpl::isRegistered_(
1595 ::osl::ResettableMutexGuard& ,
1599 return beans::Optional<beans::Ambiguous<sal_Bool> >(
true,
1600 beans::Ambiguous<sal_Bool>(
true,
false));
1604 BackendImpl::OtherPlatformPackageImpl::processPackage_(
1605 ::osl::ResettableMutexGuard& ,
1606 bool bRegisterPackage,
1611 OSL_PRECOND(!bRegisterPackage,
"this class can only be used for removing packages!");
1613 OUString
const aURL(getURL());
1615 Reference<registry::XSimpleRegistry>
const xServicesRDB(impl_openRDB());
1616 Reference<registry::XImplementationRegistration>
const xImplReg(
1617 impl_createInstance(
"com.sun.star.registry.ImplementationRegistration"),
1620 if (xImplReg.is() && xServicesRDB.is())
1621 xImplReg->revokeImplementation(
aURL, xServicesRDB);
1622 if (xServicesRDB.is())
1623 xServicesRDB->close();
1625 getMyBackend()->revokeEntryFromDb(
aURL);
1628 BackendImpl * BackendImpl::ComponentsPackageImpl::getMyBackend()
const
1630 BackendImpl * pBackend =
static_cast<BackendImpl *
>(m_myBackend.get());
1631 if (
nullptr == pBackend)
1637 static_cast<OWeakObject*>(const_cast<ComponentsPackageImpl *>(
this)));
1642 beans::Optional< beans::Ambiguous<sal_Bool> >
1643 BackendImpl::ComponentsPackageImpl::isRegistered_(
1644 ::osl::ResettableMutexGuard &,
1648 return beans::Optional< beans::Ambiguous<sal_Bool> >(
1650 beans::Ambiguous<sal_Bool>(
1651 getMyBackend()->hasInUnoRc(RCITEM_COMPONENTS, getURL()),
false));
1654 void BackendImpl::ComponentsPackageImpl::processPackage_(
1655 ::osl::ResettableMutexGuard &,
1656 bool doRegisterPackage,
1661 BackendImpl * that = getMyBackend();
1662 OUString url(getURL());
1663 if (doRegisterPackage) {
1665 css::uno::Reference< css::uno::XComponentContext > context(
1666 that->getObject(url), css::uno::UNO_QUERY);
1667 if (!context.is()) {
1672 that->getComponentContext(), abortChannel)),
1673 css::uno::UNO_QUERY_THROW);
1677 css::uno::Sequence< css::beans::NamedValue > args
1680 {
"component-context", css::uno::makeAny(context) }
1682 css::uno::Reference< css::container::XSet > smgr(
1683 that->getRootContext()->getServiceManager(),
1684 css::uno::UNO_QUERY_THROW);
1685 smgr->insert(css::uno::makeAny(args));
1687 that->addToUnoRc(RCITEM_COMPONENTS, url, xCmdEnv);
1689 that->removeFromUnoRc(RCITEM_COMPONENTS, url, xCmdEnv);
1693 css::uno::Sequence< css::beans::NamedValue > args { {
"uri", css::uno::makeAny(
expandUnoRcUrl(url)) } };
1694 css::uno::Reference< css::container::XSet > smgr(
1695 that->getRootContext()->getServiceManager(),
1696 css::uno::UNO_QUERY_THROW);
1697 smgr->remove(css::uno::makeAny(args));
1699 that->releaseObject(url);
1700 that->revokeEntryFromDb(url);
1704 BackendImpl::ComponentsPackageImpl::ComponentsPackageImpl(
1706 OUString
const & url, OUString
const & name,
1707 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
1708 bool bRemoved, OUString
const & identifier)
1709 :
Package( myBackend, url, name, name ,
1710 xPackageType, bRemoved, identifier)
1718 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
1720 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const& args)
1722 return cppu::acquire(
new dp_registry::backend::component::BackendImpl(args, context));
const size_t count(pCandidateA->getBorderLines().size())
virtual void SAL_CALL disposing() override
Reference< registry::XSimpleRegistry > m_xNativeRDB
std::deque< OUString > m_components
OUString generateRandomPipeId()
OUString expandUnoRcTerm(OUString const &term_)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
OUString makeURL(OUString const &baseURL, OUString const &relPath_)
appends a relative path to a url.
std::deque< OUString > m_jar_typelibs
Sequence< Reference< deployment::XPackageTypeInfo > > m_typeInfos
Reference< XInterface > resolveUnoURL(OUString const &connectString, Reference< XComponentContext > const &xLocalContext, AbortChannel const *abortChannel)
static bool parse(OUString const &rMediaType, OUString &rType, OUString &rSubType, INetContentTypeParameterList *pParameters=nullptr)
Any SAL_CALL getCaughtException()
OUString m_nativeRDB_orig
std::unique_ptr< ComponentBackendDb > m_backendDb
t_string2object m_backendObjects
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString const & getPlatformString()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool readLine(OUString *res, OUString const &startingWith,::ucbhelper::Content &ucb_content, rtl_TextEncoding textenc)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
OUString m_commonRDB_orig
Reference< XComponentContext > const m_xComponentContext
Reference< io::XInputStream > createInputStream(std::vector< sal_Int8 > const &rInData)
#define TOOLS_WARN_EXCEPTION(area, stream)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool platform_fits(OUString const &platform_string)
std::deque< OUString > m_rdb_typelibs
oslProcess raiseProcess(OUString const &appURL, Sequence< OUString > const &args)
const Reference< deployment::XPackageTypeInfo > m_xRDBTypelibTypeInfo
OUString makeRcTerm(OUString const &url)
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
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)
const Reference< deployment::XPackageTypeInfo > m_xJavaTypelibTypeInfo
OUString expandUnoRcUrl(OUString const &url)
#define TOOLS_INFO_EXCEPTION(area, stream)
#define BACKEND_SERVICE_NAME
static uno::Reference< css::uno::XComponentContext > xContext
css::uno::Reference< css::ucb::XContent > get() const
const Reference< deployment::XPackageTypeInfo > m_xDynComponentTypeInfo
#define SAL_WARN_IF(condition, area, stream)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
const Reference< deployment::XPackageTypeInfo > m_xComponentsTypeInfo
std::unordered_map< OString, INetContentTypeParameter > INetContentTypeParameterList
OUString DpResId(const char *pId)
#define SAL_WARN(area, stream)
Reference< registry::XSimpleRegistry > m_xCommonRDB
const Reference< deployment::XPackageTypeInfo > m_xJavaComponentTypeInfo
void writeStream(const css::uno::Reference< css::io::XInputStream > &rStream, bool bReplaceExisting)
OUString expandMacros(OUString const &text)
OUString const m_aPlatform
void set(css::uno::UnoInterfaceReference const &value)
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_xPythonComponentTypeInfo
::osl::Mutex & getMutex()