LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/cppuhelper/source - paths.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 38 44 86.4 %
Date: 2013-07-09 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 "sal/config.h"
      21             : 
      22             : #include <cassert>
      23             : 
      24             : #include "com/sun/star/uno/DeploymentException.hpp"
      25             : #include "com/sun/star/uno/Reference.hxx"
      26             : #include "com/sun/star/uno/XInterface.hpp"
      27             : #include "osl/file.hxx"
      28             : #include "osl/module.hxx"
      29             : #include "osl/mutex.hxx"
      30             : #include "rtl/ustring.hxx"
      31             : #include "sal/types.h"
      32             : 
      33             : #include "paths.hxx"
      34             : 
      35             : namespace {
      36             : 
      37         878 : rtl::OUString get_this_libpath() {
      38         878 :     static rtl::OUString s_uri;
      39         878 :     if (s_uri.isEmpty()) {
      40         487 :         rtl::OUString uri;
      41             :         osl::Module::getUrlFromAddress(
      42         487 :             reinterpret_cast< oslGenericFunction >(get_this_libpath), uri);
      43         487 :         sal_Int32 i = uri.lastIndexOf('/');
      44         487 :         if (i == -1) {
      45             :             throw css::uno::DeploymentException(
      46           0 :                 "URI " + uri + " is expected to contain a slash",
      47           0 :                 css::uno::Reference< css::uno::XInterface >());
      48             :         }
      49         487 :         uri = uri.copy(0, i);
      50         974 :         osl::MutexGuard guard(osl::Mutex::getGlobalMutex());
      51         487 :         if (s_uri.isEmpty()) {
      52         487 :             s_uri = uri;
      53         487 :         }
      54             :     }
      55         878 :     return s_uri;
      56             : }
      57             : 
      58             : }
      59             : 
      60         878 : rtl::OUString cppu::getUnoIniUri() {
      61             : #if defined ANDROID
      62             :     // Wouldn't it be lovely to avoid this fugly hard-coding.
      63             :     // The problem is that the 'create_bootstrap_macro_expander_factory()'
      64             :     // required for bootstrapping services, calls cppu::get_unorc directly
      65             :     // instead of re-using the BoostrapHandle from:
      66             :     //     defaultBootstrap_InitialComponentContext
      67             :     // and since rtlBootstrapHandle is not ref-counted doing anything
      68             :     // clean here is hardish.
      69             :     rtl::OUString uri("file:///assets/program");
      70             : #else
      71         878 :     rtl::OUString uri(get_this_libpath());
      72             : #endif
      73         878 :     return uri + "/" SAL_CONFIGFILE("uno");
      74             : }
      75             : 
      76         850 : bool cppu::nextDirectoryItem(osl::Directory & directory, rtl::OUString * url) {
      77             :     assert(url != 0);
      78             :     for (;;) {
      79         850 :         osl::DirectoryItem i;
      80         850 :         switch (directory.getNextItem(i, SAL_MAX_UINT32)) {
      81             :         case osl::FileBase::E_None:
      82         680 :             break;
      83             :         case osl::FileBase::E_NOENT:
      84         170 :             return false;
      85             :         default:
      86             :             throw css::uno::DeploymentException(
      87             :                 "Cannot iterate directory",
      88           0 :                 css::uno::Reference< css::uno::XInterface >());
      89             :         }
      90             :         osl::FileStatus stat(
      91             :             osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName |
      92         680 :             osl_FileStatus_Mask_FileURL);
      93         680 :         if (i.getFileStatus(stat) != osl::FileBase::E_None) {
      94             :             throw css::uno::DeploymentException(
      95             :                 "Cannot stat in directory",
      96           0 :                 css::uno::Reference< css::uno::XInterface >());
      97             :         }
      98         680 :         if (stat.getFileType() != osl::FileStatus::Directory) { //TODO: symlinks
      99             :             // Ignore backup files:
     100         680 :             rtl::OUString name(stat.getFileName());
     101         680 :             if (!(name.match(".") || name.endsWith("~"))) {
     102         680 :                 *url = stat.getFileURL();
     103         680 :                 return true;
     104           0 :             }
     105             :         }
     106           0 :     }
     107             : }
     108             : 
     109        2707 : void cppu::decodeRdbUri(rtl::OUString * uri, bool * optional, bool * directory)
     110             : {
     111             :     assert(uri != 0 && optional != 0 && directory != 0);
     112        2707 :     *optional = (*uri)[0] == '?';
     113        2707 :     if (*optional) {
     114          54 :         *uri = uri->copy(1);
     115             :     }
     116        5414 :     *directory = uri->getLength() >= 3 && (*uri)[0] == '<'
     117         170 :         && (*uri)[uri->getLength() - 2] == '>'
     118        2877 :         && (*uri)[uri->getLength() - 1] == '*';
     119        2707 :     if (*directory) {
     120         170 :         *uri = uri->copy(1, uri->getLength() - 3);
     121             :     }
     122        2707 : }
     123             : 
     124             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10