LibreOffice Module cppuhelper (master) 1
paths.cxx
Go to the documentation of this file.
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_folders.h>
21
22#include <sal/config.h>
23
24#include <cassert>
25
26#include <com/sun/star/uno/DeploymentException.hpp>
27#include <osl/file.hxx>
28#include <osl/module.hxx>
29#include <rtl/ustring.hxx>
30#include <sal/types.h>
31#include <o3tl/string_view.hxx>
32
33#include "paths.hxx"
34
35namespace {
36
37#if !(defined ANDROID || defined EMSCRIPTEN)
38OUString get_this_libpath() {
39 static OUString s_uri = []() {
40 OUString uri;
41 osl::Module::getUrlFromAddress(reinterpret_cast<oslGenericFunction>(get_this_libpath), uri);
42 sal_Int32 i = uri.lastIndexOf('/');
43 if (i == -1)
44 {
45 throw css::uno::DeploymentException("URI " + uri + " is expected to contain a slash");
46 }
47 return uri.copy(0, i);
48 }();
49
50 return s_uri;
51}
52#endif
53}
54
56#if defined ANDROID
57 // Wouldn't it be lovely to avoid this ugly hard-coding.
58 // The problem is that the 'create_bootstrap_macro_expander_factory()'
59 // required for bootstrapping services, calls cppu::get_unorc directly
60 // instead of re-using the BootstrapHandle from:
61 // defaultBootstrap_InitialComponentContext
62 // and since rtlBootstrapHandle is not ref-counted doing anything
63 // clean here is hardish.
64 OUString uri("file:///assets/program");
65#elif defined(EMSCRIPTEN)
66 OUString uri("file:///instdir/program");
67#else
68 OUString uri(get_this_libpath());
69#ifdef MACOSX
70 // We keep the URE dylibs directly in "Frameworks" (that is, LIBO_LIB_FOLDER) and unorc in
71 // "Resources/ure/etc" (LIBO_URE_ETC_FOLDER).
72 if (uri.endsWith( "/" LIBO_LIB_FOLDER ) )
73 {
74 uri = OUString::Concat(uri.subView( 0, uri.getLength() - (sizeof(LIBO_LIB_FOLDER)-1) )) + LIBO_URE_ETC_FOLDER;
75 }
76#endif
77#endif
78 return uri + "/" SAL_CONFIGFILE("uno");
79}
80
81bool cppu::nextDirectoryItem(osl::Directory & directory, OUString * url) {
82 assert(url != nullptr);
83 for (;;) {
84 osl::DirectoryItem i;
85 switch (directory.getNextItem(i, SAL_MAX_UINT32)) {
86 case osl::FileBase::E_None:
87 break;
88 case osl::FileBase::E_NOENT:
89 return false;
90 default:
91 throw css::uno::DeploymentException(
92 "Cannot iterate directory");
93 }
94 osl::FileStatus stat(
95 osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName |
96 osl_FileStatus_Mask_FileURL);
97 if (i.getFileStatus(stat) != osl::FileBase::E_None) {
98 throw css::uno::DeploymentException(
99 "Cannot stat in directory");
100 }
101 if (stat.getFileType() != osl::FileStatus::Directory) { //TODO: symlinks
102 // Ignore backup files:
103 OUString name(stat.getFileName());
104 if (!(name.match(".") || name.endsWith("~"))) {
105 *url = stat.getFileURL();
106 return true;
107 }
108 }
109 }
110}
111
112void cppu::decodeRdbUri(std::u16string_view * uri, bool * optional, bool * directory)
113{
114 assert(uri != nullptr && optional != nullptr && directory != nullptr);
115 if(!(uri->empty()))
116 {
117 *optional = (*uri)[0] == '?';
118 if (*optional) {
119 *uri = uri->substr(1);
120 }
121 *directory = o3tl::starts_with(*uri, u"<") && o3tl::ends_with(*uri, u">*");
122 if (*directory) {
123 *uri = uri->substr(1, uri->size() - 3);
124 }
125 }
126 else
127 {
128 *optional = false;
129 *directory = false;
130 }
131}
132
133/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SAL_CONFIGFILE(name)
float u
const char * name
void decodeRdbUri(std::u16string_view *uri, bool *optional, bool *directory)
Definition: paths.cxx:112
OUString getUnoIniUri()
Definition: paths.cxx:55
bool nextDirectoryItem(osl::Directory &directory, OUString *url)
Definition: paths.cxx:81
int i
constexpr bool ends_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
#define SAL_MAX_UINT32