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 <cstdlib>
23 : #include <memory>
24 : #include <vector>
25 :
26 : #include "com/sun/star/lang/XServiceInfo.hpp"
27 : #include "com/sun/star/registry/InvalidRegistryException.hpp"
28 : #include "com/sun/star/registry/InvalidValueException.hpp"
29 : #include "com/sun/star/registry/MergeConflictException.hpp"
30 : #include "com/sun/star/registry/RegistryKeyType.hpp"
31 : #include "com/sun/star/registry/XRegistryKey.hpp"
32 : #include "com/sun/star/registry/XSimpleRegistry.hpp"
33 : #include "com/sun/star/uno/Reference.hxx"
34 : #include "com/sun/star/uno/RuntimeException.hpp"
35 : #include "com/sun/star/uno/XComponentContext.hpp"
36 : #include "com/sun/star/uno/XInterface.hpp"
37 : #include "com/sun/star/uno/Sequence.hxx"
38 : #include "cppuhelper/implbase1.hxx"
39 : #include "cppuhelper/implbase2.hxx"
40 : #include "cppuhelper/weak.hxx"
41 : #include "osl/mutex.hxx"
42 : #include "registry/registry.hxx"
43 : #include "registry/regtype.h"
44 : #include "rtl/ref.hxx"
45 : #include "rtl/string.h"
46 : #include "rtl/string.hxx"
47 : #include "rtl/textcvt.h"
48 : #include "rtl/textenc.h"
49 : #include "rtl/unload.h"
50 : #include "rtl/ustring.h"
51 : #include "rtl/ustring.hxx"
52 : #include "sal/types.h"
53 :
54 : #include "bootstrapservices.hxx"
55 :
56 : #include "textualservices.hxx"
57 :
58 : extern rtl_StandardModuleCount g_moduleCount;
59 :
60 : namespace {
61 :
62 : class SimpleRegistry:
63 : public cppu::WeakImplHelper2<
64 : css::registry::XSimpleRegistry, css::lang::XServiceInfo >
65 : {
66 : public:
67 268 : SimpleRegistry() { g_moduleCount.modCnt.acquire(&g_moduleCount.modCnt); }
68 :
69 416 : ~SimpleRegistry() { g_moduleCount.modCnt.release(&g_moduleCount.modCnt); }
70 :
71 : osl::Mutex mutex_;
72 :
73 : private:
74 : virtual rtl::OUString SAL_CALL getURL() throw (css::uno::RuntimeException);
75 :
76 : virtual void SAL_CALL open(
77 : rtl::OUString const & rURL, sal_Bool bReadOnly, sal_Bool bCreate)
78 : throw (
79 : css::registry::InvalidRegistryException,
80 : css::uno::RuntimeException);
81 :
82 : virtual sal_Bool SAL_CALL isValid() throw (css::uno::RuntimeException);
83 :
84 : virtual void SAL_CALL close() throw (
85 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
86 :
87 : virtual void SAL_CALL destroy() throw(
88 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
89 :
90 : virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL
91 : getRootKey() throw(
92 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
93 :
94 : virtual sal_Bool SAL_CALL isReadOnly() throw(
95 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
96 :
97 : virtual void SAL_CALL mergeKey(
98 : rtl::OUString const & aKeyName, rtl::OUString const & aUrl)
99 : throw (
100 : css::registry::InvalidRegistryException,
101 : css::registry::MergeConflictException, css::uno::RuntimeException);
102 :
103 0 : virtual rtl::OUString SAL_CALL getImplementationName()
104 : throw (css::uno::RuntimeException)
105 0 : { return stoc_bootstrap::simreg_getImplementationName(); }
106 :
107 0 : virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
108 : throw (css::uno::RuntimeException)
109 0 : { return ServiceName == getSupportedServiceNames()[0]; }
110 :
111 : virtual css::uno::Sequence< rtl::OUString > SAL_CALL
112 0 : getSupportedServiceNames() throw (css::uno::RuntimeException)
113 0 : { return stoc_bootstrap::simreg_getSupportedServiceNames(); }
114 :
115 : Registry registry_;
116 : std::auto_ptr< stoc::simpleregistry::TextualServices > textual_;
117 : };
118 :
119 234930 : class Key: public cppu::WeakImplHelper1< css::registry::XRegistryKey > {
120 : public:
121 117523 : Key(
122 : rtl::Reference< SimpleRegistry > const & registry,
123 : RegistryKey const & key):
124 117523 : registry_(registry), key_(key) {}
125 :
126 : private:
127 : virtual rtl::OUString SAL_CALL getKeyName()
128 : throw (css::uno::RuntimeException);
129 :
130 : virtual sal_Bool SAL_CALL isReadOnly() throw (
131 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
132 :
133 : virtual sal_Bool SAL_CALL isValid() throw(css::uno::RuntimeException);
134 :
135 : virtual css::registry::RegistryKeyType SAL_CALL getKeyType(
136 : rtl::OUString const & rKeyName)
137 : throw (
138 : css::registry::InvalidRegistryException,
139 : css::uno::RuntimeException);
140 :
141 : virtual css::registry::RegistryValueType SAL_CALL getValueType() throw(
142 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
143 :
144 : virtual sal_Int32 SAL_CALL getLongValue() throw (
145 : css::registry::InvalidRegistryException,
146 : css::registry::InvalidValueException, css::uno::RuntimeException);
147 :
148 : virtual void SAL_CALL setLongValue(sal_Int32 value) throw (
149 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
150 :
151 : virtual css::uno::Sequence< sal_Int32 > SAL_CALL getLongListValue() throw(
152 : css::registry::InvalidRegistryException,
153 : css::registry::InvalidValueException, css::uno::RuntimeException);
154 :
155 : virtual void SAL_CALL setLongListValue(
156 : com::sun::star::uno::Sequence< sal_Int32 > const & seqValue)
157 : throw (
158 : css::registry::InvalidRegistryException,
159 : css::uno::RuntimeException);
160 :
161 : virtual rtl::OUString SAL_CALL getAsciiValue() throw (
162 : css::registry::InvalidRegistryException,
163 : css::registry::InvalidValueException, css::uno::RuntimeException);
164 :
165 : virtual void SAL_CALL setAsciiValue(rtl::OUString const & value) throw (
166 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
167 :
168 : virtual css::uno::Sequence< rtl::OUString > SAL_CALL getAsciiListValue()
169 : throw (
170 : css::registry::InvalidRegistryException,
171 : css::registry::InvalidValueException, css::uno::RuntimeException);
172 :
173 : virtual void SAL_CALL setAsciiListValue(
174 : css::uno::Sequence< rtl::OUString > const & seqValue)
175 : throw (
176 : css::registry::InvalidRegistryException,
177 : css::uno::RuntimeException);
178 :
179 : virtual rtl::OUString SAL_CALL getStringValue() throw(
180 : css::registry::InvalidRegistryException,
181 : css::registry::InvalidValueException, css::uno::RuntimeException);
182 :
183 : virtual void SAL_CALL setStringValue(rtl::OUString const & value) throw (
184 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
185 :
186 : virtual css::uno::Sequence< rtl::OUString > SAL_CALL getStringListValue()
187 : throw (
188 : css::registry::InvalidRegistryException,
189 : css::registry::InvalidValueException, css::uno::RuntimeException);
190 :
191 : virtual void SAL_CALL setStringListValue(
192 : css::uno::Sequence< rtl::OUString > const & seqValue)
193 : throw (
194 : css::registry::InvalidRegistryException,
195 : css::uno::RuntimeException);
196 :
197 : virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBinaryValue() throw (
198 : css::registry::InvalidRegistryException,
199 : css::registry::InvalidValueException, css::uno::RuntimeException);
200 :
201 : virtual void SAL_CALL setBinaryValue(
202 : css::uno::Sequence< sal_Int8 > const & value)
203 : throw (
204 : css::registry::InvalidRegistryException,
205 : css::uno::RuntimeException);
206 :
207 : virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL openKey(
208 : rtl::OUString const & aKeyName)
209 : throw (
210 : css::registry::InvalidRegistryException,
211 : css::uno::RuntimeException);
212 :
213 : virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL
214 : createKey(rtl::OUString const & aKeyName) throw (
215 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
216 :
217 : virtual void SAL_CALL closeKey() throw (
218 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
219 :
220 : virtual void SAL_CALL deleteKey(rtl::OUString const & rKeyName) throw (
221 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
222 :
223 : virtual
224 : css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
225 : SAL_CALL openKeys() throw (
226 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
227 :
228 : virtual css::uno::Sequence< rtl::OUString > SAL_CALL getKeyNames() throw (
229 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
230 :
231 : virtual sal_Bool SAL_CALL createLink(
232 : rtl::OUString const & aLinkName, rtl::OUString const & aLinkTarget)
233 : throw (
234 : css::registry::InvalidRegistryException,
235 : css::uno::RuntimeException);
236 :
237 : virtual void SAL_CALL deleteLink(rtl::OUString const & rLinkName) throw (
238 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
239 :
240 : virtual rtl::OUString SAL_CALL getLinkTarget(
241 : rtl::OUString const & rLinkName)
242 : throw (
243 : css::registry::InvalidRegistryException,
244 : css::uno::RuntimeException);
245 :
246 : virtual rtl::OUString SAL_CALL getResolvedName(
247 : rtl::OUString const & aKeyName)
248 : throw (
249 : css::registry::InvalidRegistryException,
250 : css::uno::RuntimeException);
251 :
252 : rtl::Reference< SimpleRegistry > registry_;
253 : RegistryKey key_;
254 : };
255 :
256 26101 : rtl::OUString Key::getKeyName() throw (css::uno::RuntimeException) {
257 26101 : osl::MutexGuard guard(registry_->mutex_);
258 26101 : return key_.getName();
259 : }
260 :
261 0 : sal_Bool Key::isReadOnly()
262 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
263 : {
264 0 : osl::MutexGuard guard(registry_->mutex_);
265 0 : return key_.isReadOnly();
266 : }
267 :
268 187108 : sal_Bool Key::isValid() throw (css::uno::RuntimeException) {
269 187108 : osl::MutexGuard guard(registry_->mutex_);
270 187108 : return key_.isValid();
271 : }
272 :
273 0 : css::registry::RegistryKeyType Key::getKeyType(rtl::OUString const & rKeyName)
274 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
275 : {
276 0 : osl::MutexGuard guard(registry_->mutex_);
277 : RegKeyType type;
278 0 : RegError err = key_.getKeyType(rKeyName, &type);
279 0 : if (err != REG_NO_ERROR) {
280 : throw css::registry::InvalidRegistryException(
281 : (rtl::OUString(
282 : RTL_CONSTASCII_USTRINGPARAM(
283 : "com.sun.star.registry.SimpleRegistry key getKeyType:"
284 : " underlying RegistryKey::getKeyType() = ")) +
285 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
286 0 : static_cast< OWeakObject * >(this));
287 : }
288 0 : switch (type) {
289 : default:
290 0 : std::abort(); // this cannot happen
291 : // pseudo-fall-through to avoid warnings on MSC
292 : case RG_KEYTYPE:
293 0 : return css::registry::RegistryKeyType_KEY;
294 : case RG_LINKTYPE:
295 0 : return css::registry::RegistryKeyType_LINK;
296 0 : }
297 : }
298 :
299 21185 : css::registry::RegistryValueType Key::getValueType()
300 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
301 : {
302 21185 : osl::MutexGuard guard(registry_->mutex_);
303 : RegValueType type;
304 : sal_uInt32 size;
305 21185 : RegError err = key_.getValueInfo(rtl::OUString(), &type, &size);
306 21185 : switch (err) {
307 : case REG_NO_ERROR:
308 21185 : break;
309 : case REG_INVALID_VALUE:
310 0 : type = RG_VALUETYPE_NOT_DEFINED;
311 0 : break;
312 : default:
313 : throw css::registry::InvalidRegistryException(
314 : (rtl::OUString(
315 : RTL_CONSTASCII_USTRINGPARAM(
316 : "com.sun.star.registry.SimpleRegistry key getValueType:"
317 : " underlying RegistryKey::getValueInfo() = ")) +
318 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
319 0 : static_cast< OWeakObject * >(this));
320 : }
321 21185 : switch (type) {
322 : default:
323 0 : std::abort(); // this cannot happen
324 : // pseudo-fall-through to avoid warnings on MSC
325 : case RG_VALUETYPE_NOT_DEFINED:
326 0 : return css::registry::RegistryValueType_NOT_DEFINED;
327 : case RG_VALUETYPE_LONG:
328 0 : return css::registry::RegistryValueType_LONG;
329 : case RG_VALUETYPE_STRING:
330 0 : return css::registry::RegistryValueType_ASCII;
331 : case RG_VALUETYPE_UNICODE:
332 0 : return css::registry::RegistryValueType_STRING;
333 : case RG_VALUETYPE_BINARY:
334 21185 : return css::registry::RegistryValueType_BINARY;
335 : case RG_VALUETYPE_LONGLIST:
336 0 : return css::registry::RegistryValueType_LONGLIST;
337 : case RG_VALUETYPE_STRINGLIST:
338 0 : return css::registry::RegistryValueType_ASCIILIST;
339 : case RG_VALUETYPE_UNICODELIST:
340 0 : return css::registry::RegistryValueType_STRINGLIST;
341 21185 : }
342 : }
343 :
344 0 : sal_Int32 Key::getLongValue() throw (
345 : css::registry::InvalidRegistryException,
346 : css::registry::InvalidValueException, css::uno::RuntimeException)
347 : {
348 0 : osl::MutexGuard guard(registry_->mutex_);
349 : sal_Int32 value;
350 0 : RegError err = key_.getValue(rtl::OUString(), &value);
351 0 : switch (err) {
352 : case REG_NO_ERROR:
353 0 : break;
354 : case REG_INVALID_VALUE:
355 : throw css::registry::InvalidValueException(
356 : rtl::OUString(
357 : RTL_CONSTASCII_USTRINGPARAM(
358 : "com.sun.star.registry.SimpleRegistry key getLongValue:"
359 : " underlying RegistryKey::getValue() = REG_INVALID_VALUE")),
360 0 : static_cast< OWeakObject * >(this));
361 : default:
362 : throw css::registry::InvalidRegistryException(
363 : (rtl::OUString(
364 : RTL_CONSTASCII_USTRINGPARAM(
365 : "com.sun.star.registry.SimpleRegistry key getLongValue:"
366 : " underlying RegistryKey::getValue() = ")) +
367 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
368 0 : static_cast< OWeakObject * >(this));
369 : }
370 0 : return value;
371 : }
372 :
373 0 : void Key::setLongValue(sal_Int32 value)
374 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
375 : {
376 0 : osl::MutexGuard guard(registry_->mutex_);
377 : RegError err = key_.setValue(
378 0 : rtl::OUString(), RG_VALUETYPE_LONG, &value, sizeof (sal_Int32));
379 0 : if (err != REG_NO_ERROR) {
380 : throw css::registry::InvalidRegistryException(
381 : (rtl::OUString(
382 : RTL_CONSTASCII_USTRINGPARAM(
383 : "com.sun.star.registry.SimpleRegistry key setLongValue:"
384 : " underlying RegistryKey::setValue() = ")) +
385 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
386 0 : static_cast< OWeakObject * >(this));
387 0 : }
388 0 : }
389 :
390 0 : css::uno::Sequence< sal_Int32 > Key::getLongListValue() throw (
391 : css::registry::InvalidRegistryException,
392 : css::registry::InvalidValueException, css::uno::RuntimeException)
393 : {
394 0 : osl::MutexGuard guard(registry_->mutex_);
395 0 : RegistryValueList< sal_Int32 > list;
396 0 : RegError err = key_.getLongListValue(rtl::OUString(), list);
397 0 : switch (err) {
398 : case REG_NO_ERROR:
399 0 : break;
400 : case REG_VALUE_NOT_EXISTS:
401 0 : return css::uno::Sequence< sal_Int32 >();
402 : case REG_INVALID_VALUE:
403 : throw css::registry::InvalidValueException(
404 : rtl::OUString(
405 : RTL_CONSTASCII_USTRINGPARAM(
406 : "com.sun.star.registry.SimpleRegistry key getLongListValue:"
407 : " underlying RegistryKey::getLongListValue() ="
408 : " REG_INVALID_VALUE")),
409 0 : static_cast< OWeakObject * >(this));
410 : default:
411 : throw css::registry::InvalidRegistryException(
412 : (rtl::OUString(
413 : RTL_CONSTASCII_USTRINGPARAM(
414 : "com.sun.star.registry.SimpleRegistry key getLongListValue:"
415 : " underlying RegistryKey::getLongListValue() = ")) +
416 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
417 0 : static_cast< OWeakObject * >(this));
418 : }
419 0 : sal_uInt32 n = list.getLength();
420 0 : if (n > SAL_MAX_INT32) {
421 : throw css::registry::InvalidValueException(
422 : rtl::OUString(
423 : RTL_CONSTASCII_USTRINGPARAM(
424 : "com.sun.star.registry.SimpleRegistry key getLongListValue:"
425 : " underlying RegistryKey::getLongListValue() too large")),
426 0 : static_cast< OWeakObject * >(this));
427 : }
428 0 : css::uno::Sequence< sal_Int32 > value(static_cast< sal_Int32 >(n));
429 0 : for (sal_uInt32 i = 0; i < n; ++i) {
430 0 : value[static_cast< sal_Int32 >(i)] = list.getElement(i);
431 : }
432 0 : return value;
433 : }
434 :
435 0 : void Key::setLongListValue(css::uno::Sequence< sal_Int32 > const & seqValue)
436 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
437 : {
438 0 : osl::MutexGuard guard(registry_->mutex_);
439 0 : std::vector< sal_Int32 > list;
440 0 : for (sal_Int32 i = 0; i < seqValue.getLength(); ++i) {
441 0 : list.push_back(seqValue[i]);
442 : }
443 : RegError err = key_.setLongListValue(
444 0 : rtl::OUString(), list.empty() ? 0 : &list[0],
445 0 : static_cast< sal_uInt32 >(list.size()));
446 0 : if (err != REG_NO_ERROR) {
447 : throw css::registry::InvalidRegistryException(
448 : (rtl::OUString(
449 : RTL_CONSTASCII_USTRINGPARAM(
450 : "com.sun.star.registry.SimpleRegistry key setLongListValue:"
451 : " underlying RegistryKey::setLongListValue() = ")) +
452 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
453 0 : static_cast< OWeakObject * >(this));
454 0 : }
455 0 : }
456 :
457 2 : rtl::OUString Key::getAsciiValue() throw (
458 : css::registry::InvalidRegistryException,
459 : css::registry::InvalidValueException, css::uno::RuntimeException)
460 : {
461 2 : osl::MutexGuard guard(registry_->mutex_);
462 : RegValueType type;
463 : sal_uInt32 size;
464 2 : RegError err = key_.getValueInfo(rtl::OUString(), &type, &size);
465 2 : if (err != REG_NO_ERROR) {
466 : throw css::registry::InvalidRegistryException(
467 : (rtl::OUString(
468 : RTL_CONSTASCII_USTRINGPARAM(
469 : "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
470 : " underlying RegistryKey::getValueInfo() = ")) +
471 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
472 0 : static_cast< OWeakObject * >(this));
473 : }
474 2 : if (type != RG_VALUETYPE_STRING) {
475 : throw css::registry::InvalidValueException(
476 : (rtl::OUString(
477 : RTL_CONSTASCII_USTRINGPARAM(
478 : "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
479 : " underlying RegistryKey type = ")) +
480 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(type))),
481 0 : static_cast< OWeakObject * >(this));
482 : }
483 : // size contains terminating null (error in underlying registry.cxx):
484 2 : if (size == 0) {
485 : throw css::registry::InvalidValueException(
486 : rtl::OUString(
487 : RTL_CONSTASCII_USTRINGPARAM(
488 : "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
489 : " underlying RegistryKey size 0 cannot happen due to"
490 : " design error")),
491 0 : static_cast< OWeakObject * >(this));
492 : }
493 2 : if (size > SAL_MAX_INT32) {
494 : throw css::registry::InvalidValueException(
495 : rtl::OUString(
496 : RTL_CONSTASCII_USTRINGPARAM(
497 : "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
498 : " underlying RegistryKey size too large")),
499 0 : static_cast< OWeakObject * >(this));
500 : }
501 2 : std::vector< char > list(size);
502 2 : err = key_.getValue(rtl::OUString(), &list[0]);
503 2 : if (err != REG_NO_ERROR) {
504 : throw css::registry::InvalidRegistryException(
505 : (rtl::OUString(
506 : RTL_CONSTASCII_USTRINGPARAM(
507 : "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
508 : " underlying RegistryKey::getValue() = ")) +
509 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
510 0 : static_cast< OWeakObject * >(this));
511 : }
512 2 : if (list[size - 1] != '\0') {
513 : throw css::registry::InvalidValueException(
514 : rtl::OUString(
515 : RTL_CONSTASCII_USTRINGPARAM(
516 : "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
517 : " underlying RegistryKey value must be null-terminated due"
518 : " to design error")),
519 0 : static_cast< OWeakObject * >(this));
520 : }
521 2 : rtl::OUString value;
522 2 : if (!rtl_convertStringToUString(
523 2 : &value.pData, &list[0],
524 : static_cast< sal_Int32 >(size - 1), RTL_TEXTENCODING_UTF8,
525 : (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
526 : RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
527 4 : RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
528 : {
529 : throw css::registry::InvalidValueException(
530 : rtl::OUString(
531 : RTL_CONSTASCII_USTRINGPARAM(
532 : "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
533 : " underlying RegistryKey not UTF-8")),
534 0 : static_cast< OWeakObject * >(this));
535 : }
536 2 : return value;
537 : }
538 :
539 0 : void Key::setAsciiValue(rtl::OUString const & value)
540 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
541 : {
542 0 : osl::MutexGuard guard(registry_->mutex_);
543 0 : rtl::OString utf8;
544 0 : if (!value.convertToString(
545 : &utf8, RTL_TEXTENCODING_UTF8,
546 : (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
547 0 : RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
548 : {
549 : throw css::uno::RuntimeException(
550 : rtl::OUString(
551 : RTL_CONSTASCII_USTRINGPARAM(
552 : "com.sun.star.registry.SimpleRegistry key setAsciiValue:"
553 : " value not UTF-16")),
554 0 : static_cast< OWeakObject * >(this));
555 : }
556 : RegError err = key_.setValue(
557 : rtl::OUString(), RG_VALUETYPE_STRING,
558 0 : const_cast< char * >(utf8.getStr()), utf8.getLength() + 1);
559 : // +1 for terminating null (error in underlying registry.cxx)
560 0 : if (err != REG_NO_ERROR) {
561 : throw css::registry::InvalidRegistryException(
562 : (rtl::OUString(
563 : RTL_CONSTASCII_USTRINGPARAM(
564 : "com.sun.star.registry.SimpleRegistry key setAsciiValue:"
565 : " underlying RegistryKey::setValue() = ")) +
566 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
567 0 : static_cast< OWeakObject * >(this));
568 0 : }
569 0 : }
570 :
571 0 : css::uno::Sequence< rtl::OUString > Key::getAsciiListValue() throw (
572 : css::registry::InvalidRegistryException,
573 : css::registry::InvalidValueException, css::uno::RuntimeException)
574 : {
575 0 : osl::MutexGuard guard(registry_->mutex_);
576 0 : RegistryValueList< char * > list;
577 0 : RegError err = key_.getStringListValue(rtl::OUString(), list);
578 0 : switch (err) {
579 : case REG_NO_ERROR:
580 0 : break;
581 : case REG_VALUE_NOT_EXISTS:
582 0 : return css::uno::Sequence< rtl::OUString >();
583 : case REG_INVALID_VALUE:
584 : throw css::registry::InvalidValueException(
585 : rtl::OUString(
586 : RTL_CONSTASCII_USTRINGPARAM(
587 : "com.sun.star.registry.SimpleRegistry key"
588 : " getAsciiListValue: underlying"
589 : " RegistryKey::getStringListValue() = REG_INVALID_VALUE")),
590 0 : static_cast< OWeakObject * >(this));
591 : default:
592 : throw css::registry::InvalidRegistryException(
593 : (rtl::OUString(
594 : RTL_CONSTASCII_USTRINGPARAM(
595 : "com.sun.star.registry.SimpleRegistry key"
596 : " getAsciiListValue: underlying"
597 : " RegistryKey::getStringListValue() = ")) +
598 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
599 0 : static_cast< OWeakObject * >(this));
600 : }
601 0 : sal_uInt32 n = list.getLength();
602 0 : if (n > SAL_MAX_INT32) {
603 : throw css::registry::InvalidValueException(
604 : rtl::OUString(
605 : RTL_CONSTASCII_USTRINGPARAM(
606 : "com.sun.star.registry.SimpleRegistry key"
607 : " getAsciiListValue: underlying"
608 : " RegistryKey::getStringListValue() too large")),
609 0 : static_cast< OWeakObject * >(this));
610 : }
611 0 : css::uno::Sequence< rtl::OUString > value(static_cast< sal_Int32 >(n));
612 0 : for (sal_uInt32 i = 0; i < n; ++i) {
613 0 : char * el = list.getElement(i);
614 0 : sal_Int32 size = rtl_str_getLength(el);
615 0 : if (!rtl_convertStringToUString(
616 0 : &value[static_cast< sal_Int32 >(i)].pData, el, size,
617 : RTL_TEXTENCODING_UTF8,
618 : (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
619 : RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
620 0 : RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
621 : {
622 : throw css::registry::InvalidValueException(
623 : rtl::OUString(
624 : RTL_CONSTASCII_USTRINGPARAM(
625 : "com.sun.star.registry.SimpleRegistry key"
626 : " getAsciiListValue: underlying RegistryKey not"
627 : " UTF-8")),
628 0 : static_cast< OWeakObject * >(this));
629 : }
630 : }
631 0 : return value;
632 : }
633 :
634 0 : void Key::setAsciiListValue(
635 : css::uno::Sequence< rtl::OUString > const & seqValue)
636 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
637 : {
638 0 : osl::MutexGuard guard(registry_->mutex_);
639 0 : std::vector< rtl::OString > list;
640 0 : for (sal_Int32 i = 0; i < seqValue.getLength(); ++i) {
641 0 : rtl::OString utf8;
642 0 : if (!seqValue[i].convertToString(
643 : &utf8, RTL_TEXTENCODING_UTF8,
644 : (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
645 0 : RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
646 : {
647 : throw css::uno::RuntimeException(
648 : rtl::OUString(
649 : RTL_CONSTASCII_USTRINGPARAM(
650 : "com.sun.star.registry.SimpleRegistry key"
651 : " setAsciiListValue: value not UTF-16")),
652 0 : static_cast< OWeakObject * >(this));
653 : }
654 0 : list.push_back(utf8);
655 0 : }
656 0 : std::vector< char * > list2;
657 0 : for (std::vector< rtl::OString >::iterator i(list.begin()); i != list.end();
658 : ++i)
659 : {
660 0 : list2.push_back(const_cast< char * >(i->getStr()));
661 : }
662 : RegError err = key_.setStringListValue(
663 0 : rtl::OUString(), list2.empty() ? 0 : &list2[0],
664 0 : static_cast< sal_uInt32 >(list2.size()));
665 0 : if (err != REG_NO_ERROR) {
666 : throw css::registry::InvalidRegistryException(
667 : (rtl::OUString(
668 : RTL_CONSTASCII_USTRINGPARAM(
669 : "com.sun.star.registry.SimpleRegistry key"
670 : " setAsciiListValue: underlying"
671 : " RegistryKey::setStringListValue() = ")) +
672 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
673 0 : static_cast< OWeakObject * >(this));
674 0 : }
675 0 : }
676 :
677 0 : rtl::OUString Key::getStringValue() throw (
678 : css::registry::InvalidRegistryException,
679 : css::registry::InvalidValueException, css::uno::RuntimeException)
680 : {
681 0 : osl::MutexGuard guard(registry_->mutex_);
682 : RegValueType type;
683 : sal_uInt32 size;
684 0 : RegError err = key_.getValueInfo(rtl::OUString(), &type, &size);
685 0 : if (err != REG_NO_ERROR) {
686 : throw css::registry::InvalidRegistryException(
687 : (rtl::OUString(
688 : RTL_CONSTASCII_USTRINGPARAM(
689 : "com.sun.star.registry.SimpleRegistry key getStringValue:"
690 : " underlying RegistryKey::getValueInfo() = ")) +
691 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
692 0 : static_cast< OWeakObject * >(this));
693 : }
694 0 : if (type != RG_VALUETYPE_UNICODE) {
695 : throw css::registry::InvalidValueException(
696 : (rtl::OUString(
697 : RTL_CONSTASCII_USTRINGPARAM(
698 : "com.sun.star.registry.SimpleRegistry key getStringValue:"
699 : " underlying RegistryKey type = ")) +
700 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(type))),
701 0 : static_cast< OWeakObject * >(this));
702 : }
703 : // size contains terminating null and is *2 (error in underlying
704 : // registry.cxx):
705 0 : if (size == 0 || (size & 1) == 1) {
706 : throw css::registry::InvalidValueException(
707 : rtl::OUString(
708 : RTL_CONSTASCII_USTRINGPARAM(
709 : "com.sun.star.registry.SimpleRegistry key getStringValue:"
710 : " underlying RegistryKey size 0 or odd cannot happen due to"
711 : " design error")),
712 0 : static_cast< OWeakObject * >(this));
713 : }
714 0 : if (size > SAL_MAX_INT32) {
715 : throw css::registry::InvalidValueException(
716 : rtl::OUString(
717 : RTL_CONSTASCII_USTRINGPARAM(
718 : "com.sun.star.registry.SimpleRegistry key getStringValue:"
719 : " underlying RegistryKey size too large")),
720 0 : static_cast< OWeakObject * >(this));
721 : }
722 0 : std::vector< sal_Unicode > list(size);
723 0 : err = key_.getValue(rtl::OUString(), &list[0]);
724 0 : if (err != REG_NO_ERROR) {
725 : throw css::registry::InvalidRegistryException(
726 : (rtl::OUString(
727 : RTL_CONSTASCII_USTRINGPARAM(
728 : "com.sun.star.registry.SimpleRegistry key getStringValue:"
729 : " underlying RegistryKey::getValue() = ")) +
730 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
731 0 : static_cast< OWeakObject * >(this));
732 : }
733 0 : if (list[size/2 - 1] != 0) {
734 : throw css::registry::InvalidValueException(
735 : rtl::OUString(
736 : RTL_CONSTASCII_USTRINGPARAM(
737 : "com.sun.star.registry.SimpleRegistry key getStringValue:"
738 : " underlying RegistryKey value must be null-terminated due"
739 : " to design error")),
740 0 : static_cast< OWeakObject * >(this));
741 : }
742 0 : return rtl::OUString(&list[0], static_cast< sal_Int32 >(size/2 - 1));
743 : }
744 :
745 0 : void Key::setStringValue(rtl::OUString const & value)
746 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
747 : {
748 0 : osl::MutexGuard guard(registry_->mutex_);
749 : RegError err = key_.setValue(
750 : rtl::OUString(), RG_VALUETYPE_UNICODE,
751 0 : const_cast< sal_Unicode * >(value.getStr()),
752 0 : (value.getLength() + 1) * sizeof (sal_Unicode));
753 : // +1 for terminating null (error in underlying registry.cxx)
754 0 : if (err != REG_NO_ERROR) {
755 : throw css::registry::InvalidRegistryException(
756 : (rtl::OUString(
757 : RTL_CONSTASCII_USTRINGPARAM(
758 : "com.sun.star.registry.SimpleRegistry key setStringValue:"
759 : " underlying RegistryKey::setValue() = ")) +
760 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
761 0 : static_cast< OWeakObject * >(this));
762 0 : }
763 0 : }
764 :
765 0 : css::uno::Sequence< rtl::OUString > Key::getStringListValue() throw (
766 : css::registry::InvalidRegistryException,
767 : css::registry::InvalidValueException, css::uno::RuntimeException)
768 : {
769 0 : osl::MutexGuard guard(registry_->mutex_);
770 0 : RegistryValueList< sal_Unicode * > list;
771 0 : RegError err = key_.getUnicodeListValue(rtl::OUString(), list);
772 0 : switch (err) {
773 : case REG_NO_ERROR:
774 0 : break;
775 : case REG_VALUE_NOT_EXISTS:
776 0 : return css::uno::Sequence< rtl::OUString >();
777 : case REG_INVALID_VALUE:
778 : throw css::registry::InvalidValueException(
779 : rtl::OUString(
780 : RTL_CONSTASCII_USTRINGPARAM(
781 : "com.sun.star.registry.SimpleRegistry key"
782 : " getStringListValue: underlying"
783 : " RegistryKey::getUnicodeListValue() = REG_INVALID_VALUE")),
784 0 : static_cast< OWeakObject * >(this));
785 : default:
786 : throw css::registry::InvalidRegistryException(
787 : (rtl::OUString(
788 : RTL_CONSTASCII_USTRINGPARAM(
789 : "com.sun.star.registry.SimpleRegistry key"
790 : " getStringListValue: underlying"
791 : " RegistryKey::getUnicodeListValue() = ")) +
792 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
793 0 : static_cast< OWeakObject * >(this));
794 : }
795 0 : sal_uInt32 n = list.getLength();
796 0 : if (n > SAL_MAX_INT32) {
797 : throw css::registry::InvalidValueException(
798 : rtl::OUString(
799 : RTL_CONSTASCII_USTRINGPARAM(
800 : "com.sun.star.registry.SimpleRegistry key"
801 : " getStringListValue: underlying"
802 : " RegistryKey::getUnicodeListValue() too large")),
803 0 : static_cast< OWeakObject * >(this));
804 : }
805 0 : css::uno::Sequence< rtl::OUString > value(static_cast< sal_Int32 >(n));
806 0 : for (sal_uInt32 i = 0; i < n; ++i) {
807 0 : value[static_cast< sal_Int32 >(i)] = list.getElement(i);
808 : }
809 0 : return value;
810 : }
811 :
812 0 : void Key::setStringListValue(
813 : css::uno::Sequence< rtl::OUString > const & seqValue)
814 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
815 : {
816 0 : osl::MutexGuard guard(registry_->mutex_);
817 0 : std::vector< sal_Unicode * > list;
818 0 : for (sal_Int32 i = 0; i < seqValue.getLength(); ++i) {
819 0 : list.push_back(const_cast< sal_Unicode * >(seqValue[i].getStr()));
820 : }
821 : RegError err = key_.setUnicodeListValue(
822 0 : rtl::OUString(), list.empty() ? 0 : &list[0],
823 0 : static_cast< sal_uInt32 >(list.size()));
824 0 : if (err != REG_NO_ERROR) {
825 : throw css::registry::InvalidRegistryException(
826 : (rtl::OUString(
827 : RTL_CONSTASCII_USTRINGPARAM(
828 : "com.sun.star.registry.SimpleRegistry key"
829 : " setStringListValue: underlying"
830 : " RegistryKey::setUnicodeListValue() = ")) +
831 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
832 0 : static_cast< OWeakObject * >(this));
833 0 : }
834 0 : }
835 :
836 21185 : css::uno::Sequence< sal_Int8 > Key::getBinaryValue()
837 : throw (
838 : css::registry::InvalidRegistryException,
839 : css::registry::InvalidValueException, css::uno::RuntimeException)
840 : {
841 21185 : osl::MutexGuard guard(registry_->mutex_);
842 : RegValueType type;
843 : sal_uInt32 size;
844 21185 : RegError err = key_.getValueInfo(rtl::OUString(), &type, &size);
845 21185 : if (err != REG_NO_ERROR) {
846 : throw css::registry::InvalidRegistryException(
847 : (rtl::OUString(
848 : RTL_CONSTASCII_USTRINGPARAM(
849 : "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
850 : " underlying RegistryKey::getValueInfo() = ")) +
851 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
852 0 : static_cast< OWeakObject * >(this));
853 : }
854 21185 : if (type != RG_VALUETYPE_BINARY) {
855 : throw css::registry::InvalidValueException(
856 : (rtl::OUString(
857 : RTL_CONSTASCII_USTRINGPARAM(
858 : "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
859 : " underlying RegistryKey type = ")) +
860 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(type))),
861 0 : static_cast< OWeakObject * >(this));
862 : }
863 21185 : if (size > SAL_MAX_INT32) {
864 : throw css::registry::InvalidValueException(
865 : rtl::OUString(
866 : RTL_CONSTASCII_USTRINGPARAM(
867 : "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
868 : " underlying RegistryKey size too large")),
869 0 : static_cast< OWeakObject * >(this));
870 : }
871 21185 : css::uno::Sequence< sal_Int8 > value(static_cast< sal_Int32 >(size));
872 21185 : err = key_.getValue(rtl::OUString(), value.getArray());
873 21185 : if (err != REG_NO_ERROR) {
874 : throw css::registry::InvalidRegistryException(
875 : (rtl::OUString(
876 : RTL_CONSTASCII_USTRINGPARAM(
877 : "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
878 : " underlying RegistryKey::getValue() = ")) +
879 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
880 0 : static_cast< OWeakObject * >(this));
881 : }
882 21185 : return value;
883 : }
884 :
885 0 : void Key::setBinaryValue(css::uno::Sequence< sal_Int8 > const & value)
886 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
887 : {
888 0 : osl::MutexGuard guard(registry_->mutex_);
889 : RegError err = key_.setValue(
890 : rtl::OUString(), RG_VALUETYPE_BINARY,
891 0 : const_cast< sal_Int8 * >(value.getConstArray()),
892 0 : static_cast< sal_uInt32 >(value.getLength()));
893 0 : if (err != REG_NO_ERROR) {
894 : throw css::registry::InvalidRegistryException(
895 : (rtl::OUString(
896 : RTL_CONSTASCII_USTRINGPARAM(
897 : "com.sun.star.registry.SimpleRegistry key setBinaryValue:"
898 : " underlying RegistryKey::setValue() = ")) +
899 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
900 0 : static_cast< OWeakObject * >(this));
901 0 : }
902 0 : }
903 :
904 40388 : css::uno::Reference< css::registry::XRegistryKey > Key::openKey(
905 : rtl::OUString const & aKeyName)
906 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
907 : {
908 40388 : osl::MutexGuard guard(registry_->mutex_);
909 40388 : RegistryKey key;
910 40388 : RegError err = key_.openKey(aKeyName, key);
911 40388 : switch (err) {
912 : case REG_NO_ERROR:
913 19849 : return new Key(registry_, key);
914 : case REG_KEY_NOT_EXISTS:
915 20539 : return css::uno::Reference< css::registry::XRegistryKey >();
916 : default:
917 : throw css::registry::InvalidRegistryException(
918 : (rtl::OUString(
919 : RTL_CONSTASCII_USTRINGPARAM(
920 : "com.sun.star.registry.SimpleRegistry key openKey:"
921 : " underlying RegistryKey::openKey() = ")) +
922 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
923 0 : static_cast< OWeakObject * >(this));
924 40388 : }
925 : }
926 :
927 0 : css::uno::Reference< css::registry::XRegistryKey > Key::createKey(
928 : rtl::OUString const & aKeyName)
929 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
930 : {
931 0 : osl::MutexGuard guard(registry_->mutex_);
932 0 : RegistryKey key;
933 0 : RegError err = key_.createKey(aKeyName, key);
934 0 : switch (err) {
935 : case REG_NO_ERROR:
936 0 : return new Key(registry_, key);
937 : case REG_INVALID_KEYNAME:
938 0 : return css::uno::Reference< css::registry::XRegistryKey >();
939 : default:
940 : throw css::registry::InvalidRegistryException(
941 : (rtl::OUString(
942 : RTL_CONSTASCII_USTRINGPARAM(
943 : "com.sun.star.registry.SimpleRegistry key createKey:"
944 : " underlying RegistryKey::createKey() = ")) +
945 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
946 0 : static_cast< OWeakObject * >(this));
947 0 : }
948 : }
949 :
950 18111 : void Key::closeKey()
951 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
952 : {
953 18111 : osl::MutexGuard guard(registry_->mutex_);
954 18111 : RegError err = key_.closeKey();
955 18111 : if (err != REG_NO_ERROR) {
956 : throw css::registry::InvalidRegistryException(
957 : (rtl::OUString(
958 : RTL_CONSTASCII_USTRINGPARAM(
959 : "com.sun.star.registry.SimpleRegistry key closeKey:"
960 : " underlying RegistryKey::closeKey() = ")) +
961 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
962 0 : static_cast< OWeakObject * >(this));
963 18111 : }
964 18111 : }
965 :
966 0 : void Key::deleteKey(rtl::OUString const & rKeyName)
967 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
968 : {
969 0 : osl::MutexGuard guard(registry_->mutex_);
970 0 : RegError err = key_.deleteKey(rKeyName);
971 0 : if (err != REG_NO_ERROR) {
972 : throw css::registry::InvalidRegistryException(
973 : (rtl::OUString(
974 : RTL_CONSTASCII_USTRINGPARAM(
975 : "com.sun.star.registry.SimpleRegistry key deleteKey:"
976 : " underlying RegistryKey::deleteKey() = ")) +
977 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
978 0 : static_cast< OWeakObject * >(this));
979 0 : }
980 0 : }
981 :
982 : css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
983 0 : Key::openKeys()
984 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
985 : {
986 0 : osl::MutexGuard guard(registry_->mutex_);
987 0 : RegistryKeyArray list;
988 0 : RegError err = key_.openSubKeys(rtl::OUString(), list);
989 0 : if (err != REG_NO_ERROR) {
990 : throw css::registry::InvalidRegistryException(
991 : (rtl::OUString(
992 : RTL_CONSTASCII_USTRINGPARAM(
993 : "com.sun.star.registry.SimpleRegistry key openKeys:"
994 : " underlying RegistryKey::openSubKeys() = ")) +
995 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
996 0 : static_cast< OWeakObject * >(this));
997 : }
998 0 : sal_uInt32 n = list.getLength();
999 0 : if (n > SAL_MAX_INT32) {
1000 : throw css::registry::InvalidRegistryException(
1001 : rtl::OUString(
1002 : RTL_CONSTASCII_USTRINGPARAM(
1003 : "com.sun.star.registry.SimpleRegistry key getKeyNames:"
1004 : " underlying RegistryKey::getKeyNames() too large")),
1005 0 : static_cast< OWeakObject * >(this));
1006 : }
1007 : css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
1008 0 : keys(static_cast< sal_Int32 >(n));
1009 0 : for (sal_uInt32 i = 0; i < n; ++i) {
1010 0 : keys[static_cast< sal_Int32 >(i)] = new Key(
1011 0 : registry_, list.getElement(i));
1012 : }
1013 0 : return keys;
1014 : }
1015 :
1016 22 : css::uno::Sequence< rtl::OUString > Key::getKeyNames()
1017 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1018 : {
1019 22 : osl::MutexGuard guard(registry_->mutex_);
1020 22 : RegistryKeyNames list;
1021 22 : RegError err = key_.getKeyNames(rtl::OUString(), list);
1022 22 : if (err != REG_NO_ERROR) {
1023 : throw css::registry::InvalidRegistryException(
1024 : (rtl::OUString(
1025 : RTL_CONSTASCII_USTRINGPARAM(
1026 : "com.sun.star.registry.SimpleRegistry key getKeyNames:"
1027 : " underlying RegistryKey::getKeyNames() = ")) +
1028 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1029 0 : static_cast< OWeakObject * >(this));
1030 : }
1031 22 : sal_uInt32 n = list.getLength();
1032 22 : if (n > SAL_MAX_INT32) {
1033 : throw css::registry::InvalidRegistryException(
1034 : rtl::OUString(
1035 : RTL_CONSTASCII_USTRINGPARAM(
1036 : "com.sun.star.registry.SimpleRegistry key getKeyNames:"
1037 : " underlying RegistryKey::getKeyNames() too large")),
1038 0 : static_cast< OWeakObject * >(this));
1039 : }
1040 22 : css::uno::Sequence< rtl::OUString > names(static_cast< sal_Int32 >(n));
1041 2110 : for (sal_uInt32 i = 0; i < n; ++i) {
1042 2088 : names[static_cast< sal_Int32 >(i)] = list.getElement(i);
1043 : }
1044 22 : return names;
1045 : }
1046 :
1047 0 : sal_Bool Key::createLink(
1048 : rtl::OUString const & aLinkName, rtl::OUString const & aLinkTarget)
1049 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1050 : {
1051 0 : osl::MutexGuard guard(registry_->mutex_);
1052 0 : RegError err = key_.createLink(aLinkName, aLinkTarget);
1053 0 : switch (err) {
1054 : case REG_NO_ERROR:
1055 0 : return true;
1056 : case REG_INVALID_KEY:
1057 : case REG_DETECT_RECURSION:
1058 : throw css::registry::InvalidRegistryException(
1059 : (rtl::OUString(
1060 : RTL_CONSTASCII_USTRINGPARAM(
1061 : "com.sun.star.registry.SimpleRegistry key createLink:"
1062 : " underlying RegistryKey::createLink() = ")) +
1063 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1064 0 : static_cast< OWeakObject * >(this));
1065 : default:
1066 0 : return false;
1067 0 : }
1068 : }
1069 :
1070 0 : void Key::deleteLink(rtl::OUString const & rLinkName)
1071 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1072 : {
1073 0 : osl::MutexGuard guard(registry_->mutex_);
1074 0 : RegError err = key_.deleteLink(rLinkName);
1075 0 : if (err != REG_NO_ERROR) {
1076 : throw css::registry::InvalidRegistryException(
1077 : (rtl::OUString(
1078 : RTL_CONSTASCII_USTRINGPARAM(
1079 : "com.sun.star.registry.SimpleRegistry key deleteLink:"
1080 : " underlying RegistryKey::deleteLink() = ")) +
1081 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1082 0 : static_cast< OWeakObject * >(this));
1083 0 : }
1084 0 : }
1085 :
1086 0 : rtl::OUString Key::getLinkTarget(rtl::OUString const & rLinkName)
1087 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1088 : {
1089 0 : osl::MutexGuard guard(registry_->mutex_);
1090 0 : rtl::OUString target;
1091 0 : RegError err = key_.getLinkTarget(rLinkName, target);
1092 0 : if (err != REG_NO_ERROR) {
1093 : throw css::registry::InvalidRegistryException(
1094 : (rtl::OUString(
1095 : RTL_CONSTASCII_USTRINGPARAM(
1096 : "com.sun.star.registry.SimpleRegistry key getLinkTarget:"
1097 : " underlying RegistryKey::getLinkTarget() = ")) +
1098 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1099 0 : static_cast< OWeakObject * >(this));
1100 : }
1101 0 : return target;
1102 : }
1103 :
1104 46562 : rtl::OUString Key::getResolvedName(rtl::OUString const & aKeyName)
1105 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1106 : {
1107 46562 : osl::MutexGuard guard(registry_->mutex_);
1108 46562 : rtl::OUString resolved;
1109 46562 : RegError err = key_.getResolvedKeyName(aKeyName, true, resolved);
1110 46562 : if (err != REG_NO_ERROR) {
1111 : throw css::registry::InvalidRegistryException(
1112 : (rtl::OUString(
1113 : RTL_CONSTASCII_USTRINGPARAM(
1114 : "com.sun.star.registry.SimpleRegistry key getResolvedName:"
1115 : " underlying RegistryKey::getResolvedName() = ")) +
1116 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1117 0 : static_cast< OWeakObject * >(this));
1118 : }
1119 46562 : return resolved;
1120 : }
1121 :
1122 0 : rtl::OUString SimpleRegistry::getURL() throw (css::uno::RuntimeException) {
1123 0 : osl::MutexGuard guard(mutex_);
1124 0 : return textual_.get() == 0 ? registry_.getName() : textual_->getUri();
1125 : }
1126 :
1127 268 : void SimpleRegistry::open(
1128 : rtl::OUString const & rURL, sal_Bool bReadOnly, sal_Bool bCreate)
1129 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1130 : {
1131 268 : osl::MutexGuard guard(mutex_);
1132 268 : if (textual_.get() != 0) {
1133 : throw css::registry::InvalidRegistryException(
1134 : (rtl::OUString(
1135 : RTL_CONSTASCII_USTRINGPARAM(
1136 : "com.sun.star.registry.SimpleRegistry.open(")) +
1137 0 : rURL +
1138 : rtl::OUString(
1139 : RTL_CONSTASCII_USTRINGPARAM(
1140 0 : "): instance already open"))),
1141 0 : static_cast< OWeakObject * >(this));
1142 : }
1143 268 : RegError err = (rURL.isEmpty() && bCreate)
1144 : ? REG_REGISTRY_NOT_EXISTS
1145 268 : : registry_.open(rURL, bReadOnly ? REG_READONLY : REG_READWRITE);
1146 268 : if (err == REG_REGISTRY_NOT_EXISTS && bCreate) {
1147 0 : err = registry_.create(rURL);
1148 : }
1149 268 : switch (err) {
1150 : case REG_NO_ERROR:
1151 266 : break;
1152 : case REG_INVALID_REGISTRY:
1153 2 : if (bReadOnly && !bCreate) {
1154 2 : textual_.reset(new stoc::simpleregistry::TextualServices(rURL));
1155 2 : break;
1156 : }
1157 : // fall through
1158 : default:
1159 : throw css::registry::InvalidRegistryException(
1160 : (rtl::OUString(
1161 : RTL_CONSTASCII_USTRINGPARAM(
1162 : "com.sun.star.registry.SimpleRegistry.open(")) +
1163 0 : rURL +
1164 : rtl::OUString(
1165 : RTL_CONSTASCII_USTRINGPARAM(
1166 0 : "): underlying Registry::open/create() = ")) +
1167 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1168 0 : static_cast< OWeakObject * >(this));
1169 268 : }
1170 268 : }
1171 :
1172 37208 : sal_Bool SimpleRegistry::isValid() throw (css::uno::RuntimeException) {
1173 37208 : osl::MutexGuard guard(mutex_);
1174 37208 : return textual_.get() != 0 || registry_.isValid();
1175 : }
1176 :
1177 4 : void SimpleRegistry::close()
1178 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1179 : {
1180 4 : osl::MutexGuard guard(mutex_);
1181 4 : if (textual_.get() != 0) {
1182 0 : textual_.reset();
1183 4 : return;
1184 : }
1185 4 : RegError err = registry_.close();
1186 4 : if (err != REG_NO_ERROR) {
1187 : throw css::registry::InvalidRegistryException(
1188 : (rtl::OUString(
1189 : RTL_CONSTASCII_USTRINGPARAM(
1190 : "com.sun.star.registry.SimpleRegistry.close:"
1191 : " underlying Registry::close() = ")) +
1192 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1193 0 : static_cast< OWeakObject * >(this));
1194 4 : }
1195 : }
1196 :
1197 0 : void SimpleRegistry::destroy()
1198 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1199 : {
1200 0 : osl::MutexGuard guard(mutex_);
1201 0 : if (textual_.get() != 0) {
1202 0 : textual_.reset();
1203 0 : return;
1204 : }
1205 0 : RegError err = registry_.destroy(rtl::OUString());
1206 0 : if (err != REG_NO_ERROR) {
1207 : throw css::registry::InvalidRegistryException(
1208 : (rtl::OUString(
1209 : RTL_CONSTASCII_USTRINGPARAM(
1210 : "com.sun.star.registry.SimpleRegistry.destroy:"
1211 : " underlying Registry::destroy() = ")) +
1212 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1213 0 : static_cast< OWeakObject * >(this));
1214 0 : }
1215 : }
1216 :
1217 98218 : css::uno::Reference< css::registry::XRegistryKey > SimpleRegistry::getRootKey()
1218 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1219 : {
1220 98218 : osl::MutexGuard guard(mutex_);
1221 98218 : if (textual_.get() != 0) {
1222 544 : return textual_->getRootKey();
1223 : }
1224 97674 : RegistryKey root;
1225 97674 : RegError err = registry_.openRootKey(root);
1226 97674 : if (err != REG_NO_ERROR) {
1227 : throw css::registry::InvalidRegistryException(
1228 : (rtl::OUString(
1229 : RTL_CONSTASCII_USTRINGPARAM(
1230 : "com.sun.star.registry.SimpleRegistry.getRootKey:"
1231 : " underlying Registry::getRootKey() = ")) +
1232 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1233 0 : static_cast< OWeakObject * >(this));
1234 : }
1235 97674 : return new Key(this, root);
1236 : }
1237 :
1238 0 : sal_Bool SimpleRegistry::isReadOnly()
1239 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1240 : {
1241 0 : osl::MutexGuard guard(mutex_);
1242 0 : return textual_.get() != 0 || registry_.isReadOnly();
1243 : }
1244 :
1245 0 : void SimpleRegistry::mergeKey(
1246 : rtl::OUString const & aKeyName, rtl::OUString const & aUrl)
1247 : throw (
1248 : css::registry::InvalidRegistryException,
1249 : css::registry::MergeConflictException, css::uno::RuntimeException)
1250 : {
1251 0 : osl::MutexGuard guard(mutex_);
1252 0 : if (textual_.get() != 0) {
1253 : throw css::uno::RuntimeException(
1254 : rtl::OUString(
1255 : RTL_CONSTASCII_USTRINGPARAM(
1256 : "com.sun.star.registry.SimpleRegistry.mergeKey: not"
1257 : " supported for textual representation")),
1258 0 : static_cast< cppu::OWeakObject * >(this));
1259 : }
1260 0 : RegistryKey root;
1261 0 : RegError err = registry_.openRootKey(root);
1262 0 : if (err == REG_NO_ERROR) {
1263 0 : err = registry_.mergeKey(root, aKeyName, aUrl, false, false);
1264 : }
1265 0 : switch (err) {
1266 : case REG_NO_ERROR:
1267 : case REG_MERGE_CONFLICT:
1268 0 : break;
1269 : case REG_MERGE_ERROR:
1270 : throw css::registry::MergeConflictException(
1271 : rtl::OUString(
1272 : RTL_CONSTASCII_USTRINGPARAM(
1273 : "com.sun.star.registry.SimpleRegistry.mergeKey:"
1274 : " underlying Registry::mergeKey() = REG_MERGE_ERROR")),
1275 0 : static_cast< cppu::OWeakObject * >(this));
1276 : default:
1277 : throw css::registry::InvalidRegistryException(
1278 : (rtl::OUString(
1279 : RTL_CONSTASCII_USTRINGPARAM(
1280 : "com.sun.star.registry.SimpleRegistry.mergeKey:"
1281 : " underlying Registry::getRootKey/mergeKey() = ")) +
1282 0 : rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1283 0 : static_cast< OWeakObject * >(this));
1284 0 : }
1285 0 : }
1286 :
1287 : }
1288 :
1289 : namespace stoc_bootstrap {
1290 :
1291 268 : css::uno::Reference< css::uno::XInterface > SimpleRegistry_CreateInstance(
1292 : SAL_UNUSED_PARAMETER css::uno::Reference< css::uno::XComponentContext >
1293 : const &)
1294 : {
1295 268 : return static_cast< cppu::OWeakObject * >(new SimpleRegistry);
1296 : }
1297 :
1298 250 : css::uno::Sequence< rtl::OUString > simreg_getSupportedServiceNames() {
1299 250 : css::uno::Sequence< rtl::OUString > names(1);
1300 250 : names[0] = rtl::OUString(
1301 500 : RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.SimpleRegistry"));
1302 250 : return names;
1303 : }
1304 :
1305 1596 : rtl::OUString simreg_getImplementationName() {
1306 : return rtl::OUString(
1307 1596 : RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.SimpleRegistry"));
1308 : }
1309 :
1310 : }
1311 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|