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