LibreOffice Module desktop (master) 1
dp_activepackages.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_extensions.h>
21
22#include <sal/config.h>
23
24#include <string_view>
25#include <utility>
26
27#include <osl/diagnose.h>
28#include <rtl/string.hxx>
29#include <rtl/textenc.h>
30#include <rtl/ustring.hxx>
31
32#include <dp_identifier.hxx>
33#include "dp_activepackages.hxx"
34
35// Old format of database entry:
36// key: UTF8(filename)
37// value: UTF8(tempname ";" mediatype)
38// New format of database entry:
39// key: 0xFF UTF8(identifier)
40// value: UTF8(tempname) 0xFF UTF8(filename) 0xFF UTF8(mediatype)
41
42#if HAVE_FEATURE_EXTENSIONS
43
44namespace {
45
46constexpr const char separator[] = "\xff";
47
48OString oldKey(std::u16string_view fileName) {
49 return OUStringToOString(fileName, RTL_TEXTENCODING_UTF8);
50}
51
52OString newKey(std::u16string_view id) {
53 return separator + OUStringToOString(id, RTL_TEXTENCODING_UTF8);
54}
55
57 OUString const & fileName, OString const & value)
58{
60 sal_Int32 i = value.indexOf(';');
61 OSL_ASSERT(i >= 0);
62 d.temporaryName = OUString(value.getStr(), i, RTL_TEXTENCODING_UTF8);
63 d.fileName = fileName;
64 d.mediaType = OUString(
65 value.getStr() + i + 1, value.getLength() - i - 1,
66 RTL_TEXTENCODING_UTF8);
67 return d;
68}
69
70::dp_manager::ActivePackages::Data decodeNewData(OString const & value) {
72 sal_Int32 i1 = value.indexOf(separator);
73 OSL_ASSERT(i1 >= 0);
74 d.temporaryName = OUString(
75 value.getStr(), i1, RTL_TEXTENCODING_UTF8);
76 sal_Int32 i2 = value.indexOf(separator, i1 + 1);
77 OSL_ASSERT(i2 >= 0);
78 d.fileName = OUString(
79 value.getStr() + i1 + 1, i2 - i1 - 1, RTL_TEXTENCODING_UTF8);
80 sal_Int32 i3 = value.indexOf(separator, i2 + 1);
81
82 if (i3 < 0)
83 {
84 //Before ActivePackages::Data::version was added
85 d.mediaType = OUString(
86 value.getStr() + i2 + 1, value.getLength() - i2 - 1,
87 RTL_TEXTENCODING_UTF8);
88 }
89 else
90 {
91 sal_Int32 i4 = value.indexOf(separator, i3 + 1);
92 d.mediaType = OUString(
93 value.getStr() + i2 + 1, i3 - i2 -1, RTL_TEXTENCODING_UTF8);
94 d.version = OUString(
95 value.getStr() + i3 + 1, i4 - i3 - 1,
96 RTL_TEXTENCODING_UTF8);
97 d.failedPrerequisites = OUString(
98 value.getStr() + i4 + 1, value.getLength() - i4 - 1,
99 RTL_TEXTENCODING_UTF8);
100 }
101 return d;
102}
103
104}
105#endif
106
107namespace dp_manager {
108
110
112#if HAVE_FEATURE_EXTENSIONS
113 : m_map(url)
114#endif
115{
116#if !HAVE_FEATURE_EXTENSIONS
117 (void) url;
118#endif
119}
120
122
124 OUString const & id, OUString const & fileName) const
125{
126 return get(nullptr, id, fileName);
127}
128
130 Data * data, OUString const & id, OUString const & fileName)
131 const
132{
133#if HAVE_FEATURE_EXTENSIONS
134 OString v;
135 if (m_map.get(&v, newKey(id))) {
136 if (data != nullptr) {
137 *data = decodeNewData(v);
138 }
139 return true;
140 } else if (m_map.get(&v, oldKey(fileName))) {
141 if (data != nullptr) {
142 *data = decodeOldData(fileName, v);
143 }
144 return true;
145 } else {
146 return false;
147 }
148#else
149 (void) data;
150 (void) id;
151 (void) fileName;
152 (void) this;
153 return false;
154#endif
155}
156
158 Entries es;
159#if HAVE_FEATURE_EXTENSIONS
161 for (auto const& elem : m)
162 {
163 if (!elem.first.isEmpty() && elem.first[0] == separator[0]) {
164 es.emplace_back(
165 OUString(
166 elem.first.getStr() + 1, elem.first.getLength() - 1,
167 RTL_TEXTENCODING_UTF8),
168 decodeNewData(elem.second));
169 } else {
170 OUString fn(
171 OStringToOUString(elem.first, RTL_TEXTENCODING_UTF8));
172 es.emplace_back(
174 decodeOldData(fn, elem.second));
175 }
176 }
177#else
178 (void) this;
179#endif
180 return es;
181}
182
183void ActivePackages::put(OUString const & id, Data const & data) {
184#if HAVE_FEATURE_EXTENSIONS
185 OString b =
186 OUStringToOString(data.temporaryName, RTL_TEXTENCODING_UTF8) +
187 separator +
188 OUStringToOString(data.fileName, RTL_TEXTENCODING_UTF8) +
189 separator +
190 OUStringToOString(data.mediaType, RTL_TEXTENCODING_UTF8) +
191 separator +
192 OUStringToOString(data.version, RTL_TEXTENCODING_UTF8) +
193 separator +
194 OUStringToOString(data.failedPrerequisites, RTL_TEXTENCODING_UTF8);
195 m_map.put(newKey(id), b);
196#else
197 (void) id;
198 (void) data;
199 (void) this;
200#endif
201}
202
204 OUString const & id, OUString const & fileName)
205{
206#if HAVE_FEATURE_EXTENSIONS
207 m_map.erase(newKey(id)) || m_map.erase(oldKey(fileName));
208#else
209 (void) id;
210 (void) fileName;
211 (void) this;
212#endif
213}
214
215}
216
217/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double d
bool has(OUString const &id, OUString const &fileName) const
bool get(Data *data, OUString const &id, OUString const &fileName) const
std::vector< std::pair< OUString, Data > > Entries
void erase(OUString const &id, OUString const &fileName)
void put(OUString const &id, Data const &value)
t_map m_map
Any value
float v
std::unordered_map< OString, OString > t_string2string_map
Definition: dp_persmap.h:28
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString generateLegacyIdentifier(std::u16string_view fileName)
Generates a legacy identifier based on a file name.
int i
m
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)