LCOV - code coverage report
Current view: top level - cppuhelper/source - servicefactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 144 212 67.9 %
Date: 2012-08-25 Functions: 10 10 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 174 489 35.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <vector>
      31                 :            : 
      32                 :            : #include "rtl/string.hxx"
      33                 :            : #include "rtl/bootstrap.hxx"
      34                 :            : #include "rtl/strbuf.hxx"
      35                 :            : #include "osl/diagnose.h"
      36                 :            : #include "osl/file.h"
      37                 :            : #include "osl/module.h"
      38                 :            : #include "osl/process.h"
      39                 :            : #include "cppuhelper/shlib.hxx"
      40                 :            : #include "cppuhelper/factory.hxx"
      41                 :            : #include "cppuhelper/component_context.hxx"
      42                 :            : #include "cppuhelper/servicefactory.hxx"
      43                 :            : #include "cppuhelper/bootstrap.hxx"
      44                 :            : 
      45                 :            : #include "com/sun/star/uno/DeploymentException.hpp"
      46                 :            : #include "com/sun/star/uno/XComponentContext.hpp"
      47                 :            : #include "com/sun/star/lang/XInitialization.hpp"
      48                 :            : #include <com/sun/star/lang/XServiceInfo.hpp>
      49                 :            : #include "com/sun/star/lang/XSingleServiceFactory.hpp"
      50                 :            : #include "com/sun/star/lang/XSingleComponentFactory.hpp"
      51                 :            : #include "com/sun/star/beans/XPropertySet.hpp"
      52                 :            : #include "com/sun/star/container/XSet.hpp"
      53                 :            : #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
      54                 :            : #include "com/sun/star/registry/XSimpleRegistry.hpp"
      55                 :            : #include "com/sun/star/registry/XImplementationRegistration.hpp"
      56                 :            : #include "com/sun/star/security/XAccessController.hpp"
      57                 :            : #if OSL_DEBUG_LEVEL > 1
      58                 :            : #include <stdio.h>
      59                 :            : #endif
      60                 :            : 
      61                 :            : #include "macro_expander.hxx"
      62                 :            : #include "paths.hxx"
      63                 :            : #include "servicefactory_detail.hxx"
      64                 :            : 
      65                 :            : #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
      66                 :            : 
      67                 :            : 
      68                 :            : using namespace ::rtl;
      69                 :            : using namespace ::osl;
      70                 :            : using namespace ::com::sun::star;
      71                 :            : using namespace ::com::sun::star::uno;
      72                 :            : namespace css = com::sun::star;
      73                 :            : 
      74                 :            : namespace cppu
      75                 :            : {
      76                 :            : 
      77                 :            : Reference< security::XAccessController >
      78                 :            : createDefaultAccessController() SAL_THROW(());
      79                 :            : 
      80                 :       1963 : static Reference< XInterface > SAL_CALL createInstance(
      81                 :            :     Reference< XInterface > const & xFactory,
      82                 :            :     Reference< XComponentContext > const & xContext =
      83                 :            :     Reference< XComponentContext >() )
      84                 :            : {
      85         [ +  - ]:       1963 :     Reference< lang::XSingleComponentFactory > xFac( xFactory, UNO_QUERY );
      86         [ +  - ]:       1963 :     if (xFac.is())
      87                 :            :     {
      88 [ +  - ][ +  - ]:       1963 :         return xFac->createInstanceWithContext( xContext );
      89                 :            :     }
      90                 :            :     else
      91                 :            :     {
      92         [ #  # ]:          0 :         Reference< lang::XSingleServiceFactory > xFac2( xFactory, UNO_QUERY );
      93         [ #  # ]:          0 :         if (xFac2.is())
      94                 :            :         {
      95                 :            :             OSL_ENSURE( !xContext.is(), "### ignoring context!" );
      96 [ #  # ][ #  # ]:          0 :             return xFac2->createInstance();
      97         [ #  # ]:          0 :         }
      98                 :            :     }
      99                 :            :     throw RuntimeException(
     100                 :            :         OUSTR("no factory object given!"),
     101 [ #  # ][ #  # ]:       1963 :         Reference< XInterface >() );
     102                 :            : }
     103                 :            : 
     104                 :        803 : Reference< registry::XSimpleRegistry > SAL_CALL createSimpleRegistry(
     105                 :            :     OUString const & rBootstrapPath )
     106                 :            :     SAL_THROW(())
     107                 :            : {
     108                 :            :     try
     109                 :            :     {
     110                 :            :         return Reference< registry::XSimpleRegistry >(
     111                 :            :             createInstance(
     112                 :            :                 loadSharedLibComponentFactory(
     113                 :            :                     OUSTR("bootstrap.uno" SAL_DLLEXTENSION),
     114                 :        803 :                     rBootstrapPath.isEmpty()
     115                 :            :                     ? get_this_libpath() : rBootstrapPath,
     116                 :            :                     OUSTR("com.sun.star.comp.stoc.SimpleRegistry"),
     117                 :            :                     Reference< lang::XMultiServiceFactory >(),
     118                 :            :                     Reference< registry::XRegistryKey >() ) ),
     119   [ +  -  +  - ]:       1606 :             UNO_QUERY );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     120                 :            :     }
     121                 :          0 :     catch (Exception & exc)
     122                 :            :     {
     123                 :            : #if OSL_DEBUG_LEVEL > 0
     124                 :            :         OString cstr_msg(
     125                 :            :             OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
     126                 :            :         OSL_ENSURE( !"### exception occurred:", cstr_msg.getStr() );
     127                 :            : #else
     128                 :            :         (void) exc; // avoid warning about unused variable
     129                 :            : #endif
     130                 :            :     }
     131                 :            : 
     132                 :          0 :     return Reference< registry::XSimpleRegistry >();
     133                 :            : }
     134                 :            : 
     135                 :        404 : Reference< registry::XSimpleRegistry > SAL_CALL createNestedRegistry(
     136                 :            :     OUString const & rBootstrapPath )
     137                 :            :     SAL_THROW(())
     138                 :            : {
     139                 :            :     try
     140                 :            :     {
     141                 :            :         return Reference< registry::XSimpleRegistry >(
     142                 :            :             createInstance(
     143                 :            :                 loadSharedLibComponentFactory(
     144                 :            :                     OUSTR("bootstrap.uno" SAL_DLLEXTENSION),
     145                 :        404 :                     rBootstrapPath.isEmpty()
     146                 :            :                     ? get_this_libpath() : rBootstrapPath,
     147                 :            :                     OUSTR("com.sun.star.comp.stoc.NestedRegistry"),
     148                 :            :                     Reference< lang::XMultiServiceFactory >(),
     149                 :            :                     Reference< registry::XRegistryKey >() ) ),
     150   [ +  -  +  - ]:        808 :             UNO_QUERY );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     151                 :            :     }
     152                 :          0 :     catch (Exception & exc)
     153                 :            :     {
     154                 :            : #if OSL_DEBUG_LEVEL > 0
     155                 :            :         OString cstr_msg(
     156                 :            :             OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
     157                 :            :         OSL_ENSURE( !"### exception occurred:", cstr_msg.getStr() );
     158                 :            : #else
     159                 :            :         (void) exc; // avoid warning about unused variable
     160                 :            : #endif
     161                 :            :     }
     162                 :            : 
     163                 :          0 :     return Reference< registry::XSimpleRegistry >();
     164                 :            : }
     165                 :            : 
     166                 :            : 
     167                 :            : /** bootstrap variables:
     168                 :            : 
     169                 :            :     UNO_AC=<mode> [mandatory]
     170                 :            :       -- mode := { on, off, dynamic-only, single-user, single-default-user }
     171                 :            :     UNO_AC_SERVICE=<service_name> [optional]
     172                 :            :       -- override ac singleton service name
     173                 :            :     UNO_AC_SINGLEUSER=<user-id|nothing> [optional]
     174                 :            :       -- run with this user id or with default user policy (<nothing>)
     175                 :            :          set UNO_AC=single-[default-]user
     176                 :            :     UNO_AC_USERCACHE_SIZE=<cache_size>
     177                 :            :       -- number of user permission sets to be cached
     178                 :            : 
     179                 :            :     UNO_AC_POLICYSERVICE=<service_name> [optional]
     180                 :            :       -- override policy singleton service name
     181                 :            :     UNO_AC_POLICYFILE=<file_url> [optional]
     182                 :            :       -- read policy out of simple text file
     183                 :            : */
     184                 :        756 : void add_access_control_entries(
     185                 :            :     ::std::vector< ContextEntry_Init > * values,
     186                 :            :     Bootstrap const & bootstrap )
     187                 :            :     SAL_THROW( (Exception) )
     188                 :            : {
     189                 :        756 :     ContextEntry_Init entry;
     190                 :        756 :     ::std::vector< ContextEntry_Init > & context_values = *values;
     191                 :            : 
     192                 :        756 :     OUString ac_policy;
     193 [ -  + ][ +  - ]:        756 :     if (bootstrap.getFrom( OUSTR("UNO_AC_POLICYSERVICE"), ac_policy ))
     194                 :            :     {
     195                 :            :         // overridden service name
     196                 :            :         // - policy singleton
     197                 :          0 :         entry.bLateInitService = true;
     198         [ #  # ]:          0 :         entry.name = OUSTR("/singletons/com.sun.star.security.thePolicy");
     199         [ #  # ]:          0 :         entry.value <<= ac_policy;
     200         [ #  # ]:          0 :         context_values.push_back( entry );
     201                 :            :     }
     202 [ +  - ][ -  + ]:        756 :     else if (bootstrap.getFrom( OUSTR("UNO_AC_POLICYFILE"), ac_policy ))
     203                 :            :     {
     204                 :            :         // check for file policy
     205                 :            :         // - file policy prop: file-name
     206         [ #  # ]:          0 :         if (0 != ac_policy.compareToAscii(
     207                 :          0 :                 RTL_CONSTASCII_STRINGPARAM("file:///") ))
     208                 :            :         {
     209                 :            :             // no file url
     210                 :          0 :             OUString baseDir;
     211         [ #  # ]:          0 :             if ( ::osl_getProcessWorkingDir( &baseDir.pData )
     212                 :            :                  != osl_Process_E_None )
     213                 :            :             {
     214                 :            :                 OSL_ASSERT( false );
     215                 :            :             }
     216                 :          0 :             OUString fileURL;
     217                 :          0 :             if ( ::osl_getAbsoluteFileURL(
     218         [ #  # ]:          0 :                      baseDir.pData, ac_policy.pData, &fileURL.pData )
     219                 :            :                  != osl_File_E_None )
     220                 :            :             {
     221                 :            :                 OSL_ASSERT( false );
     222                 :            :             }
     223                 :          0 :             ac_policy = fileURL;
     224                 :            :         }
     225                 :            : 
     226                 :          0 :         entry.bLateInitService = false;
     227                 :            :         entry.name =
     228         [ #  # ]:          0 :             OUSTR("/implementations/com.sun.star.security.comp.stoc.FilePolicy/"
     229                 :          0 :                   "file-name");
     230         [ #  # ]:          0 :         entry.value <<= ac_policy;
     231         [ #  # ]:          0 :         context_values.push_back( entry );
     232                 :            :         // - policy singleton
     233                 :          0 :         entry.bLateInitService = true;
     234         [ #  # ]:          0 :         entry.name = OUSTR("/singletons/com.sun.star.security.thePolicy");
     235 [ #  # ][ #  # ]:          0 :         entry.value <<= OUSTR("com.sun.star.security.comp.stoc.FilePolicy");
     236         [ #  # ]:          0 :         context_values.push_back( entry );
     237                 :            :     } // else policy singleton comes from storage
     238                 :            : 
     239                 :        756 :     OUString ac_mode;
     240 [ +  - ][ +  - ]:        756 :     if (! bootstrap.getFrom( OUSTR("UNO_AC"), ac_mode ))
     241                 :            :     {
     242         [ +  - ]:        756 :         ac_mode = OUSTR("off"); // default
     243                 :            :     }
     244                 :        756 :     OUString ac_user;
     245 [ -  + ][ +  - ]:        756 :     if (bootstrap.getFrom( OUSTR("UNO_AC_SINGLEUSER"), ac_user ))
     246                 :            :     {
     247                 :            :         // ac in single-user mode
     248         [ #  # ]:          0 :         if (!ac_user.isEmpty())
     249                 :            :         {
     250                 :            :             // - ac prop: single-user-id
     251                 :          0 :             entry.bLateInitService = false;
     252                 :            :             entry.name =
     253         [ #  # ]:          0 :                 OUSTR("/services/com.sun.star.security.AccessController/"
     254                 :          0 :                       "single-user-id");
     255         [ #  # ]:          0 :             entry.value <<= ac_user;
     256         [ #  # ]:          0 :             context_values.push_back( entry );
     257         [ #  # ]:          0 :             if ( ac_mode != "single-user" )
     258                 :            :             {
     259                 :            :                 throw SecurityException(
     260                 :            :                     OUSTR("set UNO_AC=single-user "
     261                 :            :                           "if you set UNO_AC_SINGLEUSER=<user-id>!"),
     262 [ #  # ][ #  # ]:          0 :                     Reference< XInterface >() );
     263                 :            :             }
     264                 :            :         }
     265                 :            :         else
     266                 :            :         {
     267         [ #  # ]:          0 :             if ( ac_mode != "single-default-user" )
     268                 :            :             {
     269                 :            :                 throw SecurityException(
     270                 :            :                     OUSTR("set UNO_AC=single-default-user "
     271                 :            :                           "if you set UNO_AC_SINGLEUSER=<nothing>!"),
     272 [ #  # ][ #  # ]:          0 :                     Reference< XInterface >() );
     273                 :            :             }
     274                 :            :         }
     275                 :            :     }
     276                 :            : 
     277                 :        756 :     OUString ac_service;
     278 [ +  - ][ +  - ]:        756 :     if (! bootstrap.getFrom( OUSTR("UNO_AC_SERVICE"), ac_service ))
     279                 :            :     {
     280                 :            :         // override service name
     281         [ +  - ]:        756 :         ac_service = OUSTR("com.sun.star.security.AccessController"); // default
     282                 :            : //          ac = OUSTR("com.sun.star.security.comp.stoc.AccessController");
     283                 :            :     }
     284                 :            : 
     285                 :            :     // - ac prop: user-cache-size
     286                 :        756 :     OUString ac_cache;
     287 [ -  + ][ +  - ]:        756 :     if (bootstrap.getFrom( OUSTR("UNO_AC_USERCACHE_SIZE"), ac_cache ))
     288                 :            :     {
     289                 :            :         // ac cache size
     290                 :          0 :         sal_Int32 n = ac_cache.toInt32();
     291         [ #  # ]:          0 :         if (0 < n)
     292                 :            :         {
     293                 :          0 :             entry.bLateInitService = false;
     294                 :            :             entry.name =
     295         [ #  # ]:          0 :                 OUSTR("/services/com.sun.star.security.AccessController/"
     296                 :          0 :                       "user-cache-size");
     297         [ #  # ]:          0 :             entry.value <<= n;
     298         [ #  # ]:          0 :             context_values.push_back( entry );
     299                 :            :         }
     300                 :            :     }
     301                 :            : 
     302                 :            :     // - ac prop: mode
     303                 :            :     // { "off", "on", "dynamic-only", "single-user", "single-default-user" }
     304                 :        756 :     entry.bLateInitService = false;
     305         [ +  - ]:        756 :     entry.name = OUSTR("/services/com.sun.star.security.AccessController/mode");
     306         [ +  - ]:        756 :     entry.value <<= ac_mode;
     307         [ +  - ]:        756 :     context_values.push_back( entry );
     308                 :            :     // - ac singleton
     309                 :        756 :     entry.bLateInitService = true;
     310         [ +  - ]:        756 :     entry.name = OUSTR("/singletons/com.sun.star.security.theAccessController");
     311         [ +  - ]:        756 :     entry.value <<= ac_service;
     312         [ +  - ]:        756 :     context_values.push_back( entry );
     313                 :        756 : }
     314                 :            : 
     315                 :            : namespace {
     316                 :        756 : void addFactories(
     317                 :            :     char const * const * ppNames /* implname, ..., 0 */,
     318                 :            :     OUString const & bootstrapPath,
     319                 :            :     Reference< lang::XMultiComponentFactory > const & xMgr,
     320                 :            :     Reference< registry::XRegistryKey > const & xKey )
     321                 :            :     SAL_THROW( (Exception) )
     322                 :            : {
     323         [ +  - ]:        756 :     Reference< container::XSet > xSet( xMgr, UNO_QUERY );
     324                 :            :     OSL_ASSERT( xSet.is() );
     325         [ +  - ]:        756 :     Reference< lang::XMultiServiceFactory > xSF( xMgr, UNO_QUERY );
     326                 :            : 
     327         [ +  + ]:       6804 :     while (*ppNames)
     328                 :            :     {
     329                 :       6048 :         OUString implName( OUString::createFromAscii( *ppNames++ ) );
     330                 :            : 
     331                 :            :         Any aFac( makeAny( loadSharedLibComponentFactory(
     332                 :            :                                OUSTR("bootstrap.uno" SAL_DLLEXTENSION),
     333 [ +  - ][ +  - ]:       6048 :                                bootstrapPath, implName, xSF, xKey ) ) );
                 [ +  - ]
     334 [ +  - ][ +  - ]:       6048 :         xSet->insert( aFac );
     335                 :            : #if OSL_DEBUG_LEVEL > 1
     336                 :            :         if (xSet->has( aFac ))
     337                 :            :         {
     338                 :            :             Reference< lang::XServiceInfo > xInfo;
     339                 :            :             if (aFac >>= xInfo)
     340                 :            :             {
     341                 :            :                 ::fprintf(
     342                 :            :                     stderr, "> implementation %s supports: ", ppNames[ -1 ] );
     343                 :            :                 Sequence< OUString > supported(
     344                 :            :                     xInfo->getSupportedServiceNames() );
     345                 :            :                 for ( sal_Int32 nPos = supported.getLength(); nPos--; )
     346                 :            :                 {
     347                 :            :                     OString str( OUStringToOString(
     348                 :            :                         supported[ nPos ], RTL_TEXTENCODING_ASCII_US ) );
     349                 :            :                     ::fprintf( stderr, nPos ? "%s, " : "%s\n", str.getStr() );
     350                 :            :                 }
     351                 :            :             }
     352                 :            :             else
     353                 :            :             {
     354                 :            :                 ::fprintf(
     355                 :            :                     stderr,
     356                 :            :                     "> implementation %s provides NO lang::XServiceInfo!!!\n",
     357                 :            :                     ppNames[ -1 ] );
     358                 :            :             }
     359                 :            :         }
     360                 :            : #endif
     361                 :            : #if OSL_DEBUG_LEVEL > 0
     362                 :            :         if (! xSet->has( aFac ))
     363                 :            :         {
     364                 :            :             OStringBuffer buf( 64 );
     365                 :            :             buf.append( "### failed inserting shared lib \"" );
     366                 :            :             buf.append( "bootstrap.uno" SAL_DLLEXTENSION );
     367                 :            :             buf.append( "\"!!!" );
     368                 :            :             OString str( buf.makeStringAndClear() );
     369                 :            :             OSL_FAIL( str.getStr() );
     370                 :            :         }
     371                 :            : #endif
     372                 :       6804 :     }
     373                 :        756 : }
     374                 :            : 
     375                 :            : } // namespace
     376                 :            : 
     377                 :        756 : Reference< lang::XMultiComponentFactory > bootstrapInitialSF(
     378                 :            :     OUString const & rBootstrapPath )
     379                 :            :     SAL_THROW( (Exception) )
     380                 :            : {
     381                 :            :     OUString const & bootstrap_path =
     382         [ +  + ]:        756 :         rBootstrapPath.isEmpty() ? get_this_libpath() : rBootstrapPath;
     383                 :            : 
     384                 :            :     Reference< lang::XMultiComponentFactory > xMgr(
     385                 :            :         createInstance(
     386                 :            :             loadSharedLibComponentFactory(
     387                 :            :                 OUSTR("bootstrap.uno" SAL_DLLEXTENSION), bootstrap_path,
     388                 :            :                 OUSTR("com.sun.star.comp.stoc.ORegistryServiceManager"),
     389                 :            :                 Reference< lang::XMultiServiceFactory >(),
     390                 :            :                 Reference< registry::XRegistryKey >() ) ),
     391 [ +  - ][ +  - ]:        756 :         UNO_QUERY );
         [ +  - ][ +  - ]
                 [ +  - ]
     392                 :            : 
     393                 :            :     // add initial bootstrap services
     394                 :            :     static char const * ar[] = {
     395                 :            :         "com.sun.star.comp.stoc.OServiceManagerWrapper",
     396                 :            :         "com.sun.star.comp.stoc.DLLComponentLoader",
     397                 :            :         "com.sun.star.comp.stoc.SimpleRegistry",
     398                 :            :         "com.sun.star.comp.stoc.NestedRegistry",
     399                 :            :         "com.sun.star.comp.stoc.TypeDescriptionManager",
     400                 :            :         "com.sun.star.comp.stoc.ImplementationRegistration",
     401                 :            :         "com.sun.star.security.comp.stoc.AccessController",
     402                 :            :         "com.sun.star.security.comp.stoc.FilePolicy",
     403                 :            :         0
     404                 :            :     };
     405                 :            :     addFactories(
     406                 :            :         ar, bootstrap_path,
     407         [ +  - ]:        756 :         xMgr, Reference< registry::XRegistryKey >() );
     408                 :            : 
     409                 :        756 :     return xMgr;
     410                 :            : }
     411                 :            : 
     412                 :            : // returns context with UNinitialized smgr
     413                 :        399 : Reference< XComponentContext > bootstrapInitialContext(
     414                 :            :     Reference< lang::XMultiComponentFactory > const & xSF,
     415                 :            :     Reference< registry::XSimpleRegistry > const & types_xRegistry,
     416                 :            :     Reference< registry::XSimpleRegistry > const & services_xRegistry,
     417                 :            :     OUString const & rBootstrapPath, Bootstrap const & bootstrap )
     418                 :            :     SAL_THROW( (Exception) )
     419                 :            : {
     420         [ +  - ]:        399 :     Reference< lang::XInitialization > xSFInit( xSF, UNO_QUERY );
     421         [ -  + ]:        399 :     if (! xSFInit.is())
     422                 :            :     {
     423                 :            :         throw RuntimeException(
     424                 :            :             OUSTR("servicemanager does not support XInitialization!"),
     425 [ #  # ][ #  # ]:          0 :             Reference< XInterface >() );
     426                 :            :     }
     427                 :            : 
     428                 :            :     // basic context values
     429                 :        399 :     ContextEntry_Init entry;
     430         [ +  - ]:        399 :     ::std::vector< ContextEntry_Init > context_values;
     431         [ +  - ]:        399 :     context_values.reserve( 14 );
     432                 :            : 
     433                 :            :     // macro expander singleton for loader
     434                 :        399 :     entry.bLateInitService = true;
     435         [ +  - ]:        399 :     entry.name = OUSTR("/singletons/com.sun.star.util.theMacroExpander");
     436                 :            :     entry.value
     437 [ +  - ][ +  - ]:        399 :         <<= cppuhelper::detail::create_bootstrap_macro_expander_factory();
     438         [ +  - ]:        399 :     context_values.push_back( entry );
     439                 :            : 
     440                 :            :     // tdmgr singleton
     441                 :        399 :     entry.bLateInitService = true;
     442                 :            :     entry.name =
     443         [ +  - ]:        399 :         OUSTR("/singletons/com.sun.star.reflection.theTypeDescriptionManager");
     444 [ +  - ][ +  - ]:        399 :     entry.value <<= OUSTR("com.sun.star.comp.stoc.TypeDescriptionManager");
     445         [ +  - ]:        399 :     context_values.push_back( entry );
     446                 :            : 
     447                 :            :     // read out singleton infos from registry
     448         [ +  - ]:        399 :     if (services_xRegistry.is())
     449                 :            :     {
     450                 :            :         Reference< registry::XRegistryKey > xKey(
     451 [ +  - ][ +  - ]:        399 :             services_xRegistry->getRootKey() );
     452         [ +  - ]:        399 :         if (xKey.is())
     453                 :            :         {
     454 [ +  - ][ +  - ]:        399 :             xKey = xKey->openKey( OUSTR("/SINGLETONS") );
         [ +  - ][ +  - ]
     455         [ +  - ]:        399 :             if (xKey.is())
     456                 :            :             {
     457                 :        399 :                 entry.bLateInitService = true;
     458                 :            : 
     459                 :            :                 Sequence< Reference< registry::XRegistryKey > > keys(
     460 [ +  - ][ +  - ]:        399 :                     xKey->openKeys() );
     461                 :            :                 Reference< registry::XRegistryKey > const * pKeys =
     462                 :        399 :                     keys.getConstArray();
     463         [ -  + ]:        399 :                 for ( sal_Int32 nPos = keys.getLength(); nPos--; )
     464                 :            :                 {
     465                 :            :                     css::uno::Sequence< rtl::OUString > impls(
     466                 :            :                         css::uno::Reference< css::registry::XRegistryKey >(
     467         [ #  # ]:          0 :                             pKeys[nPos]->openKey(
     468                 :            :                                 rtl::OUString(
     469                 :            :                                     RTL_CONSTASCII_USTRINGPARAM(
     470                 :          0 :                                         "REGISTERED_BY"))),
     471 [ #  # ][ #  # ]:          0 :                             css::uno::UNO_SET_THROW)->getAsciiListValue());
         [ #  # ][ #  # ]
                 [ #  # ]
     472      [ #  #  # ]:          0 :                     switch (impls.getLength()) {
     473                 :            :                     case 0:
     474                 :            :                         throw css::uno::DeploymentException(
     475         [ #  # ]:          0 :                             (pKeys[nPos]->getKeyName() +
     476                 :            :                              rtl::OUString(
     477                 :            :                                  RTL_CONSTASCII_USTRINGPARAM(
     478                 :            :                                      "/REGISTERED_BY is empty"))),
     479 [ #  # ][ #  # ]:          0 :                             css::uno::Reference< css::uno::XInterface >());
                 [ #  # ]
     480                 :            :                     case 1:
     481                 :          0 :                         break;
     482                 :            :                     default:
     483                 :            :                         OSL_TRACE(
     484                 :            :                             ("arbitrarily chosing \"%s\" among multiple"
     485                 :            :                              " implementations for \"%s\""),
     486                 :            :                             rtl::OUStringToOString(
     487                 :            :                                 impls[0], RTL_TEXTENCODING_UTF8).getStr(),
     488                 :            :                             rtl::OUStringToOString(
     489                 :            :                                 pKeys[nPos]->getKeyName(),
     490                 :            :                                 RTL_TEXTENCODING_UTF8).getStr());
     491                 :          0 :                         break;
     492                 :            :                     }
     493                 :            :                     context_values.push_back(
     494                 :            :                         ContextEntry_Init(
     495                 :            :                             (rtl::OUString(
     496                 :            :                                 RTL_CONSTASCII_USTRINGPARAM("/singletons/")) +
     497         [ #  # ]:          0 :                              pKeys[nPos]->getKeyName().copy(
     498                 :            :                                  RTL_CONSTASCII_LENGTH("/SINGLETONS/"))),
     499         [ #  # ]:          0 :                             css::uno::makeAny(impls[0]),
     500 [ #  # ][ #  # ]:          0 :                             true));
         [ #  # ][ #  # ]
     501 [ +  - ][ #  # ]:        399 :                 }
     502                 :            :             }
     503                 :        399 :         }
     504                 :            :     }
     505                 :            : 
     506                 :            :     // ac, policy:
     507         [ +  - ]:        399 :     add_access_control_entries( &context_values, bootstrap );
     508                 :            : 
     509                 :            :     // smgr singleton
     510                 :        399 :     entry.bLateInitService = false;
     511         [ +  - ]:        399 :     entry.name = OUSTR("/singletons/com.sun.star.lang.theServiceManager");
     512         [ +  - ]:        399 :     entry.value <<= xSF;
     513         [ +  - ]:        399 :     context_values.push_back( entry );
     514                 :            : 
     515                 :            :     Reference< XComponentContext > xContext(
     516                 :            :         createComponentContext(
     517                 :        399 :             &context_values[ 0 ], context_values.size(),
     518         [ +  - ]:        798 :             Reference< XComponentContext >() ) );
     519                 :            :     // set default context
     520         [ +  - ]:        399 :     Reference< beans::XPropertySet > xProps( xSF, UNO_QUERY );
     521                 :            :     OSL_ASSERT( xProps.is() );
     522         [ +  - ]:        399 :     if (xProps.is())
     523                 :            :     {
     524         [ +  - ]:        399 :         xProps->setPropertyValue(
     525 [ +  - ][ +  - ]:        399 :             OUSTR("DefaultContext"), makeAny( xContext ) );
                 [ +  - ]
     526                 :            :     }
     527                 :            : 
     528                 :        399 :     Reference< container::XHierarchicalNameAccess > xTDMgr;
     529                 :            : 
     530                 :            :     // get tdmgr singleton
     531   [ +  -  +  - ]:        798 :     if (xContext->getValueByName(
     532                 :            :             OUSTR("/singletons/"
     533                 :        399 :                   "com.sun.star.reflection.theTypeDescriptionManager") )
     534 [ +  - ][ +  - ]:        399 :         >>= xTDMgr)
                 [ +  - ]
     535                 :            :     {
     536         [ +  - ]:        399 :         if (types_xRegistry.is()) // insert rdb provider?
     537                 :            :         {
     538                 :            :             // add registry td provider factory to smgr and instance to tdmgr
     539                 :            :             Reference< lang::XSingleComponentFactory > xFac(
     540                 :            :                 loadSharedLibComponentFactory(
     541                 :            :                     OUSTR("bootstrap.uno" SAL_DLLEXTENSION),
     542                 :        399 :                     rBootstrapPath.isEmpty()
     543                 :            :                     ? get_this_libpath() : rBootstrapPath,
     544                 :            :                 OUSTR("com.sun.star.comp.stoc.RegistryTypeDescriptionProvider"),
     545                 :            :                 Reference< lang::XMultiServiceFactory >( xSF, UNO_QUERY ),
     546         [ +  - ]:        798 :                 Reference< registry::XRegistryKey >() ), UNO_QUERY );
           [ +  -  +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     547                 :            :             OSL_ASSERT( xFac.is() );
     548                 :            : 
     549                 :            :             // smgr
     550         [ +  - ]:        399 :             Reference< container::XSet > xSet( xSF, UNO_QUERY );
     551 [ +  - ][ +  - ]:        399 :             xSet->insert( makeAny( xFac ) );
                 [ +  - ]
     552                 :            :             OSL_ENSURE(
     553                 :            :                 xSet->has( makeAny( xFac ) ),
     554                 :            :                 "### failed registering registry td provider at smgr!" );
     555                 :            :             // tdmgr
     556         [ +  - ]:        399 :             xSet.set( xTDMgr, UNO_QUERY );
     557                 :            :             OSL_ASSERT( xSet.is() );
     558         [ +  - ]:        399 :             Any types_RDB( makeAny( types_xRegistry ) );
     559         [ +  - ]:        399 :             Any rdbtdp( makeAny( xFac->createInstanceWithArgumentsAndContext(
     560 [ +  - ][ +  - ]:        399 :                 Sequence< Any >( &types_RDB, 1 ), xContext ) ) );
         [ +  - ][ +  - ]
     561 [ +  - ][ +  - ]:        399 :             xSet->insert( rdbtdp );
     562                 :            :             OSL_ENSURE(
     563                 :            :                 xSet->has( rdbtdp ),
     564                 :        399 :                 "### failed inserting registry td provider to tdmgr!" );
     565                 :            :         }
     566                 :            :         // install callback
     567         [ +  - ]:        399 :         installTypeDescriptionManager( xTDMgr );
     568                 :            :     }
     569                 :            : 
     570                 :        399 :     return xContext;
     571                 :            : }
     572                 :            : 
     573                 :        394 : static Reference< lang::XMultiComponentFactory > createImplServiceFactory(
     574                 :            :     const OUString & rWriteRegistry,
     575                 :            :     const OUString & rReadRegistry,
     576                 :            :     sal_Bool bReadOnly,
     577                 :            :     const OUString & rBootstrapPath )
     578                 :            :     SAL_THROW( (Exception) )
     579                 :            : {
     580                 :            :     Reference< lang::XMultiComponentFactory > xSF(
     581         [ +  - ]:        394 :         bootstrapInitialSF( rBootstrapPath ) );
     582                 :            : 
     583                 :        394 :     Reference< registry::XSimpleRegistry > xRegistry;
     584                 :            : 
     585                 :            :     // open a registry
     586                 :        394 :     sal_Bool bRegistryShouldBeValid = sal_False;
     587 [ -  + ][ -  + ]:        394 :     if (!rWriteRegistry.isEmpty() && rReadRegistry.isEmpty())
                 [ +  - ]
     588                 :            :     {
     589                 :          0 :         bRegistryShouldBeValid = sal_True;
     590 [ #  # ][ #  # ]:          0 :         xRegistry.set( createSimpleRegistry( rBootstrapPath ) );
     591         [ #  # ]:          0 :         if (xRegistry.is())
     592                 :            :         {
     593         [ #  # ]:          0 :             if (bReadOnly)
     594                 :            :             {
     595 [ #  # ][ #  # ]:          0 :                 xRegistry->open( rWriteRegistry, sal_True, sal_False );
     596                 :            :             }
     597                 :            :             else
     598                 :            :             {
     599 [ #  # ][ #  # ]:          0 :                 xRegistry->open( rWriteRegistry, sal_False, sal_True );
     600                 :            :             }
     601                 :            :         }
     602                 :            :     }
     603 [ +  - ][ +  - ]:        394 :     else if (!rWriteRegistry.isEmpty() && !rReadRegistry.isEmpty())
                 [ +  - ]
     604                 :            :     {
     605                 :            :         // default registry
     606                 :        394 :         bRegistryShouldBeValid = sal_True;
     607 [ +  - ][ +  - ]:        394 :         xRegistry.set( createNestedRegistry( rBootstrapPath ) );
                 [ #  # ]
     608                 :            : 
     609                 :            :         Reference< registry::XSimpleRegistry > xWriteReg(
     610         [ +  - ]:        394 :             createSimpleRegistry( rBootstrapPath ) );
     611         [ +  - ]:        394 :         if (xWriteReg.is())
     612                 :            :         {
     613         [ +  - ]:        394 :             if (bReadOnly)
     614                 :            :             {
     615                 :            :                 try
     616                 :            :                 {
     617 [ +  - ][ +  - ]:        394 :                     xWriteReg->open( rWriteRegistry, sal_True, sal_False );
     618                 :            :                 }
     619         [ #  # ]:          0 :                 catch (registry::InvalidRegistryException &)
     620                 :            :                 {
     621                 :            :                 }
     622                 :            : 
     623 [ +  - ][ +  - ]:        394 :                 if (! xWriteReg->isValid())
                 [ -  + ]
     624                 :            :                 {
     625                 :            :                     throw RuntimeException(
     626                 :            :                         OUSTR("specified first registry "
     627                 :            :                               "could not be open readonly!"),
     628 [ #  # ][ #  # ]:          0 :                         Reference< XInterface >() );
     629                 :            :                 }
     630                 :            :             }
     631                 :            :             else
     632                 :            :             {
     633 [ #  # ][ #  # ]:          0 :                 xWriteReg->open( rWriteRegistry, sal_False, sal_True );
     634                 :            :             }
     635                 :            :         }
     636                 :            : 
     637                 :            :         Reference< registry::XSimpleRegistry > xReadReg(
     638         [ +  - ]:        394 :             createSimpleRegistry( rBootstrapPath ) );
     639         [ +  - ]:        394 :         if (xReadReg.is())
     640                 :            :         {
     641 [ +  - ][ +  - ]:        394 :             xReadReg->open( rReadRegistry, sal_True, sal_False );
     642                 :            :         }
     643                 :            : 
     644         [ +  - ]:        394 :         Reference< lang::XInitialization > xInit( xRegistry, UNO_QUERY );
     645         [ +  - ]:        394 :         Sequence< Any > aInitSeq( 2 );
     646 [ +  - ][ +  - ]:        394 :         aInitSeq[ 0 ] <<= xWriteReg;
     647 [ +  - ][ +  - ]:        394 :         aInitSeq[ 1 ] <<= xReadReg;
     648 [ +  - ][ +  - ]:        394 :         xInit->initialize( aInitSeq );
                 [ +  - ]
     649                 :            :     }
     650                 :            : 
     651 [ +  - ][ +  - ]:        394 :     if (bRegistryShouldBeValid && (!xRegistry.is() || !xRegistry->isValid()))
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
     652                 :            :     {
     653                 :            :         throw RuntimeException(
     654                 :            :             OUSTR("specified registry could not be initialized"),
     655 [ #  # ][ #  # ]:          0 :             Reference< XInterface >() );
     656                 :            :     }
     657                 :            : 
     658                 :        394 :     Bootstrap bootstrap;
     659                 :            :     Reference< XComponentContext > xContext(
     660                 :            :         bootstrapInitialContext(
     661         [ +  - ]:        394 :             xSF, xRegistry, xRegistry, rBootstrapPath, bootstrap ) );
     662                 :            : 
     663                 :            :     // initialize sf
     664         [ +  - ]:        394 :     Reference< lang::XInitialization > xInit( xSF, UNO_QUERY );
     665                 :            :     OSL_ASSERT( xInit.is() );
     666         [ +  - ]:        394 :     Sequence< Any > aSFInit( 1 );
     667 [ +  - ][ +  - ]:        394 :     aSFInit[ 0 ] <<= xRegistry;
     668 [ +  - ][ +  - ]:        394 :     xInit->initialize( aSFInit );
     669                 :            : 
     670         [ +  - ]:        394 :     return xSF;
     671                 :            : }
     672                 :            : 
     673                 :        394 : Reference< lang::XMultiServiceFactory > SAL_CALL createRegistryServiceFactory(
     674                 :            :     const OUString & rWriteRegistry,
     675                 :            :     const OUString & rReadRegistry,
     676                 :            :     sal_Bool bReadOnly,
     677                 :            :     const OUString & rBootstrapPath )
     678                 :            :     SAL_THROW( (Exception) )
     679                 :            : {
     680                 :            :     return Reference< lang::XMultiServiceFactory >( createImplServiceFactory(
     681         [ +  - ]:        394 :         rWriteRegistry, rReadRegistry, bReadOnly, rBootstrapPath ), UNO_QUERY );
     682                 :            : }
     683                 :            : 
     684                 :          5 : Reference< XComponentContext > SAL_CALL bootstrap_InitialComponentContext(
     685                 :            :     Reference< registry::XSimpleRegistry > const & xRegistry,
     686                 :            :     OUString const & rBootstrapPath )
     687                 :            :     SAL_THROW( (Exception) )
     688                 :            : {
     689                 :          5 :     Bootstrap bootstrap;
     690                 :            : 
     691                 :            :     Reference< lang::XMultiComponentFactory > xSF(
     692         [ +  - ]:          5 :         bootstrapInitialSF( rBootstrapPath ) );
     693                 :            :     Reference< XComponentContext > xContext(
     694                 :            :         bootstrapInitialContext(
     695         [ +  - ]:          5 :             xSF, xRegistry, xRegistry, rBootstrapPath, bootstrap ) );
     696                 :            : 
     697                 :            :     // initialize sf
     698         [ +  - ]:          5 :     Reference< lang::XInitialization > xInit( xSF, UNO_QUERY );
     699                 :            :     OSL_ASSERT( xInit.is() );
     700         [ +  - ]:          5 :     Sequence< Any > aSFInit( 2 );
     701 [ +  - ][ +  - ]:          5 :     aSFInit[ 0 ] <<= xRegistry;
     702 [ +  - ][ +  - ]:          5 :     aSFInit[ 1 ] <<= xContext; // default context
     703 [ +  - ][ +  - ]:          5 :     xInit->initialize( aSFInit );
     704                 :            : 
     705         [ +  - ]:          5 :     return xContext;
     706                 :            : }
     707                 :            : 
     708                 :            : }
     709                 :            : 
     710                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10