LCOV - code coverage report
Current view: top level - cppuhelper/source - paths.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 35 42 83.3 %
Date: 2014-04-14 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <config_features.h>
      21             : #include <config_folders.h>
      22             : 
      23             : #include "sal/config.h"
      24             : 
      25             : #include <cassert>
      26             : 
      27             : #include "com/sun/star/uno/DeploymentException.hpp"
      28             : #include "com/sun/star/uno/Reference.hxx"
      29             : #include "com/sun/star/uno/XInterface.hpp"
      30             : #include "osl/file.hxx"
      31             : #include "osl/module.hxx"
      32             : #include "osl/mutex.hxx"
      33             : #include "rtl/ustring.hxx"
      34             : #include "sal/types.h"
      35             : 
      36             : #include "paths.hxx"
      37             : 
      38             : namespace {
      39             : 
      40       42507 : rtl::OUString get_this_libpath() {
      41       42507 :     static rtl::OUString s_uri;
      42       42507 :     if (s_uri.isEmpty()) {
      43       42506 :         rtl::OUString uri;
      44             :         osl::Module::getUrlFromAddress(
      45       42506 :             reinterpret_cast< oslGenericFunction >(get_this_libpath), uri);
      46       42506 :         sal_Int32 i = uri.lastIndexOf('/');
      47       42506 :         if (i == -1) {
      48             :             throw css::uno::DeploymentException(
      49           0 :                 "URI " + uri + " is expected to contain a slash",
      50           0 :                 css::uno::Reference< css::uno::XInterface >());
      51             :         }
      52       42506 :         uri = uri.copy(0, i);
      53       85012 :         osl::MutexGuard guard(osl::Mutex::getGlobalMutex());
      54       42506 :         if (s_uri.isEmpty()) {
      55       42506 :             s_uri = uri;
      56       42506 :         }
      57             :     }
      58       42507 :     return s_uri;
      59             : }
      60             : 
      61             : }
      62             : 
      63       42507 : rtl::OUString cppu::getUnoIniUri() {
      64             : #if defined ANDROID
      65             :     // Wouldn't it be lovely to avoid this fugly hard-coding.
      66             :     // The problem is that the 'create_bootstrap_macro_expander_factory()'
      67             :     // required for bootstrapping services, calls cppu::get_unorc directly
      68             :     // instead of re-using the BoostrapHandle from:
      69             :     //     defaultBootstrap_InitialComponentContext
      70             :     // and since rtlBootstrapHandle is not ref-counted doing anything
      71             :     // clean here is hardish.
      72             :     rtl::OUString uri("file:///assets/program");
      73             : #else
      74       42507 :     rtl::OUString uri(get_this_libpath());
      75             : #if HAVE_FEATURE_MACOSX_MACLIKE_APP_STRUCTURE
      76             :     // We keep both the LO and URE dylibs direcly in "Frameworks"
      77             :     // (that is, LIBO_LIB_FOLDER) and rc files in "Resources"
      78             :     // (LIBO_ETC_FOLDER). Except for unorc, of which there are two,
      79             :     // the "LO" one (which is in "Resources") and the "URE" one (which
      80             :     // is in "Resources/ure/etc" (LIBO_URE_ETC_FOLDER)). As this code
      81             :     // goes into the cppuhelper library which is part of URE, we are
      82             :     // looking for the latter one here. I think...
      83             :     if (uri.endsWith( "/" LIBO_LIB_FOLDER ) )
      84             :     {
      85             :         uri = uri.copy( 0, uri.getLength() - (sizeof(LIBO_LIB_FOLDER)-1) ) + LIBO_URE_ETC_FOLDER;
      86             :     }
      87             : #endif
      88             : #endif
      89       42507 :     return uri + "/" SAL_CONFIGFILE("uno");
      90             : }
      91             : 
      92           7 : bool cppu::nextDirectoryItem(osl::Directory & directory, rtl::OUString * url) {
      93             :     assert(url != 0);
      94             :     for (;;) {
      95           7 :         osl::DirectoryItem i;
      96           7 :         switch (directory.getNextItem(i, SAL_MAX_UINT32)) {
      97             :         case osl::FileBase::E_None:
      98           5 :             break;
      99             :         case osl::FileBase::E_NOENT:
     100           2 :             return false;
     101             :         default:
     102             :             throw css::uno::DeploymentException(
     103             :                 "Cannot iterate directory",
     104           0 :                 css::uno::Reference< css::uno::XInterface >());
     105             :         }
     106             :         osl::FileStatus stat(
     107             :             osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName |
     108           5 :             osl_FileStatus_Mask_FileURL);
     109           5 :         if (i.getFileStatus(stat) != osl::FileBase::E_None) {
     110             :             throw css::uno::DeploymentException(
     111             :                 "Cannot stat in directory",
     112           0 :                 css::uno::Reference< css::uno::XInterface >());
     113             :         }
     114           5 :         if (stat.getFileType() != osl::FileStatus::Directory) { //TODO: symlinks
     115             :             // Ignore backup files:
     116           5 :             rtl::OUString name(stat.getFileName());
     117           5 :             if (!(name.match(".") || name.endsWith("~"))) {
     118           5 :                 *url = stat.getFileURL();
     119           5 :                 return true;
     120           0 :             }
     121             :         }
     122           0 :     }
     123             : }
     124             : 
     125           4 : void cppu::decodeRdbUri(rtl::OUString * uri, bool * optional, bool * directory)
     126             : {
     127             :     assert(uri != 0 && optional != 0 && directory != 0);
     128           4 :     *optional = (*uri)[0] == '?';
     129           4 :     if (*optional) {
     130           0 :         *uri = uri->copy(1);
     131             :     }
     132           4 :     *directory = uri->startsWith("<") && uri->endsWith(">*");
     133           4 :     if (*directory) {
     134           2 :         *uri = uri->copy(1, uri->getLength() - 3);
     135             :     }
     136           4 : }
     137             : 
     138             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10