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 
32 #include "paths.hxx"
33 
34 namespace {
35 
36 #ifndef ANDROID
37 OUString get_this_libpath() {
38  static OUString s_uri = []() {
39  OUString uri;
40  osl::Module::getUrlFromAddress(reinterpret_cast<oslGenericFunction>(get_this_libpath), uri);
41  sal_Int32 i = uri.lastIndexOf('/');
42  if (i == -1)
43  {
44  throw css::uno::DeploymentException("URI " + uri + " is expected to contain a slash");
45  }
46  return uri.copy(0, i);
47  }();
48 
49  return s_uri;
50 }
51 #endif
52 }
53 
54 OUString cppu::getUnoIniUri() {
55 #if defined ANDROID
56  // Wouldn't it be lovely to avoid this ugly hard-coding.
57  // The problem is that the 'create_bootstrap_macro_expander_factory()'
58  // required for bootstrapping services, calls cppu::get_unorc directly
59  // instead of re-using the BootstrapHandle from:
60  // defaultBootstrap_InitialComponentContext
61  // and since rtlBootstrapHandle is not ref-counted doing anything
62  // clean here is hardish.
63  OUString uri("file:///assets/program");
64 #else
65  OUString uri(get_this_libpath());
66 #ifdef MACOSX
67  // We keep both the LO and URE dylibs directly in "Frameworks"
68  // (that is, LIBO_LIB_FOLDER) and rc files in "Resources"
69  // (LIBO_ETC_FOLDER). Except for unorc, of which there are two,
70  // the "LO" one (which is in "Resources") and the "URE" one (which
71  // is in "Resources/ure/etc" (LIBO_URE_ETC_FOLDER)). As this code
72  // goes into the cppuhelper library which is part of URE, we are
73  // looking for the latter one here. I think...
74  if (uri.endsWith( "/" LIBO_LIB_FOLDER ) )
75  {
76  uri = OUString::Concat(uri.subView( 0, uri.getLength() - (sizeof(LIBO_LIB_FOLDER)-1) )) + LIBO_URE_ETC_FOLDER;
77  }
78 #endif
79 #endif
80  return uri + "/" SAL_CONFIGFILE("uno");
81 }
82 
83 bool cppu::nextDirectoryItem(osl::Directory & directory, OUString * url) {
84  assert(url != nullptr);
85  for (;;) {
86  osl::DirectoryItem i;
87  switch (directory.getNextItem(i, SAL_MAX_UINT32)) {
88  case osl::FileBase::E_None:
89  break;
90  case osl::FileBase::E_NOENT:
91  return false;
92  default:
93  throw css::uno::DeploymentException(
94  "Cannot iterate directory");
95  }
96  osl::FileStatus stat(
97  osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName |
98  osl_FileStatus_Mask_FileURL);
99  if (i.getFileStatus(stat) != osl::FileBase::E_None) {
100  throw css::uno::DeploymentException(
101  "Cannot stat in directory");
102  }
103  if (stat.getFileType() != osl::FileStatus::Directory) { //TODO: symlinks
104  // Ignore backup files:
105  OUString name(stat.getFileName());
106  if (!(name.match(".") || name.endsWith("~"))) {
107  *url = stat.getFileURL();
108  return true;
109  }
110  }
111  }
112 }
113 
114 void cppu::decodeRdbUri(OUString * uri, bool * optional, bool * directory)
115 {
116  assert(uri != nullptr && optional != nullptr && directory != nullptr);
117  if(!(uri->isEmpty()))
118  {
119  *optional = (*uri)[0] == '?';
120  if (*optional) {
121  *uri = uri->copy(1);
122  }
123  *directory = uri->startsWith("<") && uri->endsWith(">*");
124  if (*directory) {
125  *uri = uri->copy(1, uri->getLength() - 3);
126  }
127  }
128  else
129  {
130  *optional = false;
131  *directory = false;
132  }
133 }
134 
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SAL_MAX_UINT32
OUString getUnoIniUri()
Definition: paths.cxx:54
bool nextDirectoryItem(osl::Directory &directory, OUString *url)
Definition: paths.cxx:83
void decodeRdbUri(OUString *uri, bool *optional, bool *directory)
Definition: paths.cxx:114
#define SAL_CONFIGFILE(name)
int i
const char * name
exports com.sun.star. uri